14
14
import types
15
15
16
16
# 3rd party
17
+ from typing import no_type_check
18
+
17
19
import pytest
18
- from pytest_regressions .file_regression import FileRegressionFixture
20
+ from pytest_regressions .file_regression import FileRegressionFixture # type: ignore
19
21
20
22
# this package
21
23
from domdf_python_tools .pretty_print import FancyPrinter , simple_repr
@@ -140,6 +142,7 @@ def __hash__(self):
140
142
141
143
class TestFancyPrinter :
142
144
145
+ @no_type_check
143
146
def test_init (self ):
144
147
FancyPrinter ()
145
148
FancyPrinter (indent = 4 , width = 40 , depth = 5 , stream = io .StringIO (), compact = True )
@@ -182,6 +185,7 @@ def test_basic(self, safe):
182
185
assert not pp .isrecursive (safe ), f"expected not isrecursive for { safe !r} "
183
186
assert pp .isreadable (safe ), f"expected isreadable for { safe !r} "
184
187
188
+ @no_type_check
185
189
def test_knotted (self ):
186
190
a = list (range (100 ))
187
191
b = list (range (200 ))
@@ -278,6 +282,7 @@ def test_knotted(self):
278
282
# self.assertEqual(FancyPrinter().pformat(cont), expected)
279
283
# self.assertEqual(FancyPrinter(width=1, indent=0).pformat(cont), expected)
280
284
285
+ @no_type_check
281
286
def test_basic_line_wrap (self ):
282
287
# verify basic line-wrapping operation
283
288
o = {
@@ -449,7 +454,7 @@ def test_sorted_dict(self):
449
454
(): {}}) == r"{5: [[]], 'xy\tab\n': (3,), (): {}}"
450
455
451
456
def test_ordered_dict (self , file_regression : FileRegressionFixture ):
452
- d = collections .OrderedDict ()
457
+ d : collections . OrderedDict = collections .OrderedDict ()
453
458
assert FancyPrinter (width = 1 ).pformat (d ) == 'OrderedDict()'
454
459
d = collections .OrderedDict ([])
455
460
assert FancyPrinter (width = 1 ).pformat (d ) == 'OrderedDict()'
@@ -564,7 +569,7 @@ def test_sort_unorderable_values(self):
564
569
assert FancyPrinter ().pformat ({Unorderable : 0 , 1 : 0 }) == '{1: 0, ' + repr (Unorderable ) + ': 0}'
565
570
566
571
# Issue 14998: TypeError on tuples with NoneTypes as dict keys.
567
- keys = [(1 , ), (None , )]
572
+ keys = [(1 , ), (None , )] # type: ignore
568
573
assert FancyPrinter ().pformat (dict .fromkeys (keys , 0 )) == '{%r: 0, %r: 0}' % tuple (sorted (keys , key = id ))
569
574
570
575
def test_sort_orderable_and_unorderable_values (self ):
@@ -694,7 +699,7 @@ def test_compact_width(self):
694
699
number = 10
695
700
o = [0 ] * number
696
701
for i in range (levels - 1 ):
697
- o = [o ]
702
+ o = [o ] # type: ignore
698
703
for w in range (levels * 2 + 1 , levels + 3 * number - 1 ):
699
704
lines = FancyPrinter (width = w , compact = True ).pformat (o , ).splitlines ()
700
705
maxwidth = max (map (len , lines ))
@@ -811,20 +816,20 @@ def test_bytearray_wrap(self, value, width, file_regression: FileRegressionFixtu
811
816
self .check_file_regression (FancyPrinter (width = width ).pformat (value ), file_regression )
812
817
813
818
def test_default_dict (self , file_regression : FileRegressionFixture ):
814
- d = collections .defaultdict (int )
819
+ d : collections . defaultdict = collections .defaultdict (int )
815
820
assert FancyPrinter (width = 1 ).pformat (d ) == "defaultdict(<class 'int'>, {})"
816
821
words = 'the quick brown fox jumped over a lazy dog' .split ()
817
822
d = collections .defaultdict (int , zip (words , itertools .count ()))
818
823
self .check_file_regression (FancyPrinter ().pformat (d ), file_regression )
819
824
820
825
def test_counter (self , file_regression : FileRegressionFixture ):
821
- d = collections .Counter ()
826
+ d : collections . Counter = collections .Counter ()
822
827
assert FancyPrinter (width = 1 ).pformat (d ) == "Counter()"
823
828
d = collections .Counter ('senselessness' )
824
829
self .check_file_regression (FancyPrinter (width = 40 ).pformat (d ), file_regression )
825
830
826
831
def test_chainmap (self , file_regression : FileRegressionFixture ):
827
- d = collections .ChainMap ()
832
+ d : collections . ChainMap = collections .ChainMap ()
828
833
assert FancyPrinter (width = 1 ).pformat (d ) == "ChainMap({})"
829
834
words = 'the quick brown fox jumped over a lazy dog' .split ()
830
835
items = list (zip (words , itertools .count ()))
@@ -838,7 +843,7 @@ def test_chainmap_nested(self, file_regression: FileRegressionFixture):
838
843
self .check_file_regression (FancyPrinter ().pformat (d ), file_regression )
839
844
840
845
def test_deque (self ):
841
- d = collections .deque ()
846
+ d : collections . deque = collections .deque ()
842
847
assert FancyPrinter (width = 1 ).pformat (d ) == "deque([])"
843
848
d = collections .deque (maxlen = 7 )
844
849
assert FancyPrinter (width = 1 ).pformat (d ) == "deque([], maxlen=7)"
@@ -873,14 +878,14 @@ def check_file_regression(self, data, file_regression: FileRegressionFixture):
873
878
file_regression .check (data , extension = ".txt" , encoding = "UTF-8" )
874
879
875
880
def test_user_dict (self , file_regression : FileRegressionFixture ):
876
- d = collections .UserDict ()
881
+ d : collections . UserDict = collections .UserDict ()
877
882
assert FancyPrinter (width = 1 ).pformat (d ) == "{}"
878
883
words = 'the quick brown fox jumped over a lazy dog' .split ()
879
- d = collections .UserDict (zip (words , itertools .count ()))
884
+ d = collections .UserDict (zip (words , itertools .count ())) # type: ignore
880
885
self .check_file_regression (FancyPrinter ().pformat (d ), file_regression )
881
886
882
887
def test_user_list (self , file_regression : FileRegressionFixture ):
883
- d = collections .UserList ()
888
+ d : collections . UserList = collections .UserList ()
884
889
assert FancyPrinter (width = 1 ).pformat (d ) == "[]"
885
890
words = 'the quick brown fox jumped over a lazy dog' .split ()
886
891
d = collections .UserList (zip (words , itertools .count ()))
0 commit comments