renaming tests refactored. It's now much easier and understandable to create rename tests

This commit is contained in:
David Halter
2012-12-24 17:12:46 +01:00
parent bd93f8fd2d
commit 6322df11f3
2 changed files with 33 additions and 24 deletions

View File

@@ -3,10 +3,10 @@ Renaming tests. This means search for related names.
I always leave a little bit of space to add room for additions, because the
results always contain position informations.
"""
#< 4 (7,4), (10,0), (12,0)
#< 4 (0,4), (3,0), (5,0)
def abc(): pass
#< 0 (7,4), (10,0), (12,0)
#< 0 (-3,4), (0,0), (2,0)
abc.d.a.bsaasd.abc.d
abc
@@ -19,29 +19,29 @@ abc
abc =
#< (20,0), (23,0)
#< (-3,0), (0,0)
abc
Abc = 3
#< 6 (30,6), (32,4), (35,8), (47,0)
#< 6 (0,6), (2,4), (5,8), (17,0)
class Abc():
#< (30,6), (32,4), (35,8), (47,0)
#< (-2,6), (0,4), (3,8), (15,0)
Abc
def Abc(self):
Abc; self.c = 3
#< 17 (38,16), (40,8)
#< 17 (0,16), (2,8)
def a(self, Abc):
#< 10 (38,16), (40,8)
#< 10 (-2,16), (0,8)
Abc
#< 19 (43,18), (45,8)
#< 19 (0,18), (2,8)
def self_test(self):
#< 12 (43,18), (45,8)
#< 12 (-2,18), (0,8)
self.b
Abc.d.Abc
@@ -51,49 +51,49 @@ Abc.d.Abc
#< 4 (55,4), (59,1)
#< 4 (0,4), (4,1)
def blub():
#< (55,4), (59,1)
#< (-4,4), (0,1)
@blub
def a(): pass
#< (65,7), (68,0)
#< (0,7), (3,0)
import module_not_exists
#< (65,7), (68,0)
#< (-3,7), (0,0)
module_not_exists
#< (1,0), (75,24), (78,0), (81,17), (4,5), (85,17), (88,17)
#< ('rename1', 1,0), (0,24), (3,0), (6,17), ('rename2', 4,5), (10,17), (13,17)
from import_tree import rename1
#< (78,8), (3,0), (4,20), (6,0), (81,32), (85,32), (82,0)
#< (0,8), ('rename1',3,0), ('rename2',4,20), ('rename2',6,0), (3,32), (7,32), (4,0)
rename1.abc
#< (78,8), (3,0), (4,20), (6,0), (81,32), (85,32), (82,0)
#< (-3,8), ('rename1', 3,0), ('rename2', 4,20), ('rename2', 6,0), (0,32), (4,32), (1,0)
from import_tree.rename1 import abc
abc
#< 20 (1,0), (4,5), (75,24), (78,0), (81,17), (85,17), (88,17)
#< 20 ('rename1', 1,0), ('rename2', 4,5), (-10,24), (-7,0), (-4,17), (0,17), (3,17)
from import_tree.rename1 import abc
#< (88, 32),
#< (0, 32),
from import_tree.rename1 import not_existing
response = 5
#< 0 (95, 0), (96, 0), (97, 0), (99, 0)
#< 0 (0,0), (1,0), (2,0), (4,0)
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s.pdf' % id
response.write(pdf)
#< (95, 0), (96, 0), (97, 0), (99, 0)
#< (-4,0), (-3,0), (-2,0), (0,0)
response

View File

@@ -85,11 +85,20 @@ def run_related_name_test(script, correct, line_nr):
"""
result = script.related_names()
correct = correct.strip()
comp_str = sorted(r.start_pos for r in result)
correct = sorted(literal_eval(correct))
if sorted(comp_str) != sorted(correct):
compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1])
for r in result)
wanted = []
for pos_tup in literal_eval(correct):
if type(pos_tup[0]) == str:
# this means that there is a module specified
wanted.append(pos_tup)
else:
wanted.append(('renaming', line_nr + pos_tup[0], pos_tup[1]))
wanted = sorted(wanted)
if compare != wanted:
print('Solution @%s not right, received %s, wanted %s'\
% (line_nr - 1, comp_str, correct))
% (line_nr - 1, compare, wanted))
return 1
return 0