-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
65 additions
and
2 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,20 @@ | ||
"""Tests for the utils module""" | ||
import pytest | ||
|
||
from reddel_server import utils | ||
|
||
|
||
def test_get_attr_from_dotted_path(mocker): | ||
"""Test the function call importlib correctly""" | ||
class MyClass: | ||
pass | ||
|
||
importmock = mocker.Mock() | ||
modmock = mocker.Mock() | ||
modmock.MyClass = MyClass | ||
importmock.return_value = modmock | ||
|
||
mockedimport = mocker.patch("importlib.import_module", importmock) | ||
result = utils.get_attr_from_dotted_path("test.this.path.MyClass") | ||
assert result is MyClass | ||
mockedimport.assert_called_once_with('test.this.path') |
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,42 @@ | ||
"""Tests for the validators module""" | ||
import pytest | ||
import redbaron | ||
|
||
import reddel_server | ||
|
||
DEF_SRC = """def foo(bar): | ||
spam = bar + 1 | ||
return spam | ||
""" | ||
|
||
DEF_SRC2 = DEF_SRC + """ | ||
def foo2(bar): | ||
pass | ||
""" | ||
|
||
@pytest.mark.parametrize('identifiers,single,src,valid', [ | ||
[['def', 'defnode'], True, DEF_SRC, True], | ||
[['def', 'defnode'], True, DEF_SRC2, False], | ||
[['name'], True, DEF_SRC, False], | ||
[['def'], False, DEF_SRC2, True] | ||
]) | ||
def test_barontype_call(identifiers, single, src, valid): | ||
val = reddel_server.BaronTypeValidator(identifiers, single=single) | ||
red = redbaron.RedBaron(src) | ||
if valid: | ||
val(red) | ||
else: | ||
with pytest.raises(reddel_server.ValidationError): | ||
val(red) | ||
|
||
def test_barontype_transform_single(): | ||
val = reddel_server.BaronTypeValidator((), single=True) | ||
red = redbaron.RedBaron(DEF_SRC) | ||
transformed = val.transform(red) | ||
assert transformed is red[0] | ||
|
||
def test_barontype_transform_singleOff(): | ||
val = reddel_server.BaronTypeValidator((), single=False) | ||
red = redbaron.RedBaron(DEF_SRC) | ||
transformed = val.transform(red) | ||
assert transformed is red |
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