Skip to content

Commit

Permalink
tests: fix test_regression::test_issue_5131
Browse files Browse the repository at this point in the history
The test uses dummy binary/extension file, and therefore requires
special handling of `osxutils.get_macos_sdk_versiom`, similar
to what it already has for `bindepend.get_imports`.
  • Loading branch information
rokm committed Oct 26, 2023
1 parent f25c168 commit d3c0c08
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/functional/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pathlib import Path
from importlib.machinery import EXTENSION_SUFFIXES

from PyInstaller import compat
from PyInstaller.depend import analysis, bindepend
from PyInstaller.building.build_main import Analysis
from PyInstaller.building.api import PYZ
Expand Down Expand Up @@ -61,6 +62,23 @@ def get_imports(*args, **kwargs):
except Exception:
return []

orig_get_imports = bindepend.get_imports
monkeypatch.setattr(bindepend, "get_imports", get_imports)

# On macOS, we need to similarly override `osxutils.get_macos_sdk_version`.
if compat.is_darwin:
from PyInstaller.utils import osx as osxutils

def get_macos_sdk_version(*args, **kwargs):
try:
return orig_get_macos_sdk_version(*args, **kwargs)
except Exception:
return (10, 9, 0) # Minimum version expected by check in Analysis.

orig_get_macos_sdk_version = osxutils.get_macos_sdk_version
monkeypatch.setattr(osxutils, "get_macos_sdk_version", get_macos_sdk_version)

# Set up fake CONF for Analysis
monkeypatch.setattr(
'PyInstaller.config.CONF', {
'workpath': str(tmpdir),
Expand All @@ -73,12 +91,10 @@ def get_imports(*args, **kwargs):
'code_cache': dict(),
}
)

# Speedup: avoid analyzing base_library.zip
monkeypatch.setattr(analysis, 'PY3_BASE_MODULES', [])

orig_get_imports = bindepend.get_imports
monkeypatch.setattr(bindepend, "get_imports", get_imports)

pkg = (tmpdir / 'mypkg').mkdir()
init = pkg / ('__init__' + EXTENSION_SUFFIXES[0])
init.write_binary(b'\0\0\0\0\0\0\0\0\0\0\0\0' * 20)
Expand Down

0 comments on commit d3c0c08

Please sign in to comment.