mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-27 07:03:36 -04:00
tests: Compat w/ older pytest by using tmpdir instead of tmp_path
This commit is contained in:
parent
a0ea85d39e
commit
479774477b
26
tests/dist/test_FreezeTool.py
vendored
26
tests/dist/test_FreezeTool.py
vendored
@ -14,32 +14,32 @@ def test_Freezer_moduleSuffixes():
|
||||
assert mode == 'rb'
|
||||
|
||||
|
||||
def test_Freezer_getModulePath_getModuleStar(tmp_path):
|
||||
def test_Freezer_getModulePath_getModuleStar(tmpdir):
|
||||
# Package 1 can be imported
|
||||
package1 = tmp_path / "package1"
|
||||
package1 = tmpdir.join("package1")
|
||||
package1.mkdir()
|
||||
(package1 / "submodule1.py").write_text(u"")
|
||||
(package1 / "__init__.py").write_text(u"")
|
||||
package1.join("submodule1.py").write("")
|
||||
package1.join("__init__.py").write("")
|
||||
|
||||
# Package 2 can not be imported
|
||||
package2 = tmp_path / "package2"
|
||||
package2 = tmpdir.join("package2")
|
||||
package2.mkdir()
|
||||
(package2 / "submodule2.py").write_text(u"")
|
||||
(package2 / "__init__.py").write_text(u"raise ImportError\n")
|
||||
package2.join("submodule2.py").write("")
|
||||
package2.join("__init__.py").write("raise ImportError\n")
|
||||
|
||||
# Module 1 can be imported
|
||||
(tmp_path / "module1.py").write_text(u"")
|
||||
tmpdir.join("module1.py").write("")
|
||||
|
||||
# Module 2 can not be imported
|
||||
(tmp_path / "module2.py").write_text(u"raise ImportError\n")
|
||||
tmpdir.join("module2.py").write("raise ImportError\n")
|
||||
|
||||
# Module 3 has a custom __path__ and __all__
|
||||
(tmp_path / "module3.py").write_text(u"__path__ = ['foobar']\n__all__ = ['test']\n")
|
||||
tmpdir.join("module3.py").write("__path__ = ['foobar']\n__all__ = ['test']\n")
|
||||
|
||||
backup = sys.path
|
||||
try:
|
||||
# Don't fail if first item on path does not exist
|
||||
sys.path = [str(tmp_path / "nonexistent"), str(tmp_path)]
|
||||
sys.path = [str(tmpdir.join("nonexistent")), str(tmpdir)]
|
||||
|
||||
freezer = Freezer()
|
||||
assert freezer.getModulePath("nonexist") == None
|
||||
@ -68,7 +68,7 @@ def test_Freezer_getModulePath_getModuleStar(tmp_path):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_console", (False, True))
|
||||
def test_Freezer_generateRuntimeFromStub(tmp_path, use_console):
|
||||
def test_Freezer_generateRuntimeFromStub(tmpdir, use_console):
|
||||
try:
|
||||
# If installed as a wheel
|
||||
import panda3d_tools
|
||||
@ -91,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' + suffix))
|
||||
target = str(tmpdir.join('stubtest' + suffix))
|
||||
|
||||
freezer = Freezer()
|
||||
freezer.addModule('module2', filename='module2.py', text='print("Module imported")')
|
||||
|
@ -71,9 +71,9 @@ def test_load_model_okmissing(loader):
|
||||
assert model is None
|
||||
|
||||
|
||||
def test_loader_entry_points(tmp_path):
|
||||
def test_loader_entry_points(tmpdir):
|
||||
# A dummy loader for .fnrgl files.
|
||||
(tmp_path / "fnargle.py").write_text(u"""
|
||||
tmpdir.join("fnargle.py").write("""
|
||||
from panda3d.core import ModelRoot
|
||||
import sys
|
||||
|
||||
@ -88,19 +88,19 @@ class FnargleLoader:
|
||||
def load_file(path, options, record=None):
|
||||
return ModelRoot("fnargle")
|
||||
""")
|
||||
(tmp_path / "fnargle.dist-info").mkdir()
|
||||
(tmp_path / "fnargle.dist-info" / "METADATA").write_text(u"""
|
||||
tmpdir.join("fnargle.dist-info").mkdir()
|
||||
tmpdir.join("fnargle.dist-info", "METADATA").write("""
|
||||
Metadata-Version: 2.0
|
||||
Name: fnargle
|
||||
Version: 1.0.0
|
||||
""")
|
||||
(tmp_path / "fnargle.dist-info" / "entry_points.txt").write_text(u"""
|
||||
tmpdir.join("fnargle.dist-info", "entry_points.txt").write("""
|
||||
[panda3d.loaders]
|
||||
fnrgl = fnargle:FnargleLoader
|
||||
""")
|
||||
|
||||
model_path = tmp_path / "test.fnrgl"
|
||||
model_path.write_text(u"")
|
||||
model_path = tmpdir.join("test.fnrgl")
|
||||
model_path.write("")
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
import sysconfig
|
||||
@ -126,7 +126,7 @@ fnrgl = fnargle:FnargleLoader
|
||||
file_type = None
|
||||
try:
|
||||
# We do this so we don't re-register thirdparty loaders
|
||||
sys.path = [str(tmp_path), platstdlib, stdlib]
|
||||
sys.path = [str(tmpdir), platstdlib, stdlib]
|
||||
if sys.version_info < (3, 8):
|
||||
pkg_resources._initialize_master_working_set()
|
||||
|
||||
@ -151,7 +151,7 @@ fnrgl = fnargle:FnargleLoader
|
||||
assert 'fnargle' in sys.modules
|
||||
|
||||
# Now try loading a fnargle file
|
||||
model_fn = Filename(model_path)
|
||||
model_fn = Filename.from_os_specific(str(model_path))
|
||||
model_fn.make_true_case()
|
||||
model = loader.load_model(model_fn, noCache=True)
|
||||
assert model is not None
|
||||
|
Loading…
x
Reference in New Issue
Block a user