-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestfile.py
203 lines (166 loc) · 4.43 KB
/
testfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Try:
# ./fstrings.py testfile.py
# TODO write proper tests ;)
a = 'a'
b = a % ()
c = 'this is a string'
interpolated = 'interpolated'
string = 'string'
a_dict = {'a': 'interpolated'}
'this is an %s string' % interpolated
'this is an %s string' % (interpolated,)
'this is an %s %s' % (interpolated, string)
'this is an %s %s' % (interpolated, string,)
'this is an {} string'.format(interpolated)
'this is an {} {}'.format(interpolated, string)
'this is an {1} {0}'.format(string, interpolated)
'this is an {} {string}'.format(interpolated, string=string)
'this is an {} {xyz}'.format(interpolated, xyz=string)
'this is an {a} {0}'.format(string, **a_dict)
'this is an {interpolated} string'.format(interpolated=interpolated)
u"the 'u' should go away from this {string}".format(string=string)
r"the 'r' should be preserved in this {string}".format(string=string)
# Cases to *ignore*:
# mostly we only really want basic names in f-strings,
# because including too much can harm readability:
'this is an {} string'.format('interpolated')
'this is an {} string'.format(a_dict['a'])
# 'b' and 'f' prefixes can't be combined
b"this kind of {string} shouldn't become an f-string".format(string=string)
# pytestify.py
class Foo(unittest.TestCase):
# This won't be modified
def assertEqual(self, foo, bar, msg):
pass
def test_assertequal(self):
# won't be modified
self.assertEqual()
self.assertEqual('a')
self.assertEqual('a', 'b', 'c', 'd')
self.assertEqual(*args)
self.assertNotEqual()
self.assertNotEqual('a')
self.assertNotEqual('a', 'b', 'c', 'd')
self.assertNotEqual(*args)
# will be modified
self.assertEqual( 'a', 'b' )
self.assertEqual('a', 'b')
self.assertEqual('a', 'b', 'c')
self.assertEqual('a', 'b', message='c')
self.assertEqual('a', 1, message='c')
self.assertNotEqual( 'a', 'b' )
self.assertNotEqual('a', 'b')
self.assertNotEqual('a', 'b', 'c')
self.assertNotEqual('a', 'b', message='c')
self.assertNotEqual('a', 1, message='c')
# special cases
# --> 'assert a is None', etc
self.assertEqual(a, None)
self.assertEqual(None, a)
self.assertNotEqual(a, None)
self.assertNotEqual(None, a)
# --> 'assert a', etc. NOTE: assertEqual *doesn't* do `assert a is True`
self.assertEqual(a, True)
self.assertNotEqual(a, True)
self.assertEqual(a, False)
self.assertNotEqual(a, False)
self.assertEqual(True, a)
# some synonyms
self.assertEquals('a', 'b', 'c')
self.failUnlessEqual('a', 'b', 'c')
self.failIfEqual('a', 'b', 'c')
# multi-line ones
self.assertEqual(
'a',
'b')
self.assertEqual('a',
'b')
self.assertEqual(
'a',
'b'
)
self.assertEqual(
'a'
,
'b'
,
'message'
,
)
self.assertIn(x, y)
self.assertNotIn(x, y)
self.assertEqual((a, b, c), (d, e, f))
self.assertIsInstance(a, b, msg)
self.assertNotIsInstance(a, b, msg)
self.assertAlmostEqual(a, b)
self.assertNotAlmostEqual(a, b)
def test_asserttrue(self):
# ignored
self.assertTrue()
self.assertTrue(a, b, c)
# modified
self.assertTrue(a == b)
self.assertTrue(a == b, message)
self.assertTrue('a'
' string', message
)
self.failIf(a == b)
# some synonyms
self.failIf(a)
self.failUnless(a)
self.assert_(a)
# obvious_cleanup.py
# left alone
a == b
a != b
# modified
not a == b
not a != b
not a is not b
not a < b
not a > b
not a <= b
not a >= b
not a is not b
not a is b
a == None
a != None
dict([(a, b) for a, b in x])
dict((a, b) for a, b in x)
dict(((a, b) for a, b in x))
{a: b for a, b in x}
dict([(a, b) for a, b in x if y])
dict((a, b) for a, b in x if y)
dict(((a, b) for a, b in x if y))
{a: b for a, b in x if y}
dict([
(a, b)
for a, b in x
])
dict(
(a, b) for a, b
in x
)
dict(
(
(a, b) for a, b in x
)
)
set([a for a in x])
set((a for a in x))
set(a for a in x)
set([
a for a in x
])
set(
(
a for a in x
)
)
set(
a for a in x
)
def f():
self.assertRaises(foo, bar)
with self.assertRaises(x):
y()