Summary
tests/test_magic.py::test_file_corpus excludes 14 stems from the upstream libmagic corpus behind a single blanket comment:
if testfile.stem not in (
"JW07022A.mp3", "gedcom", "cmd1", "cmd2", "cmd3", "cmd4", "jpeg-text", "jsonlines1",
"multiple", "osm", "pnm1", "pnm2", "pnm3", "utf16xmlsvg"
):
# The files we skip fail because there is a bug in our implementation that we have not yet fixed
The comment records that bugs exist but not which ones, so the list is not actionable and there is no way to tell when one of them is fixed. Running each skipped stem shows the 14 failures are a handful of distinct causes rather than 14 separate problems.
Inventory
Measured on master (commit eed1f27) with the libmagic 5.48 corpus, using the same normalization the test applies:
| stem |
expected |
PolyFile reports |
pnm1 |
Netpbm image data, size = 2 x 2, greymap, ASCII text |
, greymap |
pnm2 |
Netpbm image data, size = 2 x 2, rawbits, greymap |
, rawbits, greymap |
pnm3 |
Netpbm image data, size = 10 x 20, pixmap, ASCII text |
, pixmap |
gedcom |
GEDCOM genealogy text version 5.5, ASCII text |
GEDCOM genealogy text version 5.5 plus unmerged continuation lines |
osm |
OpenStreetMap XML data, ASCII text |
OpenStreetMap XML data |
cmd1 |
a /usr/bin/cmd1 script, ASCII text executable |
a /usr/bin/cmd1 script executable (binary data) |
cmd2 |
a /usr/bin/cmd2 script, ASCII text executable |
ascii text |
cmd3 |
a /usr/bin/cmd3 script executable (binary data) |
data |
cmd4 |
a /usr/bin/cmd4 script executable (binary data) |
data |
jpeg-text |
ASCII text, with no line terminators |
ascii text |
jsonlines1 |
New Line Delimited JSON text data |
ascii text |
multiple |
Viva File 2.0, then - RTF1.0, - Test File 1.0, - ABCD File, ASCII text, with no line terminators |
ascii text |
JW07022A.mp3 |
Audio file with ID3 version 2.2.0, contains: MPEG ADTS, layer III, ... |
Audio file with ID3 version 2.2.0, contains: data |
utf16xmlsvg |
SVG Scalable Vector Graphics image, Unicode text, UTF-16, ... |
, EFI variable 3997439, total size: 6881395 bytes |
These group into roughly four causes:
- The text-encoding suffix is never appended. libmagic classifies the encoding of a matched buffer and appends it, so
OpenStreetMap XML data becomes OpenStreetMap XML data, ASCII text. PolyFile stops at the type description. Accounts for osm, gedcom, pnm1, pnm3, cmd1, cmd2, and utf16xmlsvg.
- A parent test's description is dropped when a child continues it. The three
pnm results lose Netpbm image data, size = 2 x 2 and keep only the child's , greymap, leaving output that begins with a comma. This looks like the same area as cause 1 but is a separate defect: the text is missing from the middle of the description rather than the end.
- Custom
.magic sidecars are mishandled. cmd1 through cmd4 each ship a .magic script that the test parses in place of the default matcher. cmd3 and cmd4 produce only data, meaning nothing in the sidecar matched.
- Multiple matches are not combined.
multiple expects libmagic's \n- -joined list of every match. PolyFile reports them as separate matches, which the test's assertIn cannot express.
JW07022A.mp3 and jsonlines1 do not obviously fall into any of the four and probably want individual investigation.
A related detail
PolyFile reports the plain-text classification in lower case, ascii text, where libmagic reports ASCII text:
import polyfile.magic
polyfile.magic.local_date = polyfile.magic.utc_date
from polyfile.magic import MagicMatcher, MAGIC_DEFS
matcher = MagicMatcher.parse(*MAGIC_DEFS)
with open("file/tests/jpeg-text.testfile", "rb") as f:
print({str(m) for m in matcher.match(f.read())})
test_file_corpus hides this by lower-casing both sides, and carries a dedicated escape hatch for the exact string ASCII text. Since PolyFile's default output mode mimics file, the casing is user-visible even though no test sees it.
Suggested outcome
Replace the blanket comment with per-stem entries naming the cause and linking the issue that tracks it, then split causes 1 through 4 into their own issues. Cause 1 alone would unskip seven of the fourteen.
Environment
- PolyFile at commit eed1f27
- libmagic 5.48 corpus
- Python 3.14
Summary
tests/test_magic.py::test_file_corpusexcludes 14 stems from the upstream libmagic corpus behind a single blanket comment:The comment records that bugs exist but not which ones, so the list is not actionable and there is no way to tell when one of them is fixed. Running each skipped stem shows the 14 failures are a handful of distinct causes rather than 14 separate problems.
Inventory
Measured on
master(commit eed1f27) with the libmagic 5.48 corpus, using the same normalization the test applies:pnm1Netpbm image data, size = 2 x 2, greymap, ASCII text, greymappnm2Netpbm image data, size = 2 x 2, rawbits, greymap, rawbits, greymappnm3Netpbm image data, size = 10 x 20, pixmap, ASCII text, pixmapgedcomGEDCOM genealogy text version 5.5, ASCII textGEDCOM genealogy text version 5.5plus unmerged continuation linesosmOpenStreetMap XML data, ASCII textOpenStreetMap XML datacmd1a /usr/bin/cmd1 script, ASCII text executablea /usr/bin/cmd1 script executable (binary data)cmd2a /usr/bin/cmd2 script, ASCII text executableascii textcmd3a /usr/bin/cmd3 script executable (binary data)datacmd4a /usr/bin/cmd4 script executable (binary data)datajpeg-textASCII text, with no line terminatorsascii textjsonlines1New Line Delimited JSON text dataascii textmultipleViva File 2.0, then- RTF1.0,- Test File 1.0,- ABCD File, ASCII text, with no line terminatorsascii textJW07022A.mp3Audio file with ID3 version 2.2.0, contains: MPEG ADTS, layer III, ...Audio file with ID3 version 2.2.0, contains: datautf16xmlsvgSVG Scalable Vector Graphics image, Unicode text, UTF-16, ..., EFI variable 3997439, total size: 6881395 bytesThese group into roughly four causes:
OpenStreetMap XML databecomesOpenStreetMap XML data, ASCII text. PolyFile stops at the type description. Accounts forosm,gedcom,pnm1,pnm3,cmd1,cmd2, andutf16xmlsvg.pnmresults loseNetpbm image data, size = 2 x 2and keep only the child's, greymap, leaving output that begins with a comma. This looks like the same area as cause 1 but is a separate defect: the text is missing from the middle of the description rather than the end..magicsidecars are mishandled.cmd1throughcmd4each ship a.magicscript that the test parses in place of the default matcher.cmd3andcmd4produce onlydata, meaning nothing in the sidecar matched.multipleexpects libmagic's\n--joined list of every match. PolyFile reports them as separate matches, which the test'sassertIncannot express.JW07022A.mp3andjsonlines1do not obviously fall into any of the four and probably want individual investigation.A related detail
PolyFile reports the plain-text classification in lower case,
ascii text, where libmagic reportsASCII text:test_file_corpushides this by lower-casing both sides, and carries a dedicated escape hatch for the exact stringASCII text. Since PolyFile's default output mode mimicsfile, the casing is user-visible even though no test sees it.Suggested outcome
Replace the blanket comment with per-stem entries naming the cause and linking the issue that tracks it, then split causes 1 through 4 into their own issues. Cause 1 alone would unskip seven of the fourteen.
Environment