def test_unclosed_not_in_spec_block(self): # Can only occur in implementation code since these come from # undo_amendments with pytest.raises(ComparisonError) as exc_info: compare_sources("", "## Begin not in spec", Identical()) assert format_summary(exc_info.value) == ( "'## Begin not in spec' block not closed (in implementation code, line 1)" )
def test_tokenisation_errors(self): # Can only occur in implementation code since these come from # undo_amendments with pytest.raises(ComparisonError) as exc_info: compare_sources("", "[", Identical()) assert format_summary(exc_info.value) == ( "EOF in multi-line statement (in implementation code, line 2 col 0)" )
def test_bad_amendment_comment(self): # Can only occur in implementation code since these come from # undo_amendments with pytest.raises(ComparisonError) as exc_info: compare_sources("", "## Foobar", Identical()) assert format_summary( exc_info.value) == ("Unrecognised amendment comment '## Foobar' " "(in implementation code, line 1 col 0)")
def test_differing_field_lengths(self): assert format_summary( compare_sources("foo(a, b)", "foo(a, b, c, d)", Identical())) == ( "2 extra values in implementation's args (in reference code, " "line 1 col 7 and implementation code, line 1 col 13)") assert format_summary( compare_sources("foo(a, b, c)", "foo(a, b)", Identical())) == ( "1 extra value in reference's args (in reference code, " "line 1 col 10 and implementation code, line 1 col 7)")
def test_syntax_errors(self): # NB: Syntax error reported column numbers differ depending on the # python interpreter used. with pytest.raises(ComparisonError) as exc_info: compare_sources("1 +/", "", Identical()) assert (re.match( r"invalid syntax \(in reference code, line 1 col [34]\)", format_summary(exc_info.value), ) is not None) with pytest.raises(ComparisonError) as exc_info: compare_sources("", "1 +/", Identical()) assert (re.match( r"invalid syntax \(in implementation code, line 1 col [34]\)", format_summary(exc_info.value), ) is not None)
def test_same(self): assert (compare_sources( ("def foo(a, b, c):\n" " return a + b + c\n"), ("def foo(a,b,c): return a+b+c\n"), Identical(), ) is True)
def test_ammendments_not_applied_to_reference(self): assert (compare_sources( ("def foo(a, b, c):\n" " print(a, b, c) ## Not in spec\n" " return a + b + c\n"), ("def foo(a, b, c):\n" " return a + b + c\n"), Identical(), ) is not True)
def test_amendment_makes_same(self): assert (compare_sources( ("def foo(a, b, c):\n" " return a + b + c\n"), ("def foo(a, b, c):\n" " print(a, b, c) ## Not in spec\n" " return a + b + c\n"), Identical(), ) is True)
def test_differing_node_types(self): assert format_summary( compare_sources( ("def foo(a, b):\n" " return a + b\n"), ("def foo(a, b): return a - b\n"), Identical(), )) == ( "Mismatched Add vs. Sub (in reference code, line 2 col 10 and " "implementation code, line 1 col 22)")
def test_differing_field_values(self): assert format_summary(compare_sources( "a + b", "a+cde", Identical())) == ( "Different id values (in reference code, line 1 col 4 and " "implementation code, line 1 col 2)")