diff --git a/tests/ctypesgentest.py b/tests/ctypesgentest.py index e44eee3a..36ad3e26 100644 --- a/tests/ctypesgentest.py +++ b/tests/ctypesgentest.py @@ -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 diff --git a/tests/testsuite.py b/tests/testsuite.py index b1d3309d..a82a7c17 100755 --- a/tests/testsuite.py +++ b/tests/testsuite.py @@ -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" @@ -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