Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_full(self):
namer = get_default_namer()
writer = StringWriter("b")
reporter = ReporterForTesting()
approver = FileApprover()
approver.verify(namer, writer, reporter)
self.assertTrue(reporter.called)
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)
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_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)
self.assertEqual(None, error)
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)
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)