Skip to content

Commit e414978

Browse files
committed
add mixins test
1 parent a09d55c commit e414978

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

tests/ignite/base/test_mixins.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@
33
from ignite.base import Serializable
44

55

6+
class ExampleSerializable(Serializable):
7+
_state_dict_all_req_keys = ("a", "b")
8+
_state_dict_one_of_opt_keys = (("c", "d"), ("e", "f"))
9+
10+
611
def test_state_dict():
712
s = Serializable()
813
with pytest.raises(NotImplementedError):
914
s.state_dict()
1015

11-
1216
def test_load_state_dict():
13-
s = Serializable()
14-
s.load_state_dict({})
17+
18+
s = ExampleSerializable()
19+
with pytest.raises(TypeError, match=r"Argument state_dict should be a dictionary"):
20+
s.load_state_dict("abc")
21+
22+
with pytest.raises(ValueError, match=r"is absent in provided state_dict"):
23+
s.load_state_dict({})
24+
25+
with pytest.raises(ValueError, match=r"is absent in provided state_dict"):
26+
s.load_state_dict({"a": 1})
27+
28+
with pytest.raises(ValueError, match=r"state_dict should contain only one of"):
29+
s.load_state_dict({"a": 1, "b": 2})
30+
31+
with pytest.raises(ValueError, match=r"state_dict should contain only one of"):
32+
s.load_state_dict({"a": 1, "b": 2, "c": 3, "d": 4, "e": 5})
33+
34+
with pytest.raises(ValueError, match=r"state_dict should contain only one of"):
35+
s.load_state_dict({"a": 1, "b": 2, "c": 3, "e": 5, "f": 5})
36+
37+
s.state_dict_user_keys.append("alpha")
38+
with pytest.raises(ValueError, match=r"Required user state attribute"):
39+
s.load_state_dict({"a": 1, "b": 2, "c": 3, "e": 4})

0 commit comments

Comments
 (0)