Skip to content

Commit ba3910e

Browse files
committed
Use namespace when calling functions in test_utils.py
1 parent af92ab5 commit ba3910e

File tree

1 file changed

+120
-120
lines changed

1 file changed

+120
-120
lines changed

tests/test_utils.py

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
# this package
2121
from domdf_python_tools import utils
2222
from domdf_python_tools.testing import testing_boolean_values
23-
from domdf_python_tools.utils import (
24-
Len, chunks, convert_indents, double_chain, list2str, posargs2kwargs, pyversion, str2tuple, word_join
25-
)
2623

2724

2825
def test_pyversion():
29-
assert isinstance(pyversion, int)
26+
assert isinstance(utils.pyversion, int)
3027

3128

3229
@pytest.mark.parametrize(
@@ -76,42 +73,43 @@ def test_check_dependencies(capsys):
7673

7774

7875
def test_chunks():
79-
assert isinstance(chunks(list(range(100)), 5), types.GeneratorType)
80-
assert list(chunks(list(range(100)), 5))[0] == [0, 1, 2, 3, 4]
81-
assert list(chunks(['a', 'b', 'c'], 1)) == [['a'], ['b'], ['c']]
76+
assert isinstance(utils.chunks(list(range(100)), 5), types.GeneratorType)
77+
assert list(utils.chunks(list(range(100)), 5))[0] == [0, 1, 2, 3, 4]
78+
assert list(utils.chunks(['a', 'b', 'c'], 1)) == [['a'], ['b'], ['c']]
8279

8380

8481
# TODO: cmp
8582

86-
87-
@pytest.mark.parametrize(
88-
"value, expects",
89-
[
90-
([1, 2, 3], "1,2,3"),
91-
(['a', 'b', 'c'], "a,b,c"),
92-
(['a', 'b', 1, 2], "a,b,1,2"),
93-
(['a', 2, pathlib.Path("foo.txt")], "a,2,foo.txt"),
94-
],
95-
)
96-
def test_list2str(value, expects):
97-
str_representation = list2str(value)
98-
assert isinstance(str_representation, str)
99-
assert str_representation == expects
100-
101-
102-
@pytest.mark.parametrize(
103-
"value, expects",
104-
[
105-
([1, 2, 3], "1;2;3"),
106-
(['a', 'b', 'c'], "a;b;c"),
107-
(['a', 'b', 1, 2], "a;b;1;2"),
108-
(['a', 2, pathlib.Path("foo.txt")], "a;2;foo.txt"),
109-
],
110-
)
111-
def test_list2str_semicolon(value, expects):
112-
str_representation = list2str(value, sep=';')
113-
assert isinstance(str_representation, str)
114-
assert str_representation == expects
83+
class TestList2Str:
84+
85+
@pytest.mark.parametrize(
86+
"value, expects",
87+
[
88+
([1, 2, 3], "1,2,3"),
89+
(['a', 'b', 'c'], "a,b,c"),
90+
(['a', 'b', 1, 2], "a,b,1,2"),
91+
(['a', 2, pathlib.Path("foo.txt")], "a,2,foo.txt"),
92+
],
93+
)
94+
def test_list2str(self, value, expects):
95+
str_representation = utils.list2str(value)
96+
assert isinstance(str_representation, str)
97+
assert str_representation == expects
98+
99+
100+
@pytest.mark.parametrize(
101+
"value, expects",
102+
[
103+
([1, 2, 3], "1;2;3"),
104+
(['a', 'b', 'c'], "a;b;c"),
105+
(['a', 'b', 1, 2], "a;b;1;2"),
106+
(['a', 2, pathlib.Path("foo.txt")], "a;2;foo.txt"),
107+
],
108+
)
109+
def test_list2str_semicolon(self, value, expects):
110+
str_representation = utils.list2str(value, sep=';')
111+
assert isinstance(str_representation, str)
112+
assert str_representation == expects
115113

116114

117115
def test_permutations():
@@ -254,49 +252,51 @@ def test_split_len():
254252
assert utils.split_len("Spam Spam Spam Spam Spam Spam Spam Spam ", 5) == ["Spam "] * 8
255253

256254

257-
@pytest.mark.parametrize(
258-
"value, expects",
259-
[
260-
("1,2,3", (1, 2, 3)), # tests without spaces
261-
("1, 2, 3", (1, 2, 3)), # tests with spaces
262-
],
263-
)
264-
def test_str2tuple(value, expects):
265-
assert isinstance(str2tuple(value), tuple)
266-
assert str2tuple(value) == expects
267-
268-
269-
@pytest.mark.parametrize(
270-
"value, expects",
271-
[
272-
("1;2;3", (1, 2, 3)), # tests without semicolon
273-
("1; 2; 3", (1, 2, 3)), # tests with semicolon
274-
],
275-
)
276-
def test_str2tuple_semicolon(value, expects):
277-
assert isinstance(str2tuple(value, sep=';'), tuple)
278-
assert str2tuple(value, sep=';') == expects
279-
280-
281-
@testing_boolean_values(extra_truthy=[50, -1])
282-
def test_strtobool(boolean_string, expected_boolean):
283-
assert utils.strtobool(boolean_string) == expected_boolean
284-
285-
286-
@pytest.mark.parametrize(
287-
"obj, expects",
288-
[
289-
("truthy", ValueError),
290-
("foo", ValueError),
291-
("bar", ValueError),
292-
(None, AttributeError),
293-
(1.0, AttributeError),
294-
(0.0, AttributeError),
295-
],
296-
)
297-
def test_strtobool_errors(obj, expects):
298-
with pytest.raises(expects):
299-
utils.strtobool(obj)
255+
class TestStr2Tuple:
256+
257+
@pytest.mark.parametrize(
258+
"value, expects",
259+
[
260+
("1,2,3", (1, 2, 3)), # tests without spaces
261+
("1, 2, 3", (1, 2, 3)), # tests with spaces
262+
],
263+
)
264+
def test_str2tuple(self, value, expects):
265+
assert isinstance(utils.str2tuple(value), tuple)
266+
assert utils.str2tuple(value) == expects
267+
268+
@pytest.mark.parametrize(
269+
"value, expects",
270+
[
271+
("1;2;3", (1, 2, 3)), # tests without semicolon
272+
("1; 2; 3", (1, 2, 3)), # tests with semicolon
273+
],
274+
)
275+
def test_str2tuple_semicolon(self, value, expects):
276+
assert isinstance(utils.str2tuple(value, sep=';'), tuple)
277+
assert utils.str2tuple(value, sep=';') == expects
278+
279+
280+
class TestStrToBool:
281+
282+
@testing_boolean_values(extra_truthy=[50, -1])
283+
def test_strtobool(self, boolean_string, expected_boolean):
284+
assert utils.strtobool(boolean_string) == expected_boolean
285+
286+
@pytest.mark.parametrize(
287+
"obj, expects",
288+
[
289+
("truthy", ValueError),
290+
("foo", ValueError),
291+
("bar", ValueError),
292+
(None, AttributeError),
293+
(1.0, AttributeError),
294+
(0.0, AttributeError),
295+
],
296+
)
297+
def test_strtobool_errors(self, obj, expects):
298+
with pytest.raises(expects):
299+
utils.strtobool(obj)
300300

301301

302302
@pytest.mark.parametrize(
@@ -364,20 +364,20 @@ def test_cmp():
364364
]
365365
)
366366
def test_double_chain(value, expects):
367-
assert list(double_chain(value)) == expects
367+
assert list(utils.double_chain(value)) == expects
368368

369369

370370
def test_len(capsys):
371-
assert list(Len("Hello")) == [0, 1, 2, 3, 4]
372-
assert list(Len("Hello World")) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
371+
assert list(utils.Len("Hello")) == [0, 1, 2, 3, 4]
372+
assert list(utils.Len("Hello World")) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
373373

374-
for val in Len("Hello World"):
374+
for val in utils.Len("Hello World"):
375375
print(val)
376376

377377
captured = capsys.readouterr()
378378
assert captured.out.splitlines() == ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
379379

380-
assert Len("Hello") == range(5)
380+
assert utils.Len("Hello") == range(5)
381381

382382

383383
def demo_function(arg1, arg2, arg3):
@@ -398,58 +398,58 @@ def demo_function(arg1, arg2, arg3):
398398
]
399399
)
400400
def test_posargs2kwargs(args, posarg_names, kwargs, expects):
401-
assert posargs2kwargs(args, posarg_names, kwargs) == expects
401+
assert utils.posargs2kwargs(args, posarg_names, kwargs) == expects
402402

403403

404404
def test_word_join():
405-
assert word_join([]) == ''
405+
assert utils.word_join([]) == ''
406406

407-
assert word_join(["bob"]) == "bob"
408-
assert word_join(["bob", "alice"]) == "bob and alice"
409-
assert word_join(["bob", "alice", "fred"]) == "bob, alice and fred"
407+
assert utils.word_join(["bob"]) == "bob"
408+
assert utils.word_join(["bob", "alice"]) == "bob and alice"
409+
assert utils.word_join(["bob", "alice", "fred"]) == "bob, alice and fred"
410410

411-
assert word_join(["bob"], use_repr=True) == "'bob'"
412-
assert word_join(["bob", "alice"], use_repr=True) == "'bob' and 'alice'"
413-
assert word_join(["bob", "alice", "fred"], use_repr=True) == "'bob', 'alice' and 'fred'"
411+
assert utils.word_join(["bob"], use_repr=True) == "'bob'"
412+
assert utils.word_join(["bob", "alice"], use_repr=True) == "'bob' and 'alice'"
413+
assert utils.word_join(["bob", "alice", "fred"], use_repr=True) == "'bob', 'alice' and 'fred'"
414414

415-
assert word_join(["bob"], use_repr=True, oxford=True) == "'bob'"
416-
assert word_join(["bob", "alice"], use_repr=True, oxford=True) == "'bob' and 'alice'"
417-
assert word_join(["bob", "alice", "fred"], use_repr=True, oxford=True) == "'bob', 'alice', and 'fred'"
415+
assert utils.word_join(["bob"], use_repr=True, oxford=True) == "'bob'"
416+
assert utils.word_join(["bob", "alice"], use_repr=True, oxford=True) == "'bob' and 'alice'"
417+
assert utils.word_join(["bob", "alice", "fred"], use_repr=True, oxford=True) == "'bob', 'alice', and 'fred'"
418418

419-
assert word_join(()) == ''
419+
assert utils.word_join(()) == ''
420420

421-
assert word_join(("bob", )) == "bob"
422-
assert word_join(("bob", "alice")) == "bob and alice"
423-
assert word_join(("bob", "alice", "fred")) == "bob, alice and fred"
421+
assert utils.word_join(("bob", )) == "bob"
422+
assert utils.word_join(("bob", "alice")) == "bob and alice"
423+
assert utils.word_join(("bob", "alice", "fred")) == "bob, alice and fred"
424424

425-
assert word_join(("bob", ), use_repr=True) == "'bob'"
426-
assert word_join(("bob", "alice"), use_repr=True) == "'bob' and 'alice'"
427-
assert word_join(("bob", "alice", "fred"), use_repr=True) == "'bob', 'alice' and 'fred'"
425+
assert utils.word_join(("bob", ), use_repr=True) == "'bob'"
426+
assert utils.word_join(("bob", "alice"), use_repr=True) == "'bob' and 'alice'"
427+
assert utils.word_join(("bob", "alice", "fred"), use_repr=True) == "'bob', 'alice' and 'fred'"
428428

429-
assert word_join(("bob", ), use_repr=True, oxford=True) == "'bob'"
430-
assert word_join(("bob", "alice"), use_repr=True, oxford=True) == "'bob' and 'alice'"
431-
assert word_join(("bob", "alice", "fred"), use_repr=True, oxford=True) == "'bob', 'alice', and 'fred'"
429+
assert utils.word_join(("bob", ), use_repr=True, oxford=True) == "'bob'"
430+
assert utils.word_join(("bob", "alice"), use_repr=True, oxford=True) == "'bob' and 'alice'"
431+
assert utils.word_join(("bob", "alice", "fred"), use_repr=True, oxford=True) == "'bob', 'alice', and 'fred'"
432432

433433

434434
def test_convert_indents():
435435

436436
# TODO: test 'to'
437437

438-
assert convert_indents("hello world") == "hello world"
439-
assert convert_indents(" hello world") == " hello world"
440-
assert convert_indents(" hello world") == " hello world"
441-
assert convert_indents(" hello world") == " hello world"
438+
assert utils.convert_indents("hello world") == "hello world"
439+
assert utils.convert_indents(" hello world") == " hello world"
440+
assert utils.convert_indents(" hello world") == " hello world"
441+
assert utils.convert_indents(" hello world") == " hello world"
442442

443-
assert convert_indents("hello world", tab_width=2) == "hello world"
444-
assert convert_indents(" hello world", tab_width=2) == " hello world"
445-
assert convert_indents(" hello world", tab_width=2) == " hello world"
446-
assert convert_indents(" hello world", tab_width=2) == " hello world"
443+
assert utils.convert_indents("hello world", tab_width=2) == "hello world"
444+
assert utils.convert_indents(" hello world", tab_width=2) == " hello world"
445+
assert utils.convert_indents(" hello world", tab_width=2) == " hello world"
446+
assert utils.convert_indents(" hello world", tab_width=2) == " hello world"
447447

448-
assert convert_indents("hello world", from_=" ") == "hello world"
449-
assert convert_indents(" hello world", from_=" ") == " hello world"
450-
assert convert_indents(" hello world", from_=" ") == " hello world"
451-
assert convert_indents(" hello world", from_=" ") == " hello world"
448+
assert utils.convert_indents("hello world", from_=" ") == "hello world"
449+
assert utils.convert_indents(" hello world", from_=" ") == " hello world"
450+
assert utils.convert_indents(" hello world", from_=" ") == " hello world"
451+
assert utils.convert_indents(" hello world", from_=" ") == " hello world"
452452

453-
assert convert_indents("hello world", tab_width=2, from_=" ") == "hello world"
454-
assert convert_indents(" hello world", tab_width=2, from_=" ") == " hello world"
455-
assert convert_indents(" hello world", tab_width=2, from_=" ") == " hello world"
453+
assert utils.convert_indents("hello world", tab_width=2, from_=" ") == "hello world"
454+
assert utils.convert_indents(" hello world", tab_width=2, from_=" ") == " hello world"
455+
assert utils.convert_indents(" hello world", tab_width=2, from_=" ") == " hello world"

0 commit comments

Comments
 (0)