diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-07-04 12:17:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-04 12:17:26 (GMT) |
commit | 9f8aa7a6d79eb71c339fface8f8570607b8d1cf2 (patch) | |
tree | 3c0ea9cd286ba44cea58879f3542c975d2645ec1 | |
parent | 3cc5c4a073d63534e45fc08d7906a77180e8aaa3 (diff) | |
download | cpython-9f8aa7a6d79eb71c339fface8f8570607b8d1cf2.zip cpython-9f8aa7a6d79eb71c339fface8f8570607b8d1cf2.tar.gz cpython-9f8aa7a6d79eb71c339fface8f8570607b8d1cf2.tar.bz2 |
[3.11] gh-106368: Add tests for permutation helpers in Argument Clinic (GH-106407) (#106410)
Added new test class PermutationTests()
(cherry picked from commit 8f6df5e9cbc3a1689601714192aa6ecbb23e1927)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
-rw-r--r-- | Lib/test/test_clinic.py | 106 | ||||
-rwxr-xr-x | Tools/clinic/clinic.py | 4 |
2 files changed, 108 insertions, 2 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index dafdfc2..8c9fe99 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -1518,5 +1518,111 @@ class ClinicFunctionalTest(unittest.TestCase): ac_tester.gh_99240_double_free('a', '\0b') +class PermutationTests(unittest.TestCase): + """Test permutation support functions.""" + + def test_permute_left_option_groups(self): + expected = ( + (), + (3,), + (2, 3), + (1, 2, 3), + ) + data = list(zip([1, 2, 3])) # Generate a list of 1-tuples. + actual = tuple(clinic.permute_left_option_groups(data)) + self.assertEqual(actual, expected) + + def test_permute_right_option_groups(self): + expected = ( + (), + (1,), + (1, 2), + (1, 2, 3), + ) + data = list(zip([1, 2, 3])) # Generate a list of 1-tuples. + actual = tuple(clinic.permute_right_option_groups(data)) + self.assertEqual(actual, expected) + + def test_permute_optional_groups(self): + empty = { + "left": (), "required": (), "right": (), + "expected": ((),), + } + noleft1 = { + "left": (), "required": ("b",), "right": ("c",), + "expected": ( + ("b",), + ("b", "c"), + ), + } + noleft2 = { + "left": (), "required": ("b", "c",), "right": ("d",), + "expected": ( + ("b", "c"), + ("b", "c", "d"), + ), + } + noleft3 = { + "left": (), "required": ("b", "c",), "right": ("d", "e"), + "expected": ( + ("b", "c"), + ("b", "c", "d"), + ("b", "c", "d", "e"), + ), + } + noright1 = { + "left": ("a",), "required": ("b",), "right": (), + "expected": ( + ("b",), + ("a", "b"), + ), + } + noright2 = { + "left": ("a",), "required": ("b", "c"), "right": (), + "expected": ( + ("b", "c"), + ("a", "b", "c"), + ), + } + noright3 = { + "left": ("a", "b"), "required": ("c",), "right": (), + "expected": ( + ("c",), + ("b", "c"), + ("a", "b", "c"), + ), + } + leftandright1 = { + "left": ("a",), "required": ("b",), "right": ("c",), + "expected": ( + ("b",), + ("a", "b"), # Prefer left. + ("a", "b", "c"), + ), + } + leftandright2 = { + "left": ("a", "b"), "required": ("c", "d"), "right": ("e", "f"), + "expected": ( + ("c", "d"), + ("b", "c", "d"), # Prefer left. + ("a", "b", "c", "d"), # Prefer left. + ("a", "b", "c", "d", "e"), + ("a", "b", "c", "d", "e", "f"), + ), + } + dataset = ( + empty, + noleft1, noleft2, noleft3, + noright1, noright2, noright3, + leftandright1, leftandright2, + ) + for params in dataset: + with self.subTest(**params): + left, required, right, expected = params.values() + permutations = clinic.permute_optional_groups(left, required, right) + actual = tuple(permutations) + self.assertEqual(actual, expected) + + if __name__ == "__main__": unittest.main() diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 82e4919..b18c020 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -460,7 +460,7 @@ class PythonLanguage(Language): def permute_left_option_groups(l): """ - Given [1, 2, 3], should yield: + Given [(1,), (2,), (3,)], should yield: () (3,) (2, 3) @@ -475,7 +475,7 @@ def permute_left_option_groups(l): def permute_right_option_groups(l): """ - Given [1, 2, 3], should yield: + Given [(1,), (2,), (3,)], should yield: () (1,) (1, 2) |