-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_serializers.py
38 lines (26 loc) · 1.1 KB
/
test_serializers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from serializers import _to_dict, _to_json, _to_yaml
def test_to_json(game):
assert (
_to_json(game)
== '{"food": [{"X": 3, "Y": 3}, {"X": 2, "Y": 2}], "grid_height": 5, "grid_width": 5, "score": 0, "snake": {"segments": [{"X": 1, "Y": 2}, {"X": 1, "Y": 1}, {"X": 2, "Y": 1}]}, "ticks": 0}' # noqa: E501
)
def test_mixin_to_json(game):
assert game.to_json() == _to_json(game)
def test_to_yaml(game):
assert (
_to_yaml(game)
== "food:\n- X: 3\n Y: 3\n- X: 2\n Y: 2\ngrid_height: 5\ngrid_width: 5\nscore: 0\nsnake:\n segments:\n - X: 1\n Y: 2\n - X: 1\n Y: 1\n - X: 2\n Y: 1\nticks: 0\n" # noqa: E501
)
def test_mixin_to_yaml(game):
assert game.to_yaml() == _to_yaml(game)
def test_to_dict(game):
assert _to_dict(game) == {
"grid_width": 5,
"grid_height": 5,
"snake": {"segments": [{"X": 1, "Y": 2}, {"X": 1, "Y": 1}, {"X": 2, "Y": 1}]},
"food": [{"X": 3, "Y": 3}, {"X": 2, "Y": 2}],
"score": 0,
"ticks": 0,
}
def test_mixin_to_dict(game):
assert game.to_dict() == _to_dict(game)