Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Dec 23, 2024
1 parent c4835d6 commit 80ccebe
Show file tree
Hide file tree
Showing 8 changed files with 1,537 additions and 1,095 deletions.
1,208 changes: 687 additions & 521 deletions backports/tarfile/__init__.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backports/tarfile/compat/py38.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def removeprefix(self, prefix):
return self[len(prefix) :]
else:
return self[:]

else:

def removesuffix(self, suffix):
Expand Down
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def backport_as_std():
Make sure 'import tarfile' gets the backport.
"""
from backports import tarfile

sys.modules['tarfile'] = tarfile


Expand Down
13 changes: 7 additions & 6 deletions tests/compat/archiver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from .py39 import os_helper

class OverwriteTests:

class OverwriteTests:
def setUp(self):
os.makedirs(self.testdir)
self.addCleanup(os_helper.rmtree, self.testdir)
Expand All @@ -21,7 +21,6 @@ def open(self, path):
def extractall(self, ar):
raise NotImplementedError


def test_overwrite_file_as_file(self):
target = os.path.join(self.testdir, 'test')
self.create_file(target, b'content')
Expand Down Expand Up @@ -52,8 +51,9 @@ def test_overwrite_dir_as_file(self):
target = os.path.join(self.testdir, 'test')
os.mkdir(target)
with self.open(self.ar_with_file) as ar:
with self.assertRaises(PermissionError if sys.platform == 'win32'
else IsADirectoryError):
with self.assertRaises(
PermissionError if sys.platform == 'win32' else IsADirectoryError
):
self.extractall(ar)
self.assertTrue(os.path.isdir(target))

Expand All @@ -71,8 +71,9 @@ def test_overwrite_file_as_implicit_dir(self):
target = os.path.join(self.testdir, 'test')
self.create_file(target, b'content')
with self.open(self.ar_with_implicit_dir) as ar:
with self.assertRaises(FileNotFoundError if sys.platform == 'win32'
else NotADirectoryError):
with self.assertRaises(
FileNotFoundError if sys.platform == 'win32' else NotADirectoryError
):
self.extractall(ar)
self.assertTrue(os.path.isfile(target))
with open(target, 'rb') as f:
Expand Down
3 changes: 2 additions & 1 deletion tests/compat/py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import warnings as std_warnings



try:
from test import archiver_tests
except ImportError:
Expand Down Expand Up @@ -38,11 +37,13 @@ def is_wasi():

class warnings_compat:
if sys.version_info < (3, 11):

@contextlib.contextmanager
def catch_warnings(*, record=False, module=None, action=None, **kwargs):
with std_warnings.catch_warnings(record=record, module=module) as val:
if action:
std_warnings.simplefilter(action, **kwargs)
yield val


warnings = types.SimpleNamespace(**{**vars(std_warnings), **vars(warnings_compat)})
3 changes: 3 additions & 0 deletions tests/compat/py38.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class support_compat:
if sys.version_info < (3, 9):

def requires_zlib(reason='requires zlib'):
try:
import zlib
Expand Down Expand Up @@ -68,6 +69,7 @@ def removeprefix(self, prefix):
return self[len(prefix) :]
else:
return self[:]

else:

def removesuffix(self, suffix):
Expand All @@ -91,5 +93,6 @@ def temp_tarfile_open(DIR, tarname):
"""
from .py310 import os_helper
import tarfile

with os_helper.temp_dir(DIR), tarfile.open(tarname, encoding="iso8859-1") as tar:
yield tar
13 changes: 8 additions & 5 deletions tests/compat/py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@


class FakePath:
"""Simple implementation of the path protocol.
"""
"""Simple implementation of the path protocol."""

def __init__(self, path):
self.path = path

def __repr__(self):
return f'<FakePath {self.path!r}>'

def __fspath__(self):
if (isinstance(self.path, BaseException) or
isinstance(self.path, type) and
issubclass(self.path, BaseException)):
if (
isinstance(self.path, BaseException)
or isinstance(self.path, type)
and issubclass(self.path, BaseException)
):
raise self.path
else:
return self.path
Expand All @@ -44,6 +46,7 @@ def __fspath__(self):

class support_compat:
if sys.version_info < (3, 10):

def check__all__(test_case, mod, *, not_exported=(), **kwargs):
kwargs.update(blacklist=not_exported)
return std_support.check__all__(test_case, mod, **kwargs)
Expand Down
Loading

0 comments on commit 80ccebe

Please sign in to comment.