Skip to content

Commit 994ba06

Browse files
mgornyTinche
authored andcommitted
Make it possible to skip cbor2 tests
Now that `cbor2` has been rewritten in Rust and the fallback Python implementation was removed, it is no longer possible to use it on all architectures where cattrs are used. Move the `cbor2` imports into specific tests, so that the test suite can be run again, while skipping the handful of tests that actually need it. Signed-off-by: Michał Górny <mgorny@gentoo.org>
1 parent 290d681 commit 994ba06

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

tests/test_preconf.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
)
4646
from cattrs.fns import identity
4747
from cattrs.preconf.bson import make_converter as bson_make_converter
48-
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
4948
from cattrs.preconf.json import make_converter as json_make_converter
5049
from cattrs.preconf.msgpack import make_converter as msgpack_make_converter
5150
from cattrs.preconf.pyyaml import make_converter as pyyaml_make_converter
@@ -838,20 +837,26 @@ def test_cbor2(everything: Everything):
838837
from cbor2 import dumps as cbor2_dumps
839838
from cbor2 import loads as cbor2_loads
840839

840+
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
841+
841842
converter = cbor2_make_converter()
842843
raw = cbor2_dumps(converter.unstructure(everything))
843844
assert converter.structure(cbor2_loads(raw), Everything) == everything
844845

845846

846847
@given(everythings(min_int=-9223372036854775808, max_int=18446744073709551615))
847848
def test_cbor2_converter(everything: Everything):
849+
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
850+
848851
converter = cbor2_make_converter()
849852
raw = converter.dumps(everything)
850853
assert converter.loads(raw, Everything) == everything
851854

852855

853856
@given(everythings(min_int=-9223372036854775808, max_int=18446744073709551615))
854857
def test_cbor2_converter_unstruct_collection_overrides(everything: Everything):
858+
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
859+
855860
converter = cbor2_make_converter(unstruct_collection_overrides={Set: sorted})
856861
raw = converter.unstructure(everything)
857862
assert raw["a_set"] == sorted(raw["a_set"])
@@ -862,6 +867,8 @@ def test_cbor2_converter_unstruct_collection_overrides(everything: Everything):
862867
@given(union_and_val=native_unions(include_datetimes=False), detailed_validation=...)
863868
def test_cbor2_unions(union_and_val: tuple, detailed_validation: bool):
864869
"""Native union passthrough works."""
870+
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
871+
865872
converter = cbor2_make_converter(detailed_validation=detailed_validation)
866873
type, val = union_and_val
867874

@@ -871,6 +878,8 @@ def test_cbor2_unions(union_and_val: tuple, detailed_validation: bool):
871878
def test_cbor2_native_enums():
872879
"""Bare, string and int enums are handled correctly."""
873880

881+
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
882+
874883
converter = cbor2_make_converter()
875884

876885
assert converter.dumps(Everything.AnIntEnum.A) == converter.dumps(
@@ -886,6 +895,8 @@ def test_cbor2_native_enums():
886895

887896
def test_cbor2_efficient_enum():
888897
"""`str` and `int` enums are handled efficiently."""
898+
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
899+
889900
converter = cbor2_make_converter()
890901

891902
assert converter.get_unstructure_hook(Everything.AnIntEnum) == identity
@@ -970,7 +981,6 @@ def test_msgspec_efficient_enum():
970981
"converter_factory",
971982
[
972983
bson_make_converter,
973-
cbor2_make_converter,
974984
json_make_converter,
975985
msgpack_make_converter,
976986
tomlkit_make_converter,
@@ -986,6 +996,13 @@ def test_literal_dicts(converter_factory: Callable[[], Converter]):
986996
assert converter.unstructure({"a": 1}, Dict[Literal["a"], int]) == {"a": 1}
987997

988998

999+
def test_literal_dicts_cbor2():
1000+
"""Dicts with keys that aren't subclasses of `type` work."""
1001+
from cattrs.preconf.cbor2 import make_converter as cbor2_make_converter
1002+
1003+
test_literal_dicts(cbor2_make_converter)
1004+
1005+
9891006
@pytest.mark.skipif(NO_ORJSON, reason="orjson not available")
9901007
def test_literal_dicts_orjson():
9911008
"""Dicts with keys that aren't subclasses of `type` work."""

0 commit comments

Comments
 (0)