Skip to content

Commit

Permalink
- r cleanup without individual commits
Browse files Browse the repository at this point in the history
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 <nitsanav@gmail.com>
Co-Authored-By: Kevin Maes <kevin@kevinmaes.com>
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>
  • Loading branch information
9 people committed Mar 3, 2024
1 parent 23cf124 commit 10cd704
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
9 changes: 4 additions & 5 deletions approvaltests/combination_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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.
Expand Down
36 changes: 14 additions & 22 deletions tests/test_combinations.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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,)
Expand All @@ -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,)
Expand All @@ -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,)
Expand All @@ -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,)
Expand All @@ -63,15 +62,15 @@ 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,)
arg_combinations = (arg1_combinations, arg2_combinations)
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)
Expand All @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 10cd704

Please sign in to comment.