Skip to content

Commit a0bb407

Browse files
committed
test flag parsing
1 parent 994f46f commit a0bb407

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

Lib/test/test_platform.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pickle
77
import platform
88
import subprocess
9+
import shlex
910
import sys
1011
import unittest
1112
from unittest import mock
@@ -777,10 +778,36 @@ def test_unknown_flag(self):
777778
_ = self.invoke_platform('--unknown')
778779

779780
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)
784811

785812
def test_help(self):
786813
output = io.StringIO()

0 commit comments

Comments
 (0)