Skip to content

Commit 89d275c

Browse files
committed
cleanup test
1 parent dc311c7 commit 89d275c

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

tests/cc/current_py_cc_headers/abi3_headers_linkage_test.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,26 @@
88
from python.runfiles import runfiles
99

1010
class CheckLinkageTest(unittest.TestCase):
11-
def test_linkage(self):
11+
@unittest.skipUnless(sys.platform.startswith("win"))
12+
def test_linkage_windows(self):
1213
rf = runfiles.Create()
13-
d = rf.Rlocation("_main/tests/cc/current_py_cc_headers")
14-
d = pathlib.Path(d)
15-
for file_path in d.glob("*.dll"):
16-
print(f"[*] Analyzing dependencies for: {file_path}\n")
14+
dll_path = rf.Rlocation("_main/tests/cc/current_py_cc_headers/bin_abi3.dll")
15+
if not os.path.exists(dll_path):
16+
self.fail(f"dll at {dll_path} does not exist")
17+
18+
pe = pefile.PE(dll_path)
19+
if not hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):
20+
self.fail("No import directory found.")
21+
22+
imported_dlls = [
23+
entry.dll.decode('utf-8').lower()
24+
for entry in pe.DIRECTORY_ENTRY_IMPORT
25+
]
26+
python_dlls = [
27+
dll for dll in imported_dlls if dll.startswith("python3")
28+
]
29+
self.assertEqual(python_dlls, ["python3.dll"])
1730

18-
try:
19-
# Parse the PE file
20-
pe = pefile.PE(file_path)
21-
22-
if not hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):
23-
print("[!] No import directory found. The file may not have dependencies or is packed.")
24-
raise Exception("no deps?")
25-
26-
print("Imported DLLs:")
27-
28-
# Iterate over the import directory entries
29-
# Each 'entry' corresponds to one imported DLL
30-
for entry in pe.DIRECTORY_ENTRY_IMPORT:
31-
# entry.dll is a bytes string, so we decode it to utf-8
32-
dll_name = entry.dll.decode('utf-8')
33-
print(f" - {dll_name}")
34-
35-
except pefile.PEFormatError as e:
36-
print(f"Error: Not a valid PE file (DLL/EXE). \nDetails: {e}")
37-
except Exception as e:
38-
print(f"An unexpected error occurred: {e}")
39-
40-
raise Exception("done")
4131

4232
if __name__ == "__main__":
4333
unittest.main()

0 commit comments

Comments
 (0)