summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2022-05-21 12:25:49 +0200
committerStephen Finucane <stephenfinucane@hotmail.com>2022-05-22 10:09:12 +0100
commit2586621e3c200e11d29619ed814e704d9f464fea (patch)
treeb235476f9e7777232e4d5869e594ec98b7c019b4
parentf50d2207b14c961c867a8c02225e724110f3be2b (diff)
downloadfixtures-git-2586621e3c200e11d29619ed814e704d9f464fea.tar.gz
Support Popen's process_group argument from Python 3.11
-rw-r--r--fixtures/_fixtures/popen.py9
-rw-r--r--fixtures/tests/_fixtures/test_popen.py14
2 files changed, 21 insertions, 2 deletions
diff --git a/fixtures/_fixtures/popen.py b/fixtures/_fixtures/popen.py
index ffa9bf4..a099854 100644
--- a/fixtures/_fixtures/popen.py
+++ b/fixtures/_fixtures/popen.py
@@ -131,7 +131,8 @@ class FakePopen(Fixture):
restore_signals=_unpassed, start_new_session=_unpassed,
pass_fds=_unpassed, *, group=_unpassed, extra_groups=_unpassed,
user=_unpassed, umask=_unpassed, encoding=_unpassed,
- errors=_unpassed, text=_unpassed, pipesize=_unpassed):
+ errors=_unpassed, text=_unpassed, pipesize=_unpassed,
+ process_group=_unpassed):
# Reject arguments introduced by newer versions of Python in older
# versions; this makes it harder to accidentally hide compatibility
# problems using test doubles.
@@ -149,6 +150,10 @@ class FakePopen(Fixture):
raise TypeError(
"FakePopen.__call__() got an unexpected keyword argument "
"'pipesize'")
+ if sys.version_info < (3, 11) and process_group is not FakePopen._unpassed:
+ raise TypeError(
+ "FakePopen.__call__() got an unexpected keyword argument "
+ "'process_group'")
proc_args = dict(args=args)
local = locals()
@@ -158,7 +163,7 @@ class FakePopen(Fixture):
"universal_newlines", "startupinfo", "creationflags",
"restore_signals", "start_new_session", "pass_fds", "group",
"extra_groups", "user", "umask", "encoding", "errors", "text",
- "pipesize"]:
+ "pipesize", "process_group"]:
if local[param] is not FakePopen._unpassed:
proc_args[param] = local[param]
proc_info = self.get_info(proc_args)
diff --git a/fixtures/tests/_fixtures/test_popen.py b/fixtures/tests/_fixtures/test_popen.py
index c7bf1bd..e9ab074 100644
--- a/fixtures/tests/_fixtures/test_popen.py
+++ b/fixtures/tests/_fixtures/test_popen.py
@@ -74,6 +74,8 @@ class TestFakePopen(testtools.TestCase, TestWithFixtures):
all_args["umask"] = "umask"
if sys.version_info >= (3, 10):
all_args["pipesize"] = "pipesize"
+ if sys.version_info >= (3, 11):
+ all_args["process_group"] = "process_group"
def get_info(proc_args):
self.assertEqual(all_args, proc_args)
@@ -110,6 +112,15 @@ class TestFakePopen(testtools.TestCase, TestWithFixtures):
r".* got an unexpected keyword argument 'pipesize'"):
fixture(args="args", pipesize=1024)
+ @testtools.skipUnless(
+ sys.version_info < (3, 11), "only relevant on Python <3.11")
+ def test_rejects_3_11_args_on_older_versions(self):
+ fixture = self.useFixture(FakePopen(lambda proc_args: {}))
+ with testtools.ExpectedException(
+ TypeError,
+ r".* got an unexpected keyword argument 'process_group'"):
+ fixture(args="args", process_group=42)
+
def test_function_signature(self):
fake_signature = inspect.getfullargspec(FakePopen.__call__)
real_signature = inspect.getfullargspec(subprocess.Popen)
@@ -130,6 +141,9 @@ class TestFakePopen(testtools.TestCase, TestWithFixtures):
fake_kwargs = set(fake_signature.kwonlyargs)
real_kwargs = set(real_signature.kwonlyargs)
+ if sys.version_info < (3, 11):
+ fake_kwargs.remove('process_group')
+
if sys.version_info < (3, 10):
fake_kwargs.remove('pipesize')