"""Tests for binary format detection edge cases. These tests focus on edge cases and error handling in format detection, using synthetic/minimal binary data rather than full test assets. """ import struct from pathlib import Path import pytest from rocm_kpack.format_detect import ( detect_binary_format, is_elf_binary, is_pe_binary, UnsupportedBinaryFormat, ELF_MAGIC, DOS_MAGIC, PE_SIGNATURE, ) class TestDetectBinaryFormat: """Tests for detect_binary_format function.""" def test_detect_elf_format(self, tmp_path: Path): """Test that ELF format is correctly detected.""" elf_file = tmp_path / "test.so" # Minimal ELF header (just magic + padding) elf_data = ELF_MAGIC + b"\x02\x01\x01" + (b"\x00" * 57) # 64 bytes elf_file.write_bytes(elf_data) assert detect_binary_format(elf_file) == "elf" def test_detect_coff_format(self, tmp_path: Path): """Test that PE/COFF format is correctly detected.""" pe_file = tmp_path / "test.dll" # Minimal PE: DOS header + PE signature data = bytearray(256) # DOS magic data[0:2] = DOS_MAGIC # PE offset at 0x3c points to 0x80 struct.pack_into("