18
18
import pytest
19
19
20
20
# this package
21
- from domdf_python_tools import utils
22
21
from domdf_python_tools .testing import testing_boolean_values
23
22
from domdf_python_tools .typing import HasHead
24
- from domdf_python_tools .utils import head , trim_precision
23
+ from domdf_python_tools .utils import (
24
+ cmp ,
25
+ convert_indents ,
26
+ double_repr_string ,
27
+ enquote_value ,
28
+ head ,
29
+ list2str ,
30
+ posargs2kwargs ,
31
+ printr ,
32
+ printt ,
33
+ pyversion ,
34
+ stderr_writer ,
35
+ str2tuple ,
36
+ strtobool ,
37
+ trim_precision
38
+ )
25
39
26
40
27
41
def test_pyversion ():
28
- assert isinstance (utils . pyversion , int )
42
+ assert isinstance (pyversion , int )
29
43
30
44
31
45
class TestList2Str :
@@ -40,7 +54,7 @@ class TestList2Str:
40
54
],
41
55
)
42
56
def test_list2str (self , value , expects ):
43
- str_representation = utils . list2str (value )
57
+ str_representation = list2str (value )
44
58
assert isinstance (str_representation , str )
45
59
assert str_representation == expects
46
60
@@ -54,7 +68,7 @@ def test_list2str(self, value, expects):
54
68
],
55
69
)
56
70
def test_list2str_semicolon (self , value , expects ):
57
- str_representation = utils . list2str (value , sep = ';' )
71
+ str_representation = list2str (value , sep = ';' )
58
72
assert isinstance (str_representation , str )
59
73
assert str_representation == expects
60
74
@@ -96,7 +110,7 @@ def get_mem_addr(obj):
96
110
],
97
111
)
98
112
def test_printr (obj , expects , capsys ):
99
- utils . printr (obj )
113
+ printr (obj )
100
114
101
115
captured = capsys .readouterr ()
102
116
stdout = captured .out .split ('\n ' )
@@ -115,7 +129,7 @@ def test_printr(obj, expects, capsys):
115
129
],
116
130
)
117
131
def test_printt (obj , expects , capsys ):
118
- utils . printt (obj )
132
+ printt (obj )
119
133
120
134
captured = capsys .readouterr ()
121
135
stdout = captured .out .split ('\n ' )
@@ -134,7 +148,7 @@ def test_printt(obj, expects, capsys):
134
148
],
135
149
)
136
150
def test_stderr_writer (obj , expects , capsys ):
137
- utils . stderr_writer (obj )
151
+ stderr_writer (obj )
138
152
139
153
captured = capsys .readouterr ()
140
154
stderr = captured .err .split ('\n ' )
@@ -151,8 +165,8 @@ class TestStr2Tuple:
151
165
],
152
166
)
153
167
def test_str2tuple (self , value , expects ):
154
- assert isinstance (utils . str2tuple (value ), tuple )
155
- assert utils . str2tuple (value ) == expects
168
+ assert isinstance (str2tuple (value ), tuple )
169
+ assert str2tuple (value ) == expects
156
170
157
171
@pytest .mark .parametrize (
158
172
"value, expects" ,
@@ -162,15 +176,15 @@ def test_str2tuple(self, value, expects):
162
176
],
163
177
)
164
178
def test_str2tuple_semicolon (self , value , expects ):
165
- assert isinstance (utils . str2tuple (value , sep = ';' ), tuple )
166
- assert utils . str2tuple (value , sep = ';' ) == expects
179
+ assert isinstance (str2tuple (value , sep = ';' ), tuple )
180
+ assert str2tuple (value , sep = ';' ) == expects
167
181
168
182
169
183
class TestStrToBool :
170
184
171
185
@testing_boolean_values (extra_truthy = [50 , - 1 ])
172
186
def test_strtobool (self , boolean_string , expected_boolean ):
173
- assert utils . strtobool (boolean_string ) == expected_boolean
187
+ assert strtobool (boolean_string ) == expected_boolean
174
188
175
189
@pytest .mark .parametrize (
176
190
"obj, expects" ,
@@ -185,7 +199,7 @@ def test_strtobool(self, boolean_string, expected_boolean):
185
199
)
186
200
def test_strtobool_errors (self , obj , expects ):
187
201
with pytest .raises (expects ):
188
- utils . strtobool (obj )
202
+ strtobool (obj )
189
203
190
204
191
205
@pytest .mark .parametrize (
@@ -210,7 +224,7 @@ def test_strtobool_errors(self, obj, expects):
210
224
],
211
225
)
212
226
def test_enquote_value (obj , expects ):
213
- assert utils . enquote_value (obj ) == expects
227
+ assert enquote_value (obj ) == expects
214
228
215
229
216
230
#
@@ -225,20 +239,20 @@ def test_enquote_value(obj, expects):
225
239
# ])
226
240
# def test_enquote_value_errors(obj, expects):
227
241
# with pytest.raises(expects):
228
- # utils. enquote_value(obj)
242
+ # enquote_value(obj)
229
243
230
244
231
245
def test_cmp ():
232
- assert isinstance (utils . cmp (5 , 20 ), int )
233
- assert utils . cmp (5 , 20 ) < 0
234
- assert utils . cmp (5 , 20 ) == - 1
246
+ assert isinstance (cmp (5 , 20 ), int )
247
+ assert cmp (5 , 20 ) < 0
248
+ assert cmp (5 , 20 ) == - 1
235
249
236
- assert isinstance (utils . cmp (20 , 5 ), int )
237
- assert utils . cmp (20 , 5 ) > 0
238
- assert utils . cmp (20 , 5 ) == 1
250
+ assert isinstance (cmp (20 , 5 ), int )
251
+ assert cmp (20 , 5 ) > 0
252
+ assert cmp (20 , 5 ) == 1
239
253
240
- assert isinstance (utils . cmp (20 , 20 ), int )
241
- assert utils . cmp (20 , 20 ) == 0
254
+ assert isinstance (cmp (20 , 20 ), int )
255
+ assert cmp (20 , 20 ) == 0
242
256
243
257
244
258
def demo_function (arg1 , arg2 , arg3 ):
@@ -259,31 +273,31 @@ def demo_function(arg1, arg2, arg3):
259
273
]
260
274
)
261
275
def test_posargs2kwargs (args , posarg_names , kwargs , expects ):
262
- assert utils . posargs2kwargs (args , posarg_names , kwargs ) == expects
276
+ assert posargs2kwargs (args , posarg_names , kwargs ) == expects
263
277
264
278
265
279
def test_convert_indents ():
266
280
267
281
# TODO: test 'to'
268
282
269
- assert utils . convert_indents ("hello world" ) == "hello world"
270
- assert utils . convert_indents ("\t hello world" ) == " hello world"
271
- assert utils . convert_indents ("\t \t hello world" ) == " hello world"
272
- assert utils . convert_indents ("\t hello world" ) == " hello world"
283
+ assert convert_indents ("hello world" ) == "hello world"
284
+ assert convert_indents ("\t hello world" ) == " hello world"
285
+ assert convert_indents ("\t \t hello world" ) == " hello world"
286
+ assert convert_indents ("\t hello world" ) == " hello world"
273
287
274
- assert utils . convert_indents ("hello world" , tab_width = 2 ) == "hello world"
275
- assert utils . convert_indents ("\t hello world" , tab_width = 2 ) == " hello world"
276
- assert utils . convert_indents ("\t \t hello world" , tab_width = 2 ) == " hello world"
277
- assert utils . convert_indents ("\t hello world" , tab_width = 2 ) == " hello world"
288
+ assert convert_indents ("hello world" , tab_width = 2 ) == "hello world"
289
+ assert convert_indents ("\t hello world" , tab_width = 2 ) == " hello world"
290
+ assert convert_indents ("\t \t hello world" , tab_width = 2 ) == " hello world"
291
+ assert convert_indents ("\t hello world" , tab_width = 2 ) == " hello world"
278
292
279
- assert utils . convert_indents ("hello world" , from_ = " " ) == "hello world"
280
- assert utils . convert_indents (" hello world" , from_ = " " ) == " hello world"
281
- assert utils . convert_indents (" hello world" , from_ = " " ) == " hello world"
282
- assert utils . convert_indents (" hello world" , from_ = " " ) == " hello world"
293
+ assert convert_indents ("hello world" , from_ = " " ) == "hello world"
294
+ assert convert_indents (" hello world" , from_ = " " ) == " hello world"
295
+ assert convert_indents (" hello world" , from_ = " " ) == " hello world"
296
+ assert convert_indents (" hello world" , from_ = " " ) == " hello world"
283
297
284
- assert utils . convert_indents ("hello world" , tab_width = 2 , from_ = " " ) == "hello world"
285
- assert utils . convert_indents (" hello world" , tab_width = 2 , from_ = " " ) == " hello world"
286
- assert utils . convert_indents (" hello world" , tab_width = 2 , from_ = " " ) == " hello world"
298
+ assert convert_indents ("hello world" , tab_width = 2 , from_ = " " ) == "hello world"
299
+ assert convert_indents (" hello world" , tab_width = 2 , from_ = " " ) == " hello world"
300
+ assert convert_indents (" hello world" , tab_width = 2 , from_ = " " ) == " hello world"
287
301
288
302
289
303
class TestHead :
@@ -396,3 +410,17 @@ def test_trim_precision():
396
410
assert trim_precision (170.15800000000002 , 4 ) == 170.158
397
411
assert trim_precision (170.15800000000002 , 5 ) == 170.158
398
412
assert trim_precision (170.15800000000002 ) == 170.158
413
+
414
+
415
+ @pytest .mark .parametrize (
416
+ "value, expects" ,
417
+ [
418
+ ("foo" , '"foo"' ),
419
+ ("'foo'" , "\" 'foo'\" " ),
420
+ ("don't" , "\" don't\" " ),
421
+ ("Here's a single quote \" " , "\" Here's a single quote \\ \" \" " ),
422
+ (enquote_value ('☃' ), "\" '☃'\" " ),
423
+ ]
424
+ )
425
+ def test_double_repr_string (value : str , expects : str ):
426
+ assert double_repr_string (value ) == expects
0 commit comments