Skip to content

Commit

Permalink
Rename ValidationError so name better reflects its purpose.
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkz committed Nov 17, 2018
1 parent 941785a commit 7c8f068
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions riposte/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class CommandError(RiposteException):
pass


class ValidationError(RiposteException):
def __init__(self, value: str, validator: Callable):
class GuideError(RiposteException):
def __init__(self, value: str, guide: Callable):
self.value = value
self.validator = validator
self.guide = guide

def __str__(self):
return (
f"ValidationError: Can't validate "
f"{Palette.BOLD.format(self.value)} using "
f"{Palette.BOLD.format(self.validator.__name__)} validator"
f"ValidationError: Can't apply "
f"{Palette.BOLD.format(self.guide.__name__)} guide "
f"to value {Palette.BOLD.format(self.value)}"
)
8 changes: 4 additions & 4 deletions riposte/guides.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import ast
from typing import Any, AnyStr, Callable, Dict, Tuple

from riposte.exceptions import ValidationError
from riposte.exceptions import GuideError


def literal(value: str) -> Any:
try:
return ast.literal_eval(value)
except Exception:
raise ValidationError(value, literal)
raise GuideError(value, literal)


def encode(value: str) -> Any:
try:
return value.encode()
except Exception:
raise ValidationError(value, encode)
raise GuideError(value, encode)


def get_guides(annotation) -> Tuple[Callable]:
""" Based on given annotation get set of guides. """
""" Based on given annotation get chain of guides. """

if annotation is AnyStr:
return ()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from riposte import guides
from riposte.exceptions import ValidationError
from riposte.exceptions import GuideError


@mock.patch("riposte.guides.ast")
Expand All @@ -21,7 +21,7 @@ def test_literal(mocked_ast):
def test_literal_exception(mocked_ast):
mocked_ast.literal_eval.side_effect = TypeError

with pytest.raises(ValidationError):
with pytest.raises(GuideError):
guides.literal("foo")


Expand All @@ -38,7 +38,7 @@ def test_encode_exception():
mocked_value = mock.Mock()
mocked_value.encode.side_effect = UnicodeEncodeError

with pytest.raises(ValidationError):
with pytest.raises(GuideError):
guides.encode(mocked_value)


Expand Down

0 comments on commit 7c8f068

Please sign in to comment.