Exemplo n.º 1
0
 def test_full(self):
     namer = get_default_namer()
     writer = StringWriter("b")
     reporter = ReporterForTesting()
     approver = FileApprover()
     approver.verify(namer, writer, reporter, Options().comparator)
     self.assertTrue(reporter.called)
Exemplo n.º 2
0
 def test_returns_none_when_files_are_same_files(self):
     namer = get_default_namer()
     writer = StringWriter("b")
     reporter = GenericDiffReporterFactory().get_first_working()
     approver = FileApprover()
     error = approver.verify(namer, writer, reporter, Options().comparator)
     self.assertEqual(None, error)
Exemplo n.º 3
0
 def test_returns_error_when_files_are_different(self):
     namer = get_default_namer()
     writer = StringWriter("b")
     reporter = ReporterForTesting()
     approver = FileApprover()
     error = approver.verify(namer, writer, reporter)
     self.assertEqual("Approval Mismatch", error)
Exemplo n.º 4
0
 def test_passes_for_func_accepting_one_arg_and_combination_of_one_arg(self) -> None:
     arg1_combinations = (1,)
     all_args_combinations = (arg1_combinations,)
     namer = get_default_namer()
     verify_all_combinations_with_namer(
         self.func, all_args_combinations, namer, reporter=self.reporter
     )
Exemplo n.º 5
0
def assert_equal_with_reporter(expected, actual, reporter=None):
    if actual == expected:
        return

    name = get_default_namer().get_file_name()
    expected_file = write_to_temporary_file(expected, name + '.expected.')
    actual_file = write_to_temporary_file(actual, name + '.actual.')
    get_reporter(reporter).report(actual_file, expected_file)
    raise AssertionError('expected != actual\n  actual: "{}"\nexpected: "{}"'.format(actual, expected))
    def test_returns_error_when_files_are_different(self):
        namer = get_default_namer()
        writer = StringWriter("b")
        reporter = ReporterForTesting()
        approver = FileApprover()
        error = approver.verify(namer, writer, reporter)
        import re
        replaced = re.sub("ved: .*approved_files.", 'ved: <rootdir>/', error)

        verify(replaced)
Exemplo n.º 7
0
def assert_equal_with_reporter(expected, actual, reporter=None):
    if actual == expected:
        return

    name = get_default_namer().get_file_name()
    expected_file = write_to_temporary_file(expected, name + '.expected.')
    actual_file = write_to_temporary_file(actual, name + '.actual.')
    get_reporter(reporter).report(actual_file, expected_file)
    raise AssertionError(
        'expected != actual\n  actual: "{}"\nexpected: "{}"'.format(
            actual, expected))
def verify_all_combinations(function_under_test, input_arguments, formatter=None, reporter=None):
    """Run func with all possible combinations of args and verify outputs against the recorded approval file.

    Args:
        function_under_test (function): function under test.
        input_arguments: list of values to test for each input argument.  For example, a function f(product, quantity)
            could be tested with the input_arguments [['water', 'cola'], [1, 4]], which would result in outputs for the
            following calls being recorded and verified: f('water', 1), f('water', 4), f('cola', 1), f('cola', 4).
        formatter (function): function for formatting the function inputs/outputs before they are recorded to an
            approval file for comparison.
        reporter (approvaltests.reporter.Reporter): an approval reporter.

    Raises:
        ApprovalException: if the results to not match the approved results.
    """
    namer = get_default_namer()
    verify_all_combinations_with_namer(function_under_test, input_arguments, namer, formatter, reporter)
Exemplo n.º 9
0
def verify_all_combinations(function_under_test,
                            input_arguments,
                            formatter=None,
                            reporter=None):
    """Run func with all possible combinations of args and verify outputs against the recorded approval file.

    Args:
        function_under_test (function): function under test.
        input_arguments: list of values to test for each input argument.  For example, a function f(product, quantity)
            could be tested with the input_arguments [['water', 'cola'], [1, 4]], which would result in outputs for the
            following calls being recorded and verified: f('water', 1), f('water', 4), f('cola', 1), f('cola', 4).
        formatter (function): function for formatting the function inputs/outputs before they are recorded to an
            approval file for comparison.
        reporter (approvaltests.reporter.Reporter): an approval reporter.

    Raises:
        ApprovalException: if the results to not match the approved results.
    """
    namer = get_default_namer()
    verify_all_combinations_with_namer(function_under_test, input_arguments,
                                       namer, formatter, reporter)
Exemplo n.º 10
0
    def namer(self) -> Namer:
        from approvaltests import get_default_namer

        namer = get_default_namer()
        namer.set_extension(self.fields.get("extension_with_dot", ".txt"))
        return namer
 def test_passes_for_func_accepting_one_arg_and_combination_of_one_arg(self):
     arg1_combinations = (1,)
     all_args_combinations = (arg1_combinations,)
     namer= get_default_namer()
     verify_all_combinations_with_namer(self.func, all_args_combinations, namer, reporter=self.reporter)
Exemplo n.º 12
0
def assert_against_file(actual, file_path, reporter=None):
    namer = get_default_namer()
    namer.get_approved_filename = lambda self,_=None: file_path
    verify_with_namer(actual, namer, reporter)
Exemplo n.º 13
0
def assert_against_file(actual, file_path, reporter=None):
    namer = get_default_namer()
    namer.get_approved_filename = lambda self, _=None: file_path
    verify_with_namer(actual, namer, reporter)