Coverage for tests/test_schema/test_types_collection.py: 89%
35 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-21 15:58 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-21 15:58 +0200
1from sbe2.schema import Types, Enum
2from sbe2.schema.builtin import decimal, decimal32, decimal64, int_
3from pytest import raises
6def test_types_initialization():
7 types_ =Types()
8 assert len(types_) > 0
10 assert types_['decimal'] == decimal
11 assert types_['decimal32'] == decimal32
12 assert types_['decimal64'] == decimal64
13 assert types_['int'] == int_
16def test_types_get():
17 types_ = Types()
18 assert types_['decimal'] == decimal
20 with raises(KeyError):
21 _ = types_['non_existent_type']
23def test_types_add():
24 types_ = Types()
25 new_type = Enum(name="NewType", encoding_type_name="int", description="", valid_values=[])
26 types_.add(new_type)
28 assert len(types_) > 0
29 assert types_[new_type.name] == new_type
31 with raises(ValueError):
32 types_.add(new_type)
33 # Attempting to add a type with the same name should raise ValueError
34 with raises(ValueError):
35 types_.add(new_type)
37 got = types_['NewType']
38 assert got == new_type
41def test_iter():
42 types = Types()
43 assert len(list(types)) == 15
46def test_get_composite_type():
47 types = Types()
48 assert types.get_type('int') is not None
49 with raises(ValueError):
50 types.get_composite('int')