diff --git a/.github/workflows/autofmt.yml b/.github/workflows/autofmt.yml index d6d70f25..02f35052 100644 --- a/.github/workflows/autofmt.yml +++ b/.github/workflows/autofmt.yml @@ -16,6 +16,6 @@ jobs: - name: Install ruff run: pip install ruff==0.6.9 - name: Check format - run: python -m ruff format comtypes/. --check --diff + run: python -m ruff format test_pip_install.py comtypes/. --check --diff - name: Check lint - run: python -m ruff check --output-format=github comtypes/. + run: python -m ruff check --output-format=github test_pip_install.py comtypes/. diff --git a/test_pip_install.py b/test_pip_install.py index 1084c69d..ebd8ed4d 100644 --- a/test_pip_install.py +++ b/test_pip_install.py @@ -1,11 +1,13 @@ """This test covers 'pip install' issue #155""" + import os -import sys import shutil import subprocess +import sys import tarfile import unittest + def read_version(): # Determine the version number by reading it from the file # 'comtypes\__init__.py'. We cannot import this file (with py3, @@ -13,42 +15,47 @@ def read_version(): with open("comtypes/__init__.py") as ofi: for line in ofi: if line.startswith("__version__ = "): - var, value = line.split('=') + var, value = line.split("=") return value.strip().strip('"').strip("'") raise NotImplementedError("__version__ is not found in __init__.py") class TestPipInstall(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.version = read_version() def setUp(self): """prepare the same package that is usually uploaded to PyPI""" - subprocess.check_call([sys.executable, '-m', 'build', '--sdist']) + subprocess.check_call([sys.executable, "-m", "build", "--sdist"]) - filename_for_upload = 'comtypes-%s.tar.gz' % read_version() - self.target_package = os.path.join(os.getcwd(), 'dist', filename_for_upload) - self.pip_exe = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'pip.exe') + filename_for_upload = f"comtypes-{self.version}.tar.gz" + self.target_package = os.path.join(os.getcwd(), "dist", filename_for_upload) + self.pip_exe = os.path.join( + os.path.dirname(sys.executable), "Scripts", "pip.exe" + ) def test_pip_install(self): """Test that "pip install comtypes-x.y.z.tar.gz" works""" - subprocess.check_call([self.pip_exe, 'install', self.target_package]) + subprocess.check_call([self.pip_exe, "install", self.target_package]) def test_py_typed_is_packaged(self): with tarfile.open(self.target_package, "r:gz") as tar: - self.assertIn( - f"comtypes-{read_version()}/comtypes/py.typed", tar.getnames() - ) + self.assertIn(f"comtypes-{self.version}/comtypes/py.typed", tar.getnames()) def test_no_cache_dir_custom_location(self): """Test that 'pip install comtypes-x.y.z.tar.gz --no-cache-dir --target="...\custom location"' works""" - custom_dir = os.path.join(os.getcwd(), 'custom location') + custom_dir = os.path.join(os.getcwd(), "custom location") if os.path.exists(custom_dir): shutil.rmtree(custom_dir) os.makedirs(custom_dir) # this test catches issue #158 - subprocess.check_call('{0} install {1} --no-cache-dir --target="{2}"' \ - ''.format(self.pip_exe, self.target_package, custom_dir)) + subprocess.check_call( + f"{self.pip_exe} install {self.target_package} " + f'--no-cache-dir --target="{custom_dir}"' + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main()