|
1 | 1 | from __future__ import annotations |
| 2 | + |
2 | 3 | import decimal |
| 4 | + |
3 | 5 | import pytest |
4 | 6 | from pydra.compose import python |
5 | | -from fileformats.core import from_mime, DataType, FileSet |
6 | | -from fileformats.core import converter |
| 7 | + |
7 | 8 | from fileformats.application import Zip |
8 | | -from fileformats.generic import DirectoryOf |
9 | | -from fileformats.field import Array, Integer, Decimal, Text, Boolean |
| 9 | +from fileformats.core import DataType, FileSet, converter, from_mime |
10 | 10 | from fileformats.core.exceptions import ( |
11 | | - FormatDefinitionError, |
12 | 11 | FormatConversionError, |
13 | | - FormatRecognitionError, |
| 12 | + FormatDefinitionError, |
14 | 13 | FormatMismatchError, |
| 14 | + FormatRecognitionError, |
15 | 15 | ) |
| 16 | +from fileformats.field import Array, Boolean, Decimal, Integer, Text |
| 17 | +from fileformats.generic import DirectoryOf |
| 18 | +from fileformats.testing import J # Y, |
16 | 19 | from fileformats.testing import ( |
17 | 20 | A, |
18 | 21 | B, |
19 | 22 | C, |
| 23 | + Classified, |
20 | 24 | D, |
21 | 25 | E, |
22 | 26 | F, |
23 | 27 | G, |
24 | 28 | H, |
25 | | - J, |
26 | 29 | K, |
27 | 30 | L, |
28 | 31 | M, |
|
31 | 34 | Q, |
32 | 35 | R, |
33 | 36 | TestField, |
34 | | - Classified, |
35 | 37 | U, |
36 | 38 | V, |
37 | 39 | W, |
38 | 40 | X, |
39 | | - # Y, |
40 | 41 | Z, |
41 | 42 | ) |
42 | 43 |
|
43 | | - |
44 | 44 | SpecificDataType = DataType.type_var("SpecificDataType") |
45 | 45 | SpecificFileSet = FileSet.type_var("SpecificFileSet") |
46 | 46 |
|
@@ -242,9 +242,28 @@ def test_mime_roundtrips(): |
242 | 242 | assert from_mime("testing/b.a+k") is K[B, A] |
243 | 243 | assert from_mime("testing/b.a+k") is not K[A, B] |
244 | 244 |
|
245 | | - with pytest.raises(FormatRecognitionError) as e: |
| 245 | + with pytest.raises( |
| 246 | + FormatRecognitionError, match="Cannot create reversible MIME type" |
| 247 | + ): |
246 | 248 | Array[TestField].mime_like |
247 | | - assert "Cannot create reversible MIME type for " in str(e) |
| 249 | + |
| 250 | + |
| 251 | +def test_mime_fail(): |
| 252 | + class BadFormat(DataType): |
| 253 | + pass |
| 254 | + |
| 255 | + with pytest.raises(FormatDefinitionError, match="Cannot determine namespace"): |
| 256 | + BadFormat.namespace |
| 257 | + |
| 258 | + |
| 259 | +def test_vendor_mime_fail(): |
| 260 | + class BadVendorFormat(DataType): |
| 261 | + pass |
| 262 | + |
| 263 | + BadVendorFormat.__module__ = "fileformats.vendor.badnamespace" |
| 264 | + |
| 265 | + with pytest.raises(FormatDefinitionError, match="Cannot determine namespace"): |
| 266 | + BadVendorFormat.namespace |
248 | 267 |
|
249 | 268 |
|
250 | 269 | def test_inherited_classifiers(): |
@@ -430,3 +449,4 @@ def test_classifier_categories6(): |
430 | 449 | match="Cannot have more than one occurrence of a classifier ", |
431 | 450 | ): |
432 | 451 | Classified[C, E] |
| 452 | + Classified[C, E] |
0 commit comments