diff --git a/tests/__init__.py b/tests/__init__.py index f97540a8..88371db7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,13 +15,13 @@ # along with this program. If not, see . """ A lot of these tests need an external compression program. -See https://github.com/wummel/patool/blob/debian/debian/control +See https://salsa.debian.org/debian/patool/-/blob/master/debian/control at the "Suggests:" for a list of packages with supported compression programs. The file type detection uses the file(1) program which uses a library of "magic" patterns. The contents of the magic pattern library can vary -between distributions so the tests might not run on all Linux systems. +between distributions so the tests might not run on all systems. """ import os import patoolib @@ -39,7 +39,7 @@ def _need_func(testfunc, name, description): def check_func(func): def newfunc(*args, **kwargs): if not testfunc(name): - pytest.skip("%s %r is not available" % (description, name)) + pytest.skip(f"{description} {name!r} is not available") return func(*args, **kwargs) setattr(newfunc, fnameattr, getattr(func, fnameattr)) return newfunc @@ -72,14 +72,14 @@ def has_module(module): return _need_func(has_module, name, 'Python module') -def needs_codec (program, codec): +def needs_codec(program, codec): """Decorator skipping test if given program codec is not available.""" - def check_prog (f): - def newfunc (*args, **kwargs): + def check_prog(f): + def newfunc(*args, **kwargs): if not patoolib.util.find_program(program): - pytest.skip("program `%s' not available" % program) + pytest.skip(f"program `{program}' not available") if not has_codec(program, codec): - pytest.skip("codec `%s' for program `%s' not available" % (codec, program)) + pytest.skip(f"codec `{codec}' for program `{program}' not available") return f(*args, **kwargs) setattr(newfunc, fnameattr, getattr(f, fnameattr)) return newfunc diff --git a/tests/archives/__init__.py b/tests/archives/__init__.py index 4017dd82..684156fb 100644 --- a/tests/archives/__init__.py +++ b/tests/archives/__init__.py @@ -63,10 +63,10 @@ def archive_commands (self, filename, **kwargs): if not kwargs.get('skip_create'): self.archive_create(filename, **kwargs) - def archive_extract (self, filename, check=Content.Recursive): + def archive_extract(self, filename, check=Content.Recursive): """Test archive extraction.""" archive = os.path.join(datadir, filename) - self.assertTrue(os.path.isabs(archive), "archive path is not absolute: %r" % archive) + self.assertTrue(os.path.isabs(archive), f"archive path is not absolute: {archive!r}") self._archive_extract(archive, check) # archive name relative to tmpdir relarchive = os.path.join("..", archive[len(basedir)+1:]) @@ -128,7 +128,7 @@ def archive_test (self, filename): for verbosity in (-1, 0, 1, 2): patoolib.test_archive(archive, program=self.program, verbosity=verbosity, interactive=False, password=self.password) - def archive_create (self, archive, srcfiles=None, check=Content.Recursive): + def archive_create(self, archive, srcfiles=None, check=Content.Recursive): """Test archive creation.""" if srcfiles is None: if check == Content.Recursive: @@ -138,7 +138,7 @@ def archive_create (self, archive, srcfiles=None, check=Content.Recursive): elif check == Content.Multifile: srcfiles = ('t.txt', 't2.txt',) else: - raise ValueError('invalid check value %r' % check) + raise ValueError('invalid check value {check!r}') olddir = patoolib.fileutil.chdir(datadir) try: # The format and compression arguments are needed for creating @@ -158,7 +158,7 @@ def _archive_create (self, archive, srcfiles, program=None, verbosity=0): tmpdir = patoolib.fileutil.tmpdir(dir=basedir) try: archive = os.path.join(tmpdir, archive) - self.assertTrue(os.path.isabs(archive), "archive path is not absolute: %r" % archive) + self.assertTrue(os.path.isabs(archive), f"archive path is not absolute: {archive!r}") patoolib.create_archive(archive, srcfiles, verbosity=verbosity, interactive=False, program=program, password=self.password) self.assertTrue(os.path.isfile(archive)) self.check_created_archive_with_test(archive) @@ -235,10 +235,4 @@ def get_filecontent(filename): def get_nonexisting_directory(basedir): """Note: this is _not_ intended to be used to create a directory.""" - d = os.path.join(basedir, "foo") - while os.path.exists(d): - d += 'a' - if len(d) > 100: - # wtf - raise ValueError('could not construct unique directory name at %r' % basedir) - return d + return patoolib.fileutil.get_single_outfile(basedir, "foo") diff --git a/tests/archives/test_rpm.py b/tests/archives/test_rpm.py index 0ba3f703..3fcf89d0 100644 --- a/tests/archives/test_rpm.py +++ b/tests/archives/test_rpm.py @@ -20,7 +20,7 @@ class TestRpm (ArchiveTest): program = 'rpm' - @needs_program('rpm') + @needs_program(program) def test_rpm(self): self.archive_list('t.rpm') # The rpm test fails on non-rpm system with missing dependencies. diff --git a/tests/test_mime.py b/tests/test_mime.py index 1d8803b5..22f7df8b 100644 --- a/tests/test_mime.py +++ b/tests/test_mime.py @@ -27,7 +27,7 @@ def mime_test(self, func, filename, mime, encoding, info): file_mime, file_encoding = func(filename) fail_msg = "%s for archive `%s' should be %s, but was %s. Info: %s" if isinstance(mime, tuple): - self.assertTrue(file_mime in mime, fail_msg % ("MIME type", filename, "in %s" % str(mime), file_mime, info)) + self.assertTrue(file_mime in mime, fail_msg % ("MIME type", filename, f"in {mime}", file_mime, info)) else: self.assertEqual(file_mime, mime, fail_msg % ("MIME type", filename, mime, file_mime, info)) self.assertEqual(file_encoding, encoding, fail_msg % ("Encoding", filename, encoding, file_encoding, info))