6
6
from _pytest .mark import Mark , MarkDecorator
7
7
8
8
# this package
9
- from domdf_python_tools .testing import (
10
- count ,
11
- generate_falsy_values ,
12
- generate_truthy_values ,
13
- testing_boolean_values ,
14
- whitespace_perms ,
15
- )
9
+ from domdf_python_tools import testing
16
10
from domdf_python_tools .utils import strtobool
17
11
18
12
19
13
def test_count ():
20
- assert isinstance (count (100 ), MarkDecorator )
21
- assert isinstance (count (100 ).mark , Mark )
22
- assert "count" in count (100 ).mark .args
23
- assert count (100 ).mark .args [0 ] == "count"
24
- assert count (100 ).mark .args [1 ] == range (0 , 100 )
14
+ assert isinstance (testing . count (100 ), MarkDecorator )
15
+ assert isinstance (testing . count (100 ).mark , Mark )
16
+ assert "count" in testing . count (100 ).mark .args
17
+ assert testing . count (100 ).mark .args [0 ] == "count"
18
+ assert testing . count (100 ).mark .args [1 ] == range (0 , 100 )
25
19
26
- assert count (10 ).mark .args [1 ] == range (0 , 10 )
27
- assert count (10 , 5 ).mark .args [1 ] == range (5 , 10 ) # order of count is "stop, start, step"
28
- assert count (10 , 5 , 2 ).mark .args [1 ] == range (5 , 10 , 2 ) # order of count is "stop, start, step"
20
+ assert testing . count (10 ).mark .args [1 ] == range (0 , 10 )
21
+ assert testing . count (10 , 5 ).mark .args [1 ] == range (5 , 10 ) # order of count is "stop, start, step"
22
+ assert testing . count (10 , 5 , 2 ).mark .args [1 ] == range (5 , 10 , 2 ) # order of count is "stop, start, step"
29
23
30
24
31
25
def test_whitespace_perms ():
32
26
random .seed (1234 )
33
27
34
- assert isinstance (whitespace_perms (), MarkDecorator )
35
- assert isinstance (whitespace_perms ().mark , Mark )
36
- assert "char" in whitespace_perms ().mark .args
37
- assert whitespace_perms ().mark .args [0 ] == "char"
38
- assert len (whitespace_perms ().mark .args [1 ]) == 20
39
- assert len (whitespace_perms (1 ).mark .args [1 ]) == 41
40
- assert len (whitespace_perms (.1 ).mark .args [1 ]) == 4
28
+ assert isinstance (testing . whitespace_perms (), MarkDecorator )
29
+ assert isinstance (testing . whitespace_perms ().mark , Mark )
30
+ assert "char" in testing . whitespace_perms ().mark .args
31
+ assert testing . whitespace_perms ().mark .args [0 ] == "char"
32
+ assert len (testing . whitespace_perms ().mark .args [1 ]) == 20
33
+ assert len (testing . whitespace_perms (1 ).mark .args [1 ]) == 41
34
+ assert len (testing . whitespace_perms (.1 ).mark .args [1 ]) == 4
41
35
42
- assert isinstance (whitespace_perms (.1 ).mark .args [1 ], list )
43
- assert isinstance (whitespace_perms (.1 ).mark .args [1 ][0 ], str )
36
+ assert isinstance (testing . whitespace_perms (.1 ).mark .args [1 ], list )
37
+ assert isinstance (testing . whitespace_perms (.1 ).mark .args [1 ][0 ], str )
44
38
45
- assert whitespace_perms (.1 ).mark .args [1 ] == ['\n \t \r ' , '\r \t ' , '\t \n ' , '\n \r ' ]
39
+ assert testing . whitespace_perms (.1 ).mark .args [1 ] == ['\n \t \r ' , '\r \t ' , '\t \n ' , '\n \r ' ]
46
40
47
- for string in whitespace_perms ().mark .args [1 ]:
41
+ for string in testing . whitespace_perms ().mark .args [1 ]:
48
42
assert re .match (r"^\s*$" , string )
49
43
50
44
51
45
def test_testing_boolean_strings ():
52
- assert isinstance (testing_boolean_values (), MarkDecorator )
53
- assert isinstance (testing_boolean_values ().mark , Mark )
54
- assert "boolean_string, expected_boolean" in testing_boolean_values ().mark .args
55
- assert testing_boolean_values ().mark .args [0 ] == "boolean_string, expected_boolean"
56
- assert len (testing_boolean_values ().mark .args [1 ]) == 28
57
- assert isinstance (testing_boolean_values ().mark .args [1 ], list )
58
- assert isinstance (testing_boolean_values ().mark .args [1 ][0 ], tuple )
59
- assert len (testing_boolean_values ().mark .args [1 ][0 ]) == 2
60
- assert isinstance (testing_boolean_values ().mark .args [1 ][0 ][0 ], bool )
61
- assert isinstance (testing_boolean_values ().mark .args [1 ][0 ][1 ], bool )
62
-
63
- for value , expects in testing_boolean_values ().mark .args [1 ]:
46
+ assert isinstance (testing . testing_boolean_values (), MarkDecorator )
47
+ assert isinstance (testing . testing_boolean_values ().mark , Mark )
48
+ assert "boolean_string, expected_boolean" in testing . testing_boolean_values ().mark .args
49
+ assert testing . testing_boolean_values ().mark .args [0 ] == "boolean_string, expected_boolean"
50
+ assert len (testing . testing_boolean_values ().mark .args [1 ]) == 28
51
+ assert isinstance (testing . testing_boolean_values ().mark .args [1 ], list )
52
+ assert isinstance (testing . testing_boolean_values ().mark .args [1 ][0 ], tuple )
53
+ assert len (testing . testing_boolean_values ().mark .args [1 ][0 ]) == 2
54
+ assert isinstance (testing . testing_boolean_values ().mark .args [1 ][0 ][0 ], bool )
55
+ assert isinstance (testing . testing_boolean_values ().mark .args [1 ][0 ][1 ], bool )
56
+
57
+ for value , expects in testing . testing_boolean_values ().mark .args [1 ]:
64
58
assert strtobool (value ) is expects
65
59
66
60
67
61
def test_generate_truthy ():
68
62
random .seed (1234 )
69
63
70
- assert list (generate_truthy_values ()) == [
64
+ assert list (testing . generate_truthy_values ()) == [
71
65
True ,
72
66
"True" ,
73
67
"true" ,
@@ -84,7 +78,7 @@ def test_generate_truthy():
84
78
1 ,
85
79
]
86
80
87
- assert list (generate_truthy_values (["bar" ])) == [
81
+ assert list (testing . generate_truthy_values (["bar" ])) == [
88
82
True ,
89
83
"True" ,
90
84
"true" ,
@@ -102,13 +96,13 @@ def test_generate_truthy():
102
96
"bar" ,
103
97
]
104
98
105
- assert list (generate_truthy_values (ratio = .3 )) == ['1' , 'yes' , 'True' , True ]
99
+ assert list (testing . generate_truthy_values (ratio = .3 )) == ['1' , 'yes' , 'True' , True ]
106
100
107
101
108
102
def test_generate_falsy ():
109
103
random .seed (1234 )
110
104
111
- assert list (generate_falsy_values ()) == [
105
+ assert list (testing . generate_falsy_values ()) == [
112
106
False ,
113
107
"False" ,
114
108
"false" ,
@@ -125,8 +119,8 @@ def test_generate_falsy():
125
119
0 ,
126
120
]
127
121
128
- assert list (generate_falsy_values (["bar" ])) == [
122
+ assert list (testing . generate_falsy_values (["bar" ])) == [
129
123
False , "False" , "false" , "falSE" , 'n' , 'N' , "NO" , "no" , "nO" , "OFF" , "off" , "oFF" , '0' , 0 , "bar"
130
124
]
131
125
132
- assert list (generate_falsy_values (ratio = .3 )) == ['0' , 'no' , 'False' , False ]
126
+ assert list (testing . generate_falsy_values (ratio = .3 )) == ['0' , 'no' , 'False' , False ]
0 commit comments