|
6 | 6 | import pickle |
7 | 7 | import platform |
8 | 8 | import subprocess |
| 9 | +import shlex |
9 | 10 | import sys |
10 | 11 | import unittest |
11 | 12 | from unittest import mock |
@@ -777,10 +778,36 @@ def test_unknown_flag(self): |
777 | 778 | _ = self.invoke_platform('--unknown') |
778 | 779 |
|
779 | 780 | def test_invocation(self): |
780 | | - self.invoke_platform("--terse", "--nonaliased") |
781 | | - self.invoke_platform("--nonaliased") |
782 | | - self.invoke_platform("--terse") |
783 | | - self.invoke_platform() |
| 781 | + flags = ( |
| 782 | + "--terse", "--nonaliased", "terse", "nonaliased" |
| 783 | + ) |
| 784 | + |
| 785 | + for r in range(len(flags) + 1): |
| 786 | + for combination in itertools.combinations(flags, r): |
| 787 | + self.invoke_platform(*combination) |
| 788 | + |
| 789 | + def test_arg_parsing(self): |
| 790 | + # Due to backwards compatibility, the `aliased` and `terse` parameters |
| 791 | + # are computed based on a combination of positional arguments and flags. |
| 792 | + # |
| 793 | + # This test tests that the arguments are correctly passed to the underlying |
| 794 | + # `platform.platform()` call. The parameters are two booleans for `aliased` |
| 795 | + # and `terse` |
| 796 | + options = ( |
| 797 | + ("--nonaliased", (False, False)), |
| 798 | + ("nonaliased", (False, False)), |
| 799 | + ("--terse", (True, True)), |
| 800 | + ("terse", (True, True)), |
| 801 | + ("nonaliased terse", (False, True)), |
| 802 | + ("--nonaliased terse", (False, True)), |
| 803 | + ("--terse nonaliased", (False, True)), |
| 804 | + ) |
| 805 | + |
| 806 | + for flags, args in options: |
| 807 | + with self.subTest(f"{flags}, {args}"): |
| 808 | + with mock.patch.object(platform, 'platform') as obj: |
| 809 | + self.invoke_platform(*shlex.split(flags)) |
| 810 | + obj.assert_called_once_with(*args) |
784 | 811 |
|
785 | 812 | def test_help(self): |
786 | 813 | output = io.StringIO() |
|
0 commit comments