1+ import typing as ty
2+ import pytest
13from fileformats .application import Cdfx___Xml
2- from fileformats .core .identification import from_mime
4+ from fileformats .core import DataType
5+ from fileformats .core .identification import to_mime , from_mime
36from fileformats .generic import DirectoryOf , FileSet
4- from fileformats .testing import Classified , U , V
7+ from fileformats .application import Zip
8+ from fileformats .testing import Classified , A , B , U , V , X , MyFormat
59from fileformats .vendor .testing .testing import Psi , VendorClassified , Theta , Zeta
610from fileformats .vendor .openxmlformats_officedocument .application import (
711 Wordprocessingml_Document ,
@@ -24,59 +28,108 @@ def test_mimelike_roundtrip() -> None:
2428 assert reloaded is klass
2529
2630
27- def test_vendor_to_mime_roundtrip () -> None :
28- assert Psi .mime_like == "testing/vnd.testing.psi"
29- assert from_mime ("testing/vnd.testing.psi" ) is Psi
31+ @pytest .mark .parametrize (
32+ ["klass" , "expected_mime" ],
33+ [
34+ [Psi , "testing/vnd.testing.psi" ],
35+ [
36+ VendorClassified [Zeta , Theta ],
37+ "testing/[vnd.testing.theta..vnd.testing.zeta]+vnd.testing.vendor-classified" ,
38+ ],
39+ [
40+ Classified [Zeta , Theta ],
41+ "testing/[vnd.testing.theta..vnd.testing.zeta]+classified" ,
42+ ],
43+ [VendorClassified [U , V ], "testing/[u..v]+vnd.testing.vendor-classified" ],
44+ [Zip [Classified [U ]], "testing/u+classified+zip" ],
45+ [Zip [Classified [U , X ]], "testing/[u..v]+classified+zip" ],
46+ [Classified [U , Zip [MyFormat ]], "testing/[u..my-format+zip]+classified" ],
47+ [Classified [U , MyFormat [A , B ]], "testing/[u..[a..b]+my-format]+classified" ],
48+ [
49+ Wordprocessingml_Document ,
50+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
51+ ],
52+ [
53+ DirectoryOf [Wordprocessingml_Document ],
54+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document+directory" ,
55+ ],
56+ [Cdfx___Xml , "application/vnd.ms-cdfx+xml" ],
57+ [U | V , "testing/u,testing/v" ],
58+ ],
59+ )
60+ def test_compound_mime_roundtrip (klass : ty .Type [DataType ], expected_mime : str ) -> None :
61+ assert to_mime (klass , official = False ) == expected_mime
62+ assert from_mime (expected_mime ) is klass
63+
64+
65+ # def test_vendor_to_mime_roundtrip() -> None:
66+ # assert Psi.mime_like == "testing/vnd.testing.psi"
67+ # assert from_mime("testing/vnd.testing.psi") is Psi
68+
69+
70+ # def test_vendor_to_mime_classified_rountrip() -> None:
71+ # assert (
72+ # VendorClassified[Zeta, Theta].mime_like
73+ # == "testing/[vnd.testing.theta..vnd.testing.zeta]+vnd.testing.vendor-classified"
74+ # )
75+ # assert (
76+ # from_mime(
77+ # "testing/[vnd.testing.theta..vnd.testing.zeta]+vnd.testing.vendor-classified"
78+ # )
79+ # is VendorClassified[Zeta, Theta]
80+ # )
81+
82+
83+ # def test_vendor_to_mime_parent_classified_rountrip() -> None:
84+ # assert (
85+ # Classified[Zeta, Theta].mime_like
86+ # == "testing/[vnd.testing.theta..vnd.testing.zeta]+classified"
87+ # )
88+ # assert (
89+ # from_mime("testing/[vnd.testing.theta..vnd.testing.zeta]+classified")
90+ # is Classified[Zeta, Theta]
91+ # )
92+
93+
94+ # def test_vendor_to_mime_parent_classifiers_rountrip() -> None:
95+ # assert (
96+ # VendorClassified[U, V].mime_like
97+ # == "testing/[u..v]+vnd.testing.vendor-classified"
98+ # )
99+ # assert (
100+ # from_mime("testing/[u..v]+vnd.testing.vendor-classified")
101+ # is VendorClassified[U, V]
102+ # )
30103
31104
32- def test_vendor_to_mime_classified_rountrip () -> None :
33- assert (
34- VendorClassified [Zeta , Theta ].mime_like
35- == "testing/[vnd.testing.theta..vnd.testing.zeta]+vnd.testing.vendor-classified"
36- )
37- assert (
38- from_mime (
39- "testing/[vnd.testing.theta..vnd.testing.zeta]+vnd.testing.vendor-classified"
40- )
41- is VendorClassified [Zeta , Theta ]
42- )
105+ # def test_double_classified_roundtrip1() -> None:
106+ # assert Zip[Classified[U]].mime_like == "testing/u+classified+zip"
107+ # assert from_mime("testing/[[u..v]+classified]+zip") is Zip[Classified[U]]
43108
44109
45- def test_vendor_to_mime_parent_classified_rountrip () -> None :
46- assert (
47- Classified [Zeta , Theta ].mime_like
48- == "testing/[vnd.testing.theta..vnd.testing.zeta]+classified"
49- )
50- assert (
51- from_mime ("testing/[vnd.testing.theta..vnd.testing.zeta]+classified" )
52- is Classified [Zeta , Theta ]
53- )
110+ # def test_double_classified_roundtrip2() -> None:
111+ # assert Zip[Classified[U, V]].mime_like == "testing/[u..v]+classified+zip"
112+ # assert from_mime("testing/[[u..v]+classified]+zip") is Zip[Classified[U, V]]
54113
55114
56- def test_vendor_to_mime_parent_classifiers_rountrip () -> None :
57- assert (
58- VendorClassified [U , V ].mime_like
59- == "testing/[u..v]+vnd.testing.vendor-classified"
60- )
61- assert (
62- from_mime ("testing/[u..v]+vnd.testing.vendor-classified" )
63- is VendorClassified [U , V ]
64- )
115+ # def test_double_classified_roundtrip2() -> None:
116+ # assert Zip[Classified[U, V]].mime_like == "testing/[u..v]+classified+zip"
117+ # assert from_mime("testing/[[u..v]+classified]+zip") is Zip[Classified[U, V]]
65118
66119
67- def test_vendor_roundtrip () -> None :
120+ # def test_vendor_roundtrip() -> None:
68121
69- mime = Wordprocessingml_Document .mime_like
70- assert Wordprocessingml_Document is from_mime (mime )
122+ # mime = Wordprocessingml_Document.mime_like
123+ # assert Wordprocessingml_Document is from_mime(mime)
71124
72125
73- def test_vendor_in_container_roundtrip () -> None :
126+ # def test_vendor_in_container_roundtrip() -> None:
74127
75- mime = DirectoryOf [Wordprocessingml_Document ].mime_like
76- assert DirectoryOf [Wordprocessingml_Document ] is from_mime (mime )
128+ # mime = DirectoryOf[Wordprocessingml_Document].mime_like
129+ # assert DirectoryOf[Wordprocessingml_Document] is from_mime(mime)
77130
78131
79- def test_native_container_roundtrip () -> None :
132+ # def test_native_container_roundtrip() -> None:
80133
81- mime = Cdfx___Xml .mime_like
82- assert Cdfx___Xml is from_mime (mime )
134+ # mime = Cdfx___Xml.mime_like
135+ # assert Cdfx___Xml is from_mime(mime)
0 commit comments