Skip to content

Commit 23732b1

Browse files
author
Joel Collins
committed
Added more types to type testing
1 parent a0e8c9e commit 23732b1

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

tests/test_server_types.py

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1-
from labthings.server import types
1+
from labthings.server import types, fields
2+
import pytest
3+
4+
from fractions import Fraction
5+
from datetime import datetime
6+
import uuid
7+
8+
9+
@pytest.fixture
10+
def types_dict():
11+
d = {
12+
"fraction": Fraction(5, 2),
13+
"map1": {
14+
"string": "Hello",
15+
"bool": False,
16+
},
17+
"int": 5,
18+
"list_int": [1, 2, 3, 4],
19+
"range": range(1, 5),
20+
"datetime": datetime.today(),
21+
"uuid": uuid.uuid4(),
22+
}
23+
24+
s = {
25+
"fraction": fields.Float(),
26+
"map1": {
27+
"string": fields.String(),
28+
"bool": fields.Boolean(),
29+
},
30+
"int": fields.Integer(),
31+
"list_int": fields.List(fields.Int()),
32+
"range": fields.List(fields.Int()),
33+
"datetime": fields.DateTime(),
34+
"uuid": fields.UUID(),
35+
}
36+
37+
return d, s
238

339

440
def test_make_primative():
@@ -29,35 +65,13 @@ def test_value_to_field():
2965
)
3066

3167

32-
def test_data_dict_to_schema():
33-
from labthings.server import fields
34-
from fractions import Fraction
68+
def test_data_dict_to_schema(types_dict):
3569
from marshmallow import Schema
3670

37-
d = {
38-
"val1": Fraction(5, 2),
39-
"map1": {
40-
"subval1": "Hello",
41-
"subval2": False,
42-
},
43-
"val2": 5,
44-
"val3": [1, 2, 3, 4],
45-
"val4": range(1, 5),
46-
}
47-
48-
gen_schema_dict = types.data_dict_to_schema(d)
49-
expected_schema_dict = {
50-
"val1": fields.Float(),
51-
"map1": {
52-
"subval1": fields.String(),
53-
"subval2": fields.Boolean(),
54-
},
55-
"val2": fields.Integer(),
56-
"val3": fields.List(fields.Int()),
57-
"val4": fields.List(fields.Int()),
58-
}
71+
data, expected_schema_dict = types_dict
72+
gen_schema_dict = types.data_dict_to_schema(data)
5973

6074
gen_schema = Schema.from_dict(gen_schema_dict)()
6175
expected_schema = Schema.from_dict(expected_schema_dict)()
6276

63-
assert gen_schema.dump(d) == expected_schema.dump(d)
77+
assert gen_schema.dump(data) == expected_schema.dump(data)

0 commit comments

Comments
 (0)