generated from jCloud/repository-template
Rename module _utils to utils
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from src.jcloud_docsgen.utils import ExistingDirectory
|
||||
import pytest
|
||||
import pathlib
|
||||
|
||||
@pytest.mark.parametrize('path,expected', [
|
||||
('tests/unit/_utils/test_directory/', 'tests/unit/_utils/test_directory'),
|
||||
('tests/unit/_utils/test_directory', 'tests/unit/_utils/test_directory'),
|
||||
('tests/unit/_utils/', 'tests/unit/_utils'),
|
||||
('tests/unit/_utils', 'tests/unit/_utils'),
|
||||
('/', '/'),
|
||||
('./', '.'),
|
||||
('.', '.'),
|
||||
('../', '..'),
|
||||
('..', '..'),
|
||||
])
|
||||
def test_ExistingDirectory(path, expected):
|
||||
assert ExistingDirectory(path).as_posix() == expected
|
||||
|
||||
@pytest.mark.parametrize('path,expected_exception,expected_exception_message', [
|
||||
('tests/unit/_utils/does_not_exist/', FileNotFoundError, '[Errno 2] no such file or directory: \'tests/unit/_utils/does_not_exist/\''),
|
||||
('tests/unit/_utils/does_not_exist', FileNotFoundError, '[Errno 2] no such file or directory: \'tests/unit/_utils/does_not_exist\''),
|
||||
('', FileNotFoundError, '[Errno 2] no such file or directory: \'\''),
|
||||
('README.md', NotADirectoryError, '[Errno 20] not a directory: \'README.md\''),
|
||||
])
|
||||
def test_ExistingDirectory_exceptions(path, expected_exception, expected_exception_message):
|
||||
with pytest.raises(expected_exception) as exc_info:
|
||||
ExistingDirectory(path)
|
||||
assert str(exc_info.value) == expected_exception_message
|
||||
@@ -0,0 +1,29 @@
|
||||
from src.jcloud_docsgen.utils import assert_that_is_instance
|
||||
import pytest
|
||||
import types
|
||||
|
||||
class TestType: ...
|
||||
TestType.__name__ = 'NOT TestType'
|
||||
|
||||
@pytest.mark.parametrize('obj,class_or_tuple', [
|
||||
(1, int),
|
||||
(1, (int,)),
|
||||
(1, str | int),
|
||||
(1, int | str | list),
|
||||
(TestType(), TestType),
|
||||
(None, types.NoneType),
|
||||
])
|
||||
def test_assert_that_is_instance(obj, class_or_tuple):
|
||||
assert_that_is_instance(obj, class_or_tuple)
|
||||
|
||||
@pytest.mark.parametrize('obj,class_or_tuple,expected_exception_msg', [
|
||||
(1, str, 'expected \'str\', got \'int\''),
|
||||
(1, (str,), 'expected \'str\', got \'int\''),
|
||||
(1, str | float, 'expected either \'str\' or \'float\', got \'int\''),
|
||||
(1, str | float | list, 'expected either \'str\', \'float\' or \'list\', got \'int\''),
|
||||
(1, TestType, 'expected \'NOT TestType\', got \'int\''),
|
||||
])
|
||||
def test_assert_that_is_instance_exceptions(obj, class_or_tuple, expected_exception_msg):
|
||||
with pytest.raises(TypeError) as exc_info:
|
||||
assert_that_is_instance(obj, class_or_tuple)
|
||||
assert str(exc_info.value) == expected_exception_msg
|
||||
@@ -0,0 +1,40 @@
|
||||
from src.jcloud_docsgen.utils import human_readable_list
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize('ls,final_separator,quotation_mark,expected', [
|
||||
([], '', '', ''),
|
||||
([], 'and', '', ''),
|
||||
([], 'and', '\'', ''),
|
||||
([1], '', '', '1'),
|
||||
([-1], '', '', '-1'),
|
||||
([0], '', '', '0'),
|
||||
([0.0], '', '', '0.0'),
|
||||
([-0.0], '', '', '-0.0'),
|
||||
([4.2], '', '', '4.2'),
|
||||
([-4.2], '', '', '-4.2'),
|
||||
(['a'], '', '', 'a'),
|
||||
([1], 'and', '', '1'),
|
||||
(['a'], 'and', '', 'a'),
|
||||
([1], 'and', '\'', '\'1\''),
|
||||
(['a'], 'and', '\'', '\'a\''),
|
||||
([1, 2], 'and', '', '1 and 2'),
|
||||
([1, 2], 'and', '\'', '\'1\' and \'2\''),
|
||||
([1, 'a'], 'and', '', '1 and a'),
|
||||
([1, 'a'], 'and', '\'', '\'1\' and \'a\''),
|
||||
([1, 'a'], 'and', '', '1 and a'),
|
||||
([1, 'a'], 'and', '\'', '\'1\' and \'a\''),
|
||||
([1, 'a'], 'and', '\'', '\'1\' and \'a\''),
|
||||
([1, 'a'], '', '', '1 a'),
|
||||
([1, 'a'], '', '\'', '\'1\' \'a\''),
|
||||
([1, 'a'], '', '', '1 a'),
|
||||
([1, 'a'], '', '\'', '\'1\' \'a\''),
|
||||
([1, 'a'], '', '\'', '\'1\' \'a\''),
|
||||
([1, 2, 3], 'and', '', '1, 2 and 3'),
|
||||
([1, 2, 3], '', '', '1, 2 3'),
|
||||
([1, 2, 3], 'and', '\'', '\'1\', \'2\' and \'3\''),
|
||||
([1, 2, 3], '', '\'', '\'1\', \'2\' \'3\''),
|
||||
([1, 2, 3, 42, 'a', 23], 'and', '', '1, 2, 3, 42, a and 23'),
|
||||
([1, 2, 3, 42, 'a', 23], 'and', '\'', '\'1\', \'2\', \'3\', \'42\', \'a\' and \'23\''),
|
||||
])
|
||||
def test_human_readable_list(ls, final_separator, quotation_mark, expected):
|
||||
assert human_readable_list(ls, final_separator, quotation_mark) == expected
|
||||
Reference in New Issue
Block a user