Skip to content

Commit ba22385

Browse files
committed
Drop support for Python 2.7, 3.5, 3.6
1 parent e4ef054 commit ba22385

File tree

3 files changed

+9
-32
lines changed

3 files changed

+9
-32
lines changed

cli_test_helpers/commands.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
"""
44

55
from sys import version_info
6+
from types import SimpleNamespace as Namespace
67

7-
try:
8-
from types import SimpleNamespace as Namespace
9-
except ImportError: # Python < 3.3
10-
from argparse import Namespace
11-
12-
if version_info < (3, 5): # Python 2.7
13-
from subprocess import PIPE, CalledProcessError, check_output
14-
elif version_info < (3, 7):
8+
if version_info < (3, 7):
159
from subprocess import PIPE, run
1610
else:
1711
from subprocess import run
@@ -26,15 +20,7 @@ def shell(command, **kwargs):
2620
This is a better version of ``os.system()`` that captures output and
2721
returns a convenient namespace object.
2822
"""
29-
if version_info < (3, 5): # Python 2.7
30-
completed = Namespace(returncode=None, stdout=b"", stderr=b"")
31-
try:
32-
completed.stdout = check_output(command, shell=True, stderr=PIPE, **kwargs)
33-
completed.returncode = 0
34-
except CalledProcessError as ex:
35-
completed.stdout = ex.output
36-
completed.returncode = ex.returncode
37-
elif version_info < (3, 7):
23+
if version_info < (3, 7):
3824
completed = run(
3925
command, shell=True, stdout=PIPE, stderr=PIPE, check=False, **kwargs
4026
)

cli_test_helpers/decorators.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
Useful helpers for writing tests for your CLI tool.
33
"""
44

5+
import contextlib
56
import sys
6-
7-
try:
8-
from unittest.mock import patch
9-
except ImportError: # Python 2.7
10-
from mock import patch
7+
from unittest.mock import patch
118

129
__all__ = []
1310

@@ -45,13 +42,11 @@ def __init__(self, **kwargs):
4542
for key in self.clear_variables:
4643
kwargs.pop(key)
4744

48-
super(EnvironContext, self).__init__("os.environ", **kwargs)
45+
super().__init__("os.environ", **kwargs)
4946

5047
def __enter__(self):
51-
super(EnvironContext, self).__enter__()
48+
super().__enter__()
5249

5350
for key in self.clear_variables:
54-
try:
51+
with contextlib.suppress(KeyError):
5552
self.in_dict.pop(key)
56-
except KeyError:
57-
pass

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ extend-ignore = [
6565
"D205",
6666
"D212",
6767
"Q000",
68-
"PERF203", # Python < 3.4 (`contextlib.suppress`)
69-
"SIM105", # Python 2.7 only
70-
"UP008", # Python 2.7 only (`super()` call)
71-
"UP022", # Python 2.7 only (`stderr=PIPE`)
72-
"UP026", # Python 2.7 only (`mock` module)
68+
"UP022", # Python < 3.7 only (`stderr=PIPE`)
7369
"UP036", # Python < 3.7 only
7470
]
7571

0 commit comments

Comments
 (0)