From 868a4eac472695e298c43c8cd380ac97ebfc547a Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 24 Feb 2023 20:24:37 +0100 Subject: [PATCH] tests: Fix test_imports_panda3d for frozen/embedded panda3d package --- tests/test_imports.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/test_imports.py b/tests/test_imports.py index 50138735ae..b7df8d8239 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -9,23 +9,30 @@ import pytest def test_imports_panda3d(): - import importlib, os + import importlib, os, sys import panda3d - dir = os.path.dirname(panda3d.__file__) - # Iterate over the things in the panda3d package that look like modules. - extensions = set(importlib.machinery.all_suffixes()) + # Look for panda3d.* modules in builtins - pfreeze might put them there. + for mod in sys.builtin_module_names: + if mod.startswith('panda3d.'): + importlib.import_module(mod) - for basename in os.listdir(dir): - if basename.startswith('lib'): - # This not a Python module. - continue + if panda3d.__spec__.origin != 'frozen': + dir = os.path.dirname(panda3d.__file__) - module = basename.split('.', 1)[0] - ext = basename[len(module):] + # Iterate over the things in the panda3d package that look like modules. + extensions = set(importlib.machinery.all_suffixes()) - if ext in extensions: - importlib.import_module('panda3d.%s' % (module)) + for basename in os.listdir(dir): + if basename.startswith('lib'): + # This not a Python module. + continue + + module = basename.split('.', 1)[0] + ext = basename[len(module):] + + if ext in extensions: + importlib.import_module('panda3d.%s' % (module)) def test_imports_direct():