From 3f3819e7faf9f9d26095506a3ffb748f0bba80cf Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 3 Aug 2023 13:19:53 +0200 Subject: [PATCH] tests: Further expand on tools tests --- tests/test_tools.py | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 81a65e008e..b6b187ebc2 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -2,15 +2,24 @@ import pytest import subprocess import sys 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): if sys.platform == 'win32': 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) if not os.path.isfile(path): 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") -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() - 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')