Skip to content

Commit

Permalink
Try to fix test suite on mac and windows
Browse files Browse the repository at this point in the history
emphasis lies on "Try"
  • Loading branch information
mara004 committed Dec 14, 2023
1 parent bc2c843 commit 9ea3f60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 8 additions & 11 deletions tests/ctypesgentest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,19 @@ def module_from_code(name, python_code):

def generate(header_str, args=[], lang="py"):

tmp_header = tempfile.NamedTemporaryFile()
tmp_header.write(header_str.encode())
tmp_header.seek(0)
tmp_out = tempfile.NamedTemporaryFile()
ctypesgen_main(["-i", tmp_header.name, "-o", tmp_out.name, "--output-language", lang, *args])
tmp_in = TEST_DIR/"tmp_in.h"
tmp_in.write_text(header_str)
tmp_out = TEST_DIR/"tmp_out.h"
ctypesgen_main(["-i", tmp_in, "-o", tmp_out, "--output-language", lang, *args])
content = tmp_out.read_text()

tmp_header_name = tmp_header.name
tmp_header.close()
tmp_out.seek(0)
content = tmp_out.read().decode()
tmp_out.close()
tmp_in.unlink()
tmp_out.unlink()

if lang.startswith("py"):
return module_from_code("tmp_module", content)
elif lang == "json":
return json.loads(content), tmp_header_name
return json.loads(content), str(tmp_in)
else:
assert False

Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,7 @@ class MacromanEncodeTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.mac_roman_file = "temp_mac.h"
cls.mac_roman_file = TEST_DIR/"temp_mac.h"
mac_header_str = b"""
#define kICHelper "\xa9\\pHelper\xa5"
Expand All @@ -2559,8 +2559,8 @@ def setUpClass(cls):
with open(cls.mac_roman_file, "wb") as mac_file:
mac_file.write(mac_header_str)

header_str = """
#include "temp_mac.h"
header_str = f"""
#include "{cls.mac_roman_file}"
#define MYSTRING kICHelper
Expand Down

0 comments on commit 9ea3f60

Please sign in to comment.