1
1
import platform
2
+ import pprint
2
3
3
4
import packaging .version
4
5
import pytest
5
6
6
- from dirty_equals import Contains , IsApprox , IsInt , IsNegative , IsOneOf , IsPositive , IsStr
7
+ from dirty_equals import Contains , IsApprox , IsInt , IsList , IsNegative , IsOneOf , IsPositive , IsStr
7
8
from dirty_equals .version import VERSION
8
9
9
10
@@ -39,8 +40,7 @@ def test_value_eq():
39
40
v .value
40
41
41
42
assert 'foo' == v
42
- assert str (v ) == "'foo'"
43
- assert repr (v ) == "'foo'"
43
+ assert repr (v ) == str (v ) == "'foo'" == pprint .pformat (v )
44
44
assert v .value == 'foo'
45
45
46
46
@@ -50,8 +50,7 @@ def test_value_ne():
50
50
with pytest .raises (AssertionError ):
51
51
assert 1 == v
52
52
53
- assert str (v ) == 'IsStr()'
54
- assert repr (v ) == 'IsStr()'
53
+ assert repr (v ) == str (v ) == 'IsStr()' == pprint .pformat (v )
55
54
with pytest .raises (AttributeError , match = 'value is not available until __eq__ has been called' ):
56
55
v .value
57
56
@@ -110,7 +109,7 @@ def test_repr():
110
109
],
111
110
)
112
111
def test_repr_class (v , v_repr ):
113
- assert repr (v ) == v_repr
112
+ assert repr (v ) == str ( v ) == v_repr == pprint . pformat ( v )
114
113
115
114
116
115
def test_is_approx_without_init ():
@@ -119,11 +118,62 @@ def test_is_approx_without_init():
119
118
120
119
def test_ne_repr ():
121
120
v = IsInt
122
- assert repr (v ) == 'IsInt'
121
+ assert repr (v ) == str ( v ) == 'IsInt' == pprint . pformat ( v )
123
122
124
123
assert 'x' != v
125
124
126
- assert repr (v ) == 'IsInt'
125
+ assert repr (v ) == str (v ) == 'IsInt' == pprint .pformat (v )
126
+
127
+
128
+ def test_pprint ():
129
+ v = [IsList (length = ...), 1 , [IsList (length = ...), 2 ], 3 , IsInt ()]
130
+ lorem = ['lorem' , 'ipsum' , 'dolor' , 'sit' , 'amet' ] * 2
131
+ with pytest .raises (AssertionError ):
132
+ assert [lorem , 1 , [lorem , 2 ], 3 , '4' ] == v
133
+
134
+ assert repr (v ) == (f'[{ lorem } , 1, [{ lorem } , 2], 3, IsInt()]' )
135
+ assert pprint .pformat (v ) == (
136
+ "[['lorem',\n "
137
+ " 'ipsum',\n "
138
+ " 'dolor',\n "
139
+ " 'sit',\n "
140
+ " 'amet',\n "
141
+ " 'lorem',\n "
142
+ " 'ipsum',\n "
143
+ " 'dolor',\n "
144
+ " 'sit',\n "
145
+ " 'amet'],\n "
146
+ ' 1,\n '
147
+ " [['lorem',\n "
148
+ " 'ipsum',\n "
149
+ " 'dolor',\n "
150
+ " 'sit',\n "
151
+ " 'amet',\n "
152
+ " 'lorem',\n "
153
+ " 'ipsum',\n "
154
+ " 'dolor',\n "
155
+ " 'sit',\n "
156
+ " 'amet'],\n "
157
+ ' 2],\n '
158
+ ' 3,\n '
159
+ ' IsInt()]'
160
+ )
161
+
162
+
163
+ def test_pprint_not_equal ():
164
+ v = IsList (* range (30 )) # need a big value to trigger pprint
165
+ with pytest .raises (AssertionError ):
166
+ assert [] == v
167
+
168
+ assert (
169
+ pprint .pformat (v )
170
+ == (
171
+ 'IsList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, '
172
+ '15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29)'
173
+ )
174
+ == repr (v )
175
+ == str (v )
176
+ )
127
177
128
178
129
179
@pytest .mark .parametrize (
0 commit comments