Skip to content

Commit

Permalink
tests: Fix running tests on Windows and with Python 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
rdb committed Oct 14, 2023
1 parent 972c000 commit b2465c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 4 additions & 0 deletions direct/src/dist/FreezeTool.py
Expand Up @@ -1420,6 +1420,10 @@ def __loadModule(self, mdef):
fp = open(pathname, 'rb')
stuff = ("", "rb", _PY_COMPILED)
self.mf.load_module(mdef.moduleName, fp, pathname, stuff)
elif isinstance(mdef.text, bytes):
stuff = ("", "rb", _PY_SOURCE)
fp = io.BytesIO(mdef.text)
self.mf.load_module(mdef.moduleName, fp, pathname, stuff)
else:
stuff = ("", "rb", _PY_SOURCE)
if mdef.text:
Expand Down
19 changes: 10 additions & 9 deletions tests/dist/test_FreezeTool.py
Expand Up @@ -2,6 +2,8 @@
import pytest
import os
import sys
import subprocess
import platform


def test_Freezer_moduleSuffixes():
Expand All @@ -16,24 +18,23 @@ def test_Freezer_getModulePath_getModuleStar(tmp_path):
# Package 1 can be imported
package1 = tmp_path / "package1"
package1.mkdir()
(package1 / "submodule1.py").write_text("")
(package1 / "__init__.py").write_text("")
(package1 / "submodule1.py").write_text(u"")
(package1 / "__init__.py").write_text(u"")

# Package 2 can not be imported
package2 = tmp_path / "package2"
package2.mkdir()
(package2 / "submodule2.py").write_text("")
(package2 / "__init__.py").write_text("raise ImportError\n")
(package2 / "submodule2.py").write_text(u"")
(package2 / "__init__.py").write_text(u"raise ImportError\n")

# Module 1 can be imported
(tmp_path / "module1.py").write_text("")
(tmp_path / "module1.py").write_text(u"")

# Module 2 can not be imported
(tmp_path / "module2.py").write_text("raise ImportError\n")
(tmp_path / "module2.py").write_text(u"raise ImportError\n")

# Module 3 has a custom __path__ and __all__
(tmp_path / "module3.py").write_text("__path__ = ['foobar']\n"
"__all__ = ['test']\n")
(tmp_path / "module3.py").write_text(u"__path__ = ['foobar']\n__all__ = ['test']\n")

backup = sys.path
try:
Expand Down Expand Up @@ -90,7 +91,7 @@ def test_Freezer_generateRuntimeFromStub(tmp_path, use_console):
if not os.path.isfile(stub_file):
pytest.skip("Unable to find deploy-stub executable")

target = str(tmp_path / 'stubtest')
target = str(tmp_path / ('stubtest' + suffix))

freezer = Freezer()
freezer.addModule('__main__', 'main.py', text='print("Hello world")')
Expand Down
12 changes: 7 additions & 5 deletions tests/showbase/test_Loader.py
Expand Up @@ -73,7 +73,7 @@ def test_load_model_okmissing(loader):

def test_loader_entry_points(tmp_path):
# A dummy loader for .fnrgl files.
(tmp_path / "fnargle.py").write_text("""
(tmp_path / "fnargle.py").write_text(u"""
from panda3d.core import ModelRoot
import sys
Expand All @@ -89,18 +89,18 @@ def load_file(path, options, record=None):
return ModelRoot("fnargle")
""")
(tmp_path / "fnargle.dist-info").mkdir()
(tmp_path / "fnargle.dist-info" / "METADATA").write_text("""
(tmp_path / "fnargle.dist-info" / "METADATA").write_text(u"""
Metadata-Version: 2.0
Name: fnargle
Version: 1.0.0
""")
(tmp_path / "fnargle.dist-info" / "entry_points.txt").write_text("""
(tmp_path / "fnargle.dist-info" / "entry_points.txt").write_text(u"""
[panda3d.loaders]
fnrgl = fnargle:FnargleLoader
""")

model_path = tmp_path / "test.fnrgl"
model_path.write_text("")
model_path.write_text(u"")

if sys.version_info >= (3, 11):
import sysconfig
Expand Down Expand Up @@ -151,7 +151,9 @@ def load_file(path, options, record=None):
assert 'fnargle' in sys.modules

# Now try loading a fnargle file
model = loader.load_model(model_path)
model_fn = Filename(model_path)
model_fn.make_true_case()
model = loader.load_model(model_fn)
assert model is not None
assert model.name == "fnargle"

Expand Down

0 comments on commit b2465c3

Please sign in to comment.