@@ -20,15 +20,15 @@ def _actual_lines(path):
20
20
yield line
21
21
22
22
23
- def _expected_lines (path , check_prefix ):
23
+ def _expected_lines_and_line_numbers (path , check_prefix ):
24
24
"""
25
25
Returns a generator that yields each line in the file at the given path
26
26
that begins with the given prefix.
27
27
"""
28
28
with open (path ) as f :
29
- for line in f :
29
+ for line_number , line in enumerate ( f ) :
30
30
if line .startswith (check_prefix ):
31
- yield line [len (check_prefix ):]
31
+ yield line [len (check_prefix ):], line_number + 1
32
32
33
33
34
34
def compare (actual , expected , check_prefix ):
@@ -38,19 +38,23 @@ def compare(actual, expected, check_prefix):
38
38
file, raises an AssertionError. Also raises an AssertionError if the number
39
39
of lines in the two files differ.
40
40
"""
41
- for actual_line , expected_line in map (
41
+ for actual_line , expected_line_and_line_number in map (
42
42
None ,
43
43
_actual_lines (actual ),
44
- _expected_lines (expected , check_prefix )):
44
+ _expected_lines_and_line_numbers (expected , check_prefix )):
45
+
45
46
if actual_line is None :
46
47
raise AssertionError ('There were more lines expected to appear '
47
48
'than there were lines in the actual input.' )
48
- if expected_line is None :
49
+ if expected_line_and_line_number is None :
49
50
raise AssertionError ('There were more lines than expected to '
50
51
'appear.' )
52
+
53
+ (expected_line , expectation_source_line_number ) = expected_line_and_line_number
54
+
51
55
if not re .match (expected_line , actual_line ):
52
56
raise AssertionError ('Actual line did not match the expected '
53
57
'regular expression.\n '
54
- 'Actual: {}\n '
58
+ '{}:{}: Actual: {}\n '
55
59
'Expected: {}\n ' .format (
56
- repr (actual_line ), repr (expected_line )))
60
+ expected , expectation_source_line_number , repr (actual_line ), repr (expected_line )))
0 commit comments