Browse Source

tests: Further expand on tools tests

rdb 2 years ago
parent
commit
3f3819e7fa
1 changed files with 39 additions and 6 deletions
  1. 39 6
      tests/test_tools.py

+ 39 - 6
tests/test_tools.py

@@ -2,15 +2,24 @@ import pytest
 import subprocess
 import subprocess
 import sys
 import sys
 import os
 import os
+import tempfile
+import panda3d
+
+try:
+    panda3d_tools = pytest.importorskip("panda3d_tools")
+except:
+    panda3d_tools = None
 
 
-# Currently only works when Panda was installed from wheel
-panda3d_tools = pytest.importorskip("panda3d_tools")
 
 
 def get_tool(name):
 def get_tool(name):
     if sys.platform == 'win32':
     if sys.platform == 'win32':
         name += '.exe'
         name += '.exe'
 
 
-    tools_dir = os.path.dirname(panda3d_tools.__file__)
+    if panda3d_tools:
+        tools_dir = os.path.dirname(panda3d_tools.__file__)
+    else:
+        tools_dir = os.path.join(os.path.dirname(os.path.dirname(panda3d.__file__)), 'bin')
+
     path = os.path.join(tools_dir, name)
     path = os.path.join(tools_dir, name)
     if not os.path.isfile(path):
     if not os.path.isfile(path):
         pytest.skip(name + ' not found')
         pytest.skip(name + ' not found')
@@ -24,7 +33,31 @@ def test_bam_info():
     assert output.startswith(b"This program scans one or more Bam files")
     assert output.startswith(b"This program scans one or more Bam files")
 
 
 
 
-def test_pzip():
-    path = get_tool('pzip')
+def test_egg_trans():
+    path = get_tool('egg-trans')
     output = subprocess.check_output([path, '-h'], stderr=subprocess.STDOUT).strip()
     output = subprocess.check_output([path, '-h'], stderr=subprocess.STDOUT).strip()
-    assert output.startswith(b"This program compresses the named file")
+    assert output.startswith(b"egg-trans reads an egg file and writes")
+
+
+def test_pzip():
+    data = b'test \000 data'
+
+    try:
+        file = tempfile.NamedTemporaryFile(suffix='.bin', delete=False)
+        file.write(data)
+        file.close()
+
+        path = get_tool('pzip')
+        subprocess.check_output([path, file.name])
+
+        zlib = pytest.importorskip('zlib')
+
+        with open(file.name + '.pz', 'rb') as pz:
+            assert zlib.decompress(pz.read(), 32 + 15, 4096) == data
+
+    finally:
+        if os.path.isfile(file.name):
+            os.remove(file.name)
+
+        if os.path.isfile(file.name + '.pz'):
+            os.remove(file.name + '.pz')