@@ -754,6 +754,8 @@ class TestFuturizeStage1(CodeHandler):
754
754
the uncontroversial patches first.
755
755
"""
756
756
757
+ maxDiff = None
758
+
757
759
def test_apply (self ):
758
760
"""
759
761
apply() should be changed by futurize --stage1
@@ -1182,49 +1184,73 @@ def test_safe_division(self):
1182
1184
"""
1183
1185
before = """
1184
1186
import random
1187
+ class fraction(object):
1188
+ numer = 0
1189
+ denom = 0
1190
+ def __init__(self, numer, denom):
1191
+ self.numer = numer
1192
+ self.denom = denom
1193
+
1194
+ def total_count(self):
1195
+ return self.numer * 50
1196
+
1185
1197
x = 3 / 2
1186
1198
y = 3. / 2
1187
1199
foo = range(100)
1188
1200
assert x == 1 and isinstance(x, int)
1189
1201
assert y == 1.5 and isinstance(y, float)
1190
1202
a = 1 + foo[len(foo) / 2]
1191
1203
b = 1 + foo[len(foo) * 3 / 4]
1192
- assert a == 50
1193
- assert b == 75
1204
+ assert a == 51
1205
+ assert b == 76
1194
1206
r = random.randint(0, 1000) * 1.0 / 1000
1195
1207
output = { "SUCCESS": 5, "TOTAL": 10 }
1196
1208
output["SUCCESS"] * 100 / output["TOTAL"]
1197
- obj = foo
1209
+ obj = fraction(1, 50)
1198
1210
val = float(obj.numer) / obj.denom * 1e-9
1199
- mount.bytes_free * mount.free_size / bytes_in_gb
1200
- obj.total_count() * threshold / 100
1201
- 100 * abs(obj.width - original_width) / float(max(obj.width, original_width))
1202
- 100 * abs(obj.width - original_width) / max(obj.width, original_width)
1203
- float(target_width) * float(original_height) / float(original_width)
1211
+ obj.numer * obj.denom / val
1212
+ obj.total_count() * val / 100
1213
+ original_numer = 1
1214
+ original_denom = 50
1215
+ 100 * abs(obj.numer - original_numer) / float(max(obj.denom, original_denom))
1216
+ 100 * abs(obj.numer - original_numer) / max(obj.denom, original_denom)
1217
+ float(original_numer) * float(original_denom) / float(obj.numer)
1204
1218
"""
1205
1219
after = """
1206
1220
from __future__ import division
1207
1221
from past.utils import old_div
1208
1222
import random
1223
+ class fraction(object):
1224
+ numer = 0
1225
+ denom = 0
1226
+ def __init__(self, numer, denom):
1227
+ self.numer = numer
1228
+ self.denom = denom
1229
+
1230
+ def total_count(self):
1231
+ return self.numer * 50
1232
+
1209
1233
x = old_div(3, 2)
1210
1234
y = 3. / 2
1211
- foo = range(100)
1235
+ foo = list( range(100) )
1212
1236
assert x == 1 and isinstance(x, int)
1213
1237
assert y == 1.5 and isinstance(y, float)
1214
1238
a = 1 + foo[old_div(len(foo), 2)]
1215
1239
b = 1 + foo[old_div(len(foo) * 3, 4)]
1216
- assert a == 50
1217
- assert b == 75
1240
+ assert a == 51
1241
+ assert b == 76
1218
1242
r = old_div(random.randint(0, 1000) * 1.0, 1000)
1219
1243
output = { "SUCCESS": 5, "TOTAL": 10 }
1220
- output["SUCCESS"] * 100 / output["TOTAL"]
1221
- obj = foo
1244
+ old_div( output["SUCCESS"] * 100, output["TOTAL"])
1245
+ obj = fraction(1, 50)
1222
1246
val = float(obj.numer) / obj.denom * 1e-9
1223
- old_div(mount.bytes_free * mount.free_size, bytes_in_gb)
1224
- old_div(obj.total_count() * threshold, 100)
1225
- 100 * abs(obj.width - original_width) / float(max(obj.width, original_width))
1226
- 100 * abs(obj.width - original_width), max(obj.width, original_width))
1227
- float(target_width) * float(original_height) / float(original_width)
1247
+ old_div(obj.numer * obj.denom, val)
1248
+ old_div(obj.total_count() * val, 100)
1249
+ original_numer = 1
1250
+ original_denom = 50
1251
+ 100 * abs(obj.numer - original_numer) / float(max(obj.denom, original_denom))
1252
+ old_div(100 * abs(obj.numer - original_numer), max(obj.denom, original_denom))
1253
+ float(original_numer) * float(original_denom) / float(obj.numer)
1228
1254
"""
1229
1255
self .convert_check (before , after )
1230
1256
0 commit comments