Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/autofmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
35 changes: 21 additions & 14 deletions test_pip_install.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
"""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,
# at least) because it is in py2.x syntax.
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()
Loading