Skip to content

Commit

Permalink
tests: generate the fake dll on the fly to avoid issues with conda pa…
Browse files Browse the repository at this point in the history
…ckaging
  • Loading branch information
MatthieuDartiailh committed Nov 6, 2020
1 parent af1f695 commit ccd202a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 36 deletions.
Binary file removed pyvisa/testsuite/fakelibs/fakelib_bad_magic.dll
Binary file not shown.
Binary file removed pyvisa/testsuite/fakelibs/fakelib_good_32.dll
Binary file not shown.
Binary file removed pyvisa/testsuite/fakelibs/fakelib_good_64.dll
Binary file not shown.
Binary file removed pyvisa/testsuite/fakelibs/fakelib_good_64_2.dll
Binary file not shown.
Binary file removed pyvisa/testsuite/fakelibs/fakelib_good_unknown.dll
Binary file not shown.
Binary file removed pyvisa/testsuite/fakelibs/fakelib_not_pe.dll
Binary file not shown.
31 changes: 0 additions & 31 deletions pyvisa/testsuite/fakelibs/generate_fakelibs.py

This file was deleted.

39 changes: 34 additions & 5 deletions pyvisa/testsuite/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import contextlib
import logging
import os
import struct
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -495,15 +496,42 @@ def get_debug_info(cls):
util.system_details_to_str(details)


def generate_fakelibs(dirname):

for name, blob in zip(
[
"fakelib_bad_magic.dll",
"fakelib_good_32.dll",
"fakelib_good_64_2.dll",
"fakelib_good_64.dll",
"fakelib_good_unknown.dll",
"fakelib_not_pe.dll",
],
[
struct.pack("=6sH52sl", b"MAPE\x00\x00", 0x014C, 52 * b"\0", 2),
struct.pack("=6sH52sl", b"MZPE\x00\x00", 0x014C, 52 * b"\0", 2),
struct.pack("=6sH52sl", b"MZPE\x00\x00", 0x8664, 52 * b"\0", 2),
struct.pack("=6sH52sl", b"MZPE\x00\x00", 0x0200, 52 * b"\0", 2),
struct.pack("=6sH52sl", b"MZPE\x00\x00", 0xFFFF, 52 * b"\0", 2),
struct.pack("=6sH52sl", b"MZDE\x00\x00", 0x014C, 52 * b"\0", 2),
],
):
with open(os.path.join(dirname, name), "wb") as f:
f.write(blob)
print("Written %s" % name)


class TestLibraryAnalysis(BaseTestCase):
"""Test (through monkey patching) the analysis of binary libraries."""

def test_get_shared_library_arch(self):
def test_get_shared_library_arch(self, tmpdir):
"""Test analysing a library on Windows."""
dirname = os.path.join(os.path.dirname(__file__), "fakelibs")
dirname = str(tmpdir)
generate_fakelibs(dirname)

for f, a in zip(["_32", "_64", "_64_2"], ["I386", "IA64", "AMD64"]):
arch = util.get_shared_library_arch(
os.path.join(dirname, "fakelib_good%s.dll" % f)
os.path.join(tmpdir, "fakelib_good%s.dll" % f)
)
assert arch == a

Expand All @@ -520,9 +548,10 @@ def test_get_shared_library_arch(self):
util.get_shared_library_arch(os.path.join(dirname, "fakelib_not_pe.dll"))
assert "Not a PE executable" in e.exconly()

def test_get_arch_windows(self):
def test_get_arch_windows(self, tmpdir):
"""Test identifying the computer architecture on windows."""
dirname = os.path.join(os.path.dirname(__file__), "fakelibs")
dirname = str(tmpdir)
generate_fakelibs(dirname)

platform = sys.platform
sys.platform = "win32"
Expand Down

0 comments on commit ccd202a

Please sign in to comment.