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