1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
import importlib.util
import os
import subprocess
import warnings
from pathlib import Path
import pytest
import psygnal
def test_hook_content():
spec = importlib.util.spec_from_file_location(
"hook",
os.path.join(
os.path.dirname(psygnal.__file__), "_pyinstaller_util", "hook-psygnal.py"
),
)
hook = importlib.util.module_from_spec(spec)
spec.loader.exec_module(hook)
assert "mypy_extensions" in hook.hiddenimports
if not psygnal._compiled:
return
assert "psygnal._dataclass_utils" in hook.hiddenimports
@pytest.mark.skipif(not os.getenv("CI"), reason="slow test")
def test_pyintstaller_hiddenimports(tmp_path: Path) -> None:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
pyi_main = pytest.importorskip("PyInstaller.__main__")
build_path = tmp_path / "build"
dist_path = tmp_path / "dist"
app_name = "psygnal_test"
app = tmp_path / f"{app_name}.py"
app.write_text("\n".join(["import psygnal", "print(psygnal.__version__)"]))
args = [
# Place all generated files in ``tmp_path``.
"--workpath",
str(build_path),
"--distpath",
str(dist_path),
"--specpath",
str(tmp_path),
str(app),
]
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# silence warnings about deprecations
pyi_main.run(args)
subprocess.run([str(dist_path / app_name / app_name)], check=True)
|