This repository has been archived by the owner on Apr 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
tests.py
100 lines (68 loc) · 2.28 KB
/
tests.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import itypes
import pytest
# [], .get()
def test_dict_get():
orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
assert orig.get('a') == 1
assert orig.get('z') is None
def test_dict_lookup():
orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
assert orig['a'] == 1
with pytest.raises(KeyError):
orig['zzz']
def test_list_lookup():
orig = itypes.List(['a', 'b', 'c'])
assert orig[1] == 'b'
with pytest.raises(IndexError):
orig[999]
# .delete(), .set()
def test_dict_delete():
orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
new = orig.delete('a')
assert new == {'b': 2, 'c': 3}
def test_dict_set():
orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
new = orig.set('d', 4)
assert new == {'a': 1, 'b': 2, 'c': 3, 'd': 4}
def test_list_delete():
orig = itypes.List(['a', 'b', 'c'])
new = orig.delete(1)
assert new == ['a', 'c']
def test_list_set():
orig = itypes.List(['a', 'b', 'c'])
new = orig.set(1, 'xxx')
assert new == ['a', 'xxx', 'c']
# .get_in()
def test_get_in():
orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
assert orig.get_in(['a', -1]) == 'z'
assert orig.get_in(['dummy', -1]) is None
assert orig.get_in(['a', 999]) is None
# .delete_in(), .set_in()
def test_delete_in():
orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
new = orig.delete_in(['a', 1])
assert new == {'a': ['x', 'z'], 'b': 2, 'c': 3}
orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
new = orig.delete_in(['a'])
assert new == {'b': 2, 'c': 3}
orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
new = orig.delete_in([])
assert new is None
def test_set_in():
orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
new = orig.set_in(['a', 1], 'yyy')
assert new == {'a': ['x', 'yyy', 'z'], 'b': 2, 'c': 3}
orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
new = orig.set_in(['a'], 'yyy')
assert new == {'a': 'yyy', 'b': 2, 'c': 3}
orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
new = orig.set_in([], 'yyy')
assert new == 'yyy'
# Objects
def test_setting_object_property():
class Example(itypes.Object):
pass
example = Example()
with pytest.raises(TypeError):
example.a = 123