From 10cd70432aa877bc77cd877ff5b43fe6aeded155 Mon Sep 17 00:00:00 2001 From: Llewellyn Falco Date: Sun, 3 Mar 2024 19:33:34 +0000 Subject: [PATCH] - r cleanup without individual commits Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com> Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com> Co-Authored-By: Nitsan Avni Co-Authored-By: Kevin Maes Co-Authored-By: blade290 <43077216+blade290@users.noreply.github.com> Co-Authored-By: jmasonlee <262853+jmasonlee@users.noreply.github.com> Co-Authored-By: T. E. Green <78671457+Tegsy@users.noreply.github.com> Co-Authored-By: Nazee Hajebi <2491283+NazeeHajebi@users.noreply.github.com> --- approvaltests/combination_approvals.py | 9 +++-- ...ests.test_with_labeled_input.approved.txt} | 0 tests/test_combinations.py | 36 ++++++++----------- 3 files changed, 18 insertions(+), 27 deletions(-) rename tests/approved_files/{VerifyAllCombinationsTests.test_2_uses_user_specified_formatter_when_supplied.approved.txt => VerifyAllCombinationsTests.test_with_labeled_input.approved.txt} (100%) diff --git a/approvaltests/combination_approvals.py b/approvaltests/combination_approvals.py index a896366..c51bb32 100644 --- a/approvaltests/combination_approvals.py +++ b/approvaltests/combination_approvals.py @@ -63,9 +63,9 @@ def verify_all_combinations_with_labeled_input( ) -> None: labels = list(kwargs.keys()) input_arguments = [kwargs[key] for key in kwargs] - def formatter(args, output): - text = ", ".join([f"{label}: {arg}" for label, arg in zip(labels, args)]) - return f"({text}) => {output}\n" + def formatter(inputs, output): + labeled_inputs = ", ".join([f"{label}: {input}" for label, input in zip(labels, inputs)]) + return f"({labeled_inputs}) => {output}\n" verify_all_combinations(function_under_test, input_arguments, formatter=formatter, options=options) @@ -75,8 +75,7 @@ def verify_all_combinations( formatter: Optional[Callable] = None, reporter: Optional[ReporterForTesting] = None, *, # enforce keyword arguments - https://www.python.org/dev/peps/pep-3102/ - options: Optional[Options] = None, - **kwargs + options: Optional[Options] = None ) -> None: """Run func with all possible combinations of args and verify outputs against the recorded approval file. diff --git a/tests/approved_files/VerifyAllCombinationsTests.test_2_uses_user_specified_formatter_when_supplied.approved.txt b/tests/approved_files/VerifyAllCombinationsTests.test_with_labeled_input.approved.txt similarity index 100% rename from tests/approved_files/VerifyAllCombinationsTests.test_2_uses_user_specified_formatter_when_supplied.approved.txt rename to tests/approved_files/VerifyAllCombinationsTests.test_with_labeled_input.approved.txt diff --git a/tests/test_combinations.py b/tests/test_combinations.py index 0139321..60228cf 100644 --- a/tests/test_combinations.py +++ b/tests/test_combinations.py @@ -1,12 +1,11 @@ import unittest -from approvaltests import Options from approvaltests.approval_exception import ApprovalException from approvaltests.combination_approvals import ( verify_all_combinations, verify_all_combinations_with_namer, verify_all_combinations_with_labeled_input, ) -from approvaltests.reporters import CommandLineReporter, ReporterThatAutomaticallyApproves +from approvaltests.reporters import CommandLineReporter from approvaltests.reporters.testing_reporter import ReporterForTesting @@ -16,7 +15,7 @@ def setUp(self) -> None: self.func = lambda *args: sum(args) + 1 def test_fails_for_mismatch_with_for_func_accepting_one_arg_and_combination_of_one_arg( - self, + self, ) -> None: arg1_combinations = (1,) all_args_combinations = (arg1_combinations,) @@ -33,7 +32,7 @@ def test_passes_for_func_accepting_one_arg_and_combination_of_one_arg(self) -> N ) def test_fails_for_mismatch_with_for_func_accepting_one_arg_and_combination_of_two_args( - self, + self, ) -> None: arg1_combinations = (1, 2) all_args_combinations = (arg1_combinations,) @@ -43,7 +42,7 @@ def test_fails_for_mismatch_with_for_func_accepting_one_arg_and_combination_of_t ) def test_passes_for_func_accepting_one_arg_and_combination_of_two_args( - self, + self, ) -> None: arg1_combinations = (1, 2) all_args_combinations = (arg1_combinations,) @@ -52,7 +51,7 @@ def test_passes_for_func_accepting_one_arg_and_combination_of_two_args( ) def test_fails_for_mismatch_with_for_func_accepting_two_args_and_combination_of_one_arg( - self, + self, ) -> None: arg1_combinations = (1,) arg2_combinations = (2,) @@ -63,7 +62,7 @@ def test_fails_for_mismatch_with_for_func_accepting_two_args_and_combination_of_ ) def test_passes_for_func_accepting_two_args_and_combination_of_one_arg( - self, + self, ) -> None: arg1_combinations = (1,) arg2_combinations = (2,) @@ -71,7 +70,7 @@ def test_passes_for_func_accepting_two_args_and_combination_of_one_arg( verify_all_combinations(self.func, arg_combinations, reporter=self.reporter) def test_fails_for_mismatch_with_for_func_accepting_two_args_and_combination_of_two_args( - self, + self, ) -> None: arg1_combinations = (1, 3) arg2_combinations = (2, 4) @@ -95,7 +94,7 @@ def test_when_arg_combinations_have_equal_lengths(self) -> None: verify_all_combinations(self.func, arg_combinations, reporter=self.reporter) def test_records_exception_message_when_function_under_test_throws_an_exception( - self, + self, ) -> None: def function_that_raises_exceptions(*args): raise Exception(args) @@ -115,27 +114,20 @@ def test_uses_user_specified_formatter_when_supplied(self) -> None: self.func, arg_combinations, formatter=lambda args, output: "inputs=" - + str(args) - + ", outputs=" - + str(output) - + "\n", + + str(args) + + ", outputs=" + + str(output) + + "\n", reporter=self.reporter, ) - def test_2_uses_user_specified_formatter_when_supplied(self) -> None: - """ - (arg1: 1, arg2: 2) => 4 - (arg1: 1, arg2: 4) => 6 - (arg1: 3, arg2: 2) => 6 - (arg1: 3, arg2: 4) => 8 - """ + def test_with_labeled_input(self) -> None: verify_all_combinations_with_labeled_input( self.func, arg1=(1, 3), arg2=(2, 4), ) - def applesauce(self,*, options = None,**kwargs): - return kwargs + class VerifyAllCombinationsWithNamerTests(unittest.TestCase): def setUp(self) -> None: