Beispiel #1
0
    def test_full_reference(self, T):
        def f():
            pass

        assert format_summary(
            T(
                "foobar",
                ref_row=1000,
                ref_col=10,
                ref_func=f,
            )) == "foobar (in reference code, line {} col 10 of {})".format(
                1000 + inspect.getsourcelines(f)[1],
                _test_script_filename,
            )

        assert format_summary(
            T(
                "foobar",
                imp_row=1000,
                imp_col=10,
                imp_func=f,
            )
        ) == "foobar (in implementation code, line {} col 10 of {})".format(
            1000 + inspect.getsourcelines(f)[1],
            _test_script_filename,
        )
Beispiel #2
0
 def test_just_line_number(self, T):
     assert (format_summary(T(
         "foobar",
         ref_row=123,
     )) == "foobar (in reference code, line 123)")
     assert (format_summary(T(
         "foobar",
         imp_row=123,
     )) == "foobar (in implementation code, line 123)")
Beispiel #3
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)")
Beispiel #4
0
    def test_just_line_and_column_number(self, T):
        assert (format_summary(T(
            "foobar",
            ref_row=123,
            ref_col=10,
        )) == "foobar (in reference code, line 123 col 10)")

        assert (format_summary(T(
            "foobar",
            imp_row=123,
            imp_col=10,
        )) == "foobar (in implementation code, line 123 col 10)")
Beispiel #5
0
    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)
Beispiel #6
0
 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)"
     )
Beispiel #7
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)")
Beispiel #8
0
 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)"
     )
Beispiel #9
0
 def test_both_functions_at_once(self, T):
     assert (
         format_summary(T(
             "foobar",
             ref_row=123,
             imp_row=321,
         )) ==
         "foobar (in reference code, line 123 and implementation code, line 321)"
     )
Beispiel #10
0
 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)")
Beispiel #11
0
 def test_just_message(self, T):
     assert format_summary(T("foobar")) == "foobar"
Beispiel #12
0
 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)")