Ejemplo n.º 1
0
 def test_compare_rows_invalid_columns(self):
     """
         Row comparison should raise an error if
         `comparison_columns` is not a subset of `display_columns`
     """
     with pytest.raises(ValueError):
         assertions.compare_rows(
             table=[], expected_table=[],
             comparison_columns=['foo', 'bar'],
             display_columns=['bar', 'baz'],
         )
Ejemplo n.º 2
0
 def test_compare_rows(self, table, expected_table, comparison_columns,
                       display_columns, strict, fail_limit,
                       expected_result):
     assert assertions.compare_rows(
         table=table,
         expected_table=expected_table,
         comparison_columns=comparison_columns,
         display_columns=display_columns,
         strict=strict,
         fail_limit=fail_limit) == expected_result
Ejemplo n.º 3
0
    def test_compare_rows_error(self):
        """
            Getting exact traceback is not very
            trivial so we have this test separate.
        """
        error_ctx = {}

        def error_func(value):
            try:
                raise Exception('some message')
            except Exception as exc:
                error_ctx['msg'] = format_trace(inspect.trace(), exc)
                raise

        table = [
            {'foo': 1, 'bar': 2}
        ]

        expected_table = [
            {'foo': 1, 'bar': error_func}
        ]

        passed, row_comparisons = assertions.compare_rows(
            table=table, expected_table=expected_table,
            comparison_columns=['foo', 'bar'],
            display_columns=['foo', 'bar'],
            strict=True,
            fail_limit=0,
        )

        row_comparison = row_comparisons[0]

        traceback_regex = re.compile(r'raise\s{1}')

        error_orig = row_comparison.errors['bar']
        error_expected = error_ctx['msg']

        error_orig = error_orig[traceback_regex.search(
            error_orig).start():]
        error_expected = error_expected[traceback_regex.search(
            error_expected).start():]

        assert passed is False
        assert row_comparison.idx == 0
        assert row_comparison.data == [1, 2]
        assert row_comparison.diff == {}
        assert error_orig == error_expected
        assert row_comparison.extra == {'bar': error_func}
Ejemplo n.º 4
0
    def test_compare_rows_error(self):
        """
            Getting exact traceback is not very
            trivial so we have this test separate.
        """
        error_ctx = {}

        def error_func(value):
            try:
                raise Exception("some message")
            except Exception:
                error_ctx["msg"] = traceback.format_exc()
                raise

        table = [{"foo": 1, "bar": 2}]

        expected_table = [{"foo": 1, "bar": error_func}]

        passed, row_comparisons = assertions.compare_rows(
            table=table,
            expected_table=expected_table,
            comparison_columns=["foo", "bar"],
            display_columns=["foo", "bar"],
            strict=True,
            fail_limit=0,
        )

        row_comparison = row_comparisons[0]

        traceback_regex = re.compile(r"raise\s{1}")

        error_orig = row_comparison.errors["bar"]
        error_expected = error_ctx["msg"]

        error_orig = error_orig[traceback_regex.search(error_orig).start() :]
        error_expected = error_expected[
            traceback_regex.search(error_expected).start() :
        ]

        assert passed is False
        assert row_comparison.idx == 0
        assert row_comparison.data == [1, 2]
        assert row_comparison.diff == {}
        assert error_orig == error_expected
        assert row_comparison.extra == {"bar": error_func}
Ejemplo n.º 5
0
 def test_compare_rows(
     self,
     table,
     expected_table,
     comparison_columns,
     display_columns,
     strict,
     fail_limit,
     report_fails_only,
     expected_result,
 ):
     assert (
         assertions.compare_rows(
             table=table,
             expected_table=expected_table,
             comparison_columns=comparison_columns,
             display_columns=display_columns,
             strict=strict,
             fail_limit=fail_limit,
             report_fails_only=report_fails_only,
         )
         == expected_result
     )