|
1 | | -import mimetypes |
2 | 1 | from pathlib import Path |
| 2 | +import platform |
3 | 3 | from typing import Collection |
4 | 4 | from uuid import uuid4, UUID |
5 | 5 |
|
@@ -40,28 +40,27 @@ def valid_data() -> dict: |
40 | 40 | return FileLinkDataFactory(url='www.citrine.io', filename='materials.txt') |
41 | 41 |
|
42 | 42 |
|
43 | | -def test_mime_types(collection: FileCollection): |
44 | | - mime_xlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" |
45 | | - mime_xls = "application/vnd.ms-excel" |
46 | | - mime_txt = "text/plain" |
47 | | - mime_unknown = "application/octet-stream" |
48 | | - mime_csv = "text/csv" |
49 | | - |
50 | | - test_names = { |
51 | | - "asdf.xlsx": mime_xlsx, |
52 | | - "asdf.XLSX": mime_xlsx, |
53 | | - "asdf.xls": mime_xls, |
54 | | - "asdf.TXT": mime_txt, |
55 | | - "asdf.csv": mime_csv, |
56 | | - "asdf.FAKE": mime_unknown, |
57 | | - } |
58 | | - |
59 | | - fails = [] |
60 | | - for file, mime in test_names.items(): |
61 | | - resolved = collection._mime_type(Path(file)) |
62 | | - if resolved != mime: |
63 | | - fails.append(f"{resolved} != {mime} for {file}") |
64 | | - assert fails == [], "\n".join(["MIME type mismatch:"] + fails + [f"Known encodings: {mimetypes.encodings_map}"]) |
| 43 | +@pytest.mark.parametrize( |
| 44 | + ("filename", "mimetype"), |
| 45 | + [ |
| 46 | + pytest.param( |
| 47 | + "asdf.xlsx", |
| 48 | + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", |
| 49 | + marks=pytest.mark.xfail( |
| 50 | + platform.system() == "Windows", |
| 51 | + reason="windows-latest test servers omit xlsx from their registry", |
| 52 | + strict=True |
| 53 | + ) |
| 54 | + ), |
| 55 | + ("asdf.xls", "application/vnd.ms-excel"), |
| 56 | + ("asdf.XLS", "application/vnd.ms-excel"), |
| 57 | + ("asdf.TXT", "text/plain"), |
| 58 | + ("asdf.csv", "text/csv"), |
| 59 | + ("asdf.FAKE", "application/octet-stream"), |
| 60 | + ], |
| 61 | +) |
| 62 | +def test_mime_types(collection: FileCollection, filename, mimetype): |
| 63 | + assert collection._mime_type(Path(filename)) == mimetype |
65 | 64 |
|
66 | 65 |
|
67 | 66 | def test_build_equivalence(collection, valid_data): |
|
0 commit comments