-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
168 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class LevelError(Exception): | ||
"""Raised when a requested level is not available""" | ||
|
||
def __init__(self, *args) -> None: | ||
if args: | ||
self.message = args[0] | ||
else: | ||
self.message = None | ||
|
||
def __str__(self): | ||
if self.message: | ||
return self.message | ||
else: | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pytest | ||
|
||
from histolab import exceptions as exp | ||
|
||
from ..unitutil import ANY, initializer_mock | ||
|
||
|
||
class DescribeExceptions(object): | ||
@pytest.mark.parametrize("args", ("error", ["hello", "error"], None)) | ||
def it_can_construct_from_args_level_error(self, request, args): | ||
_init = initializer_mock(request, exp.LevelError) | ||
|
||
if type(args) == list: | ||
level_error = exp.LevelError(*args) | ||
else: | ||
level_error = exp.LevelError(args) | ||
|
||
if type(args) == list: | ||
_init.assert_called_once_with(ANY, *args) | ||
else: | ||
_init.assert_called_once_with(ANY, args) | ||
assert isinstance(level_error, exp.LevelError) | ||
assert isinstance(level_error, Exception) | ||
|
||
@pytest.mark.parametrize("args", ("error", ["hello", "error"], None)) | ||
def it_knows_its_message_level_error(self, request, args): | ||
if type(args) == list: | ||
level_error = exp.LevelError(*args) | ||
else: | ||
level_error = exp.LevelError(args) | ||
|
||
message = level_error.message | ||
|
||
if args: | ||
if type(args) == str: | ||
assert type(message) == str | ||
assert message == args | ||
if type(args) == list: | ||
assert type(message) == str | ||
assert message == list(args)[0] | ||
else: | ||
assert message is None | ||
|
||
@pytest.mark.parametrize("args", ("error", ["hello", "error"], None)) | ||
def it_knows_its_str_level_error(self, request, args): | ||
if type(args) == list: | ||
level_error = exp.LevelError(*args) | ||
else: | ||
level_error = exp.LevelError(args) | ||
|
||
s = str(level_error) | ||
|
||
if not args: | ||
assert s == "" | ||
else: | ||
assert s == level_error.message |
Oops, something went wrong.