@@ -754,6 +754,8 @@ class TestFuturizeStage1(CodeHandler):
754754 the uncontroversial patches first.
755755 """
756756
757+ maxDiff = None
758+
757759 def test_apply (self ):
758760 """
759761 apply() should be changed by futurize --stage1
@@ -1182,49 +1184,73 @@ def test_safe_division(self):
11821184 """
11831185 before = """
11841186 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+
11851197 x = 3 / 2
11861198 y = 3. / 2
11871199 foo = range(100)
11881200 assert x == 1 and isinstance(x, int)
11891201 assert y == 1.5 and isinstance(y, float)
11901202 a = 1 + foo[len(foo) / 2]
11911203 b = 1 + foo[len(foo) * 3 / 4]
1192- assert a == 50
1193- assert b == 75
1204+ assert a == 51
1205+ assert b == 76
11941206 r = random.randint(0, 1000) * 1.0 / 1000
11951207 output = { "SUCCESS": 5, "TOTAL": 10 }
11961208 output["SUCCESS"] * 100 / output["TOTAL"]
1197- obj = foo
1209+ obj = fraction(1, 50)
11981210 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)
12041218 """
12051219 after = """
12061220 from __future__ import division
12071221 from past.utils import old_div
12081222 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+
12091233 x = old_div(3, 2)
12101234 y = 3. / 2
1211- foo = range(100)
1235+ foo = list( range(100) )
12121236 assert x == 1 and isinstance(x, int)
12131237 assert y == 1.5 and isinstance(y, float)
12141238 a = 1 + foo[old_div(len(foo), 2)]
12151239 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
12181242 r = old_div(random.randint(0, 1000) * 1.0, 1000)
12191243 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)
12221246 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)
12281254 """
12291255 self .convert_check (before , after )
12301256
0 commit comments