@@ -54,145 +54,6 @@ def test_url():
54
54
assert url == "coaps://host:5684/path1/path2"
55
55
56
56
57
- def test_combining_mutates ():
58
- """Test combining mutates."""
59
- DATA_INT = {"key_int" : 0 }
60
- DATA_INT2 = {"key_int_2" : 1 }
61
- COMBINED_INT = {"key_int" : 0 , "key_int_2" : 1 }
62
-
63
- command1 = Command ("method" , "path" , DATA_INT )
64
- command2 = Command ("method" , "path" , DATA_INT2 )
65
- combined = command1 + command2
66
-
67
- # Adding shouldn't mutate the original commands
68
- assert command1 ._data == DATA_INT
69
- assert command2 ._data == DATA_INT2
70
- assert combined ._data == COMBINED_INT
71
-
72
- # Combining should mutate the original command
73
- command1 .combine_data (command2 )
74
- assert command1 ._data == COMBINED_INT
75
- assert command2 ._data == DATA_INT2
76
-
77
-
78
- def test_combining_with_none ():
79
- """Test combining with nothing."""
80
- DATA_INT = {"key_int" : 0 }
81
-
82
- command1 = Command ("method" , "path" , DATA_INT )
83
- combined = command1 + None
84
-
85
- assert combined ._data == DATA_INT
86
-
87
- # Combining should mutate the original command
88
- command1 .combine_data (None )
89
- assert command1 ._data == DATA_INT
90
-
91
-
92
- def test_combining_integer_keys ():
93
- """Test combining integer keys."""
94
- DATA_INT = {"key_int" : 0 }
95
- DATA_INT_SAME_KEY = {"key_int" : 1 }
96
- DATA_INT2 = {"key_int_2" : 1 }
97
- COMBINED_INT = {"key_int" : 0 , "key_int_2" : 1 }
98
-
99
- command1 = Command ("method" , "path" , DATA_INT )
100
- command2 = Command ("method" , "path" , DATA_INT2 )
101
- combined = command1 + command2
102
- assert combined ._data == COMBINED_INT
103
-
104
- command1 = Command ("method" , "path" , DATA_INT )
105
- command2 = Command ("method" , "path" , DATA_INT_SAME_KEY )
106
- # We should always take the last key if we can't merge
107
- combined = command1 + command2
108
- assert combined ._data == DATA_INT_SAME_KEY
109
-
110
-
111
- def test_combining_string_keys ():
112
- """Test combining simple keys."""
113
- DATA_STRING = {"key_string" : "a" }
114
- DATA_STRING_SAME_KEY = {"key_string" : "same" }
115
- DATA_STRING2 = {"key_string_2" : "b" }
116
- COMBINED_STRING = {"key_string" : "a" , "key_string_2" : "b" }
117
-
118
- command1 = Command ("method" , "path" , DATA_STRING )
119
- command2 = Command ("method" , "path" , DATA_STRING2 )
120
- combined = command1 + command2
121
- assert combined ._data == COMBINED_STRING
122
-
123
- command1 = Command ("method" , "path" , DATA_STRING )
124
- command2 = Command ("method" , "path" , DATA_STRING_SAME_KEY )
125
- # We should always take the last key if we can't merge
126
- combined = command1 + command2
127
- assert combined ._data == DATA_STRING_SAME_KEY
128
-
129
-
130
- def test_combining_dict_keys ():
131
- """Test combining dict keys."""
132
- DATA_EMPTY_DICT = {"key_dict" : {}}
133
- DATA_DICT_INT = {"key_dict" : {"key_int" : 0 }}
134
- DATA_DICT_STRING = {"key_dict" : {"key_string" : "a" }}
135
- DATA_DICT_STRING2 = {"key_dict" : {"key_string" : "b" }}
136
- DATA_DICT_INTSTRING = {"key_dict" : {"key_int" : 0 , "key_string" : "a" }}
137
-
138
- command1 = Command ("method" , "path" , DATA_EMPTY_DICT )
139
- command2 = Command ("method" , "path" , DATA_DICT_INT )
140
- combined = command1 + command2
141
- assert combined ._data == DATA_DICT_INT
142
-
143
- command1 = Command ("method" , "path" , DATA_DICT_INT )
144
- command2 = Command ("method" , "path" , DATA_DICT_STRING )
145
- combined = command1 + command2
146
- assert combined ._data == DATA_DICT_INTSTRING
147
-
148
- command1 = Command ("method" , "path" , DATA_DICT_STRING )
149
- command2 = Command ("method" , "path" , DATA_DICT_STRING2 )
150
- combined = command1 + command2
151
- assert combined ._data == DATA_DICT_STRING2
152
-
153
- command1 = Command ("method" , "path" , DATA_DICT_INT )
154
- command2 = Command ("method" , "path" , DATA_DICT_STRING2 )
155
- command3 = Command ("method" , "path" , DATA_DICT_STRING )
156
- combined = command1 + command2 + command3
157
- assert combined ._data == DATA_DICT_INTSTRING
158
-
159
-
160
- def test_combining_list_keys ():
161
- """Test combining simple list keys."""
162
- DATA_EMPTY_LIST = {"key_list" : []}
163
- DATA_INT_LIST1 = {"key_list" : [0 , 1 , 2 ]}
164
- DATA_INT_LIST2 = {"key_list" : [10 , 11 , 12 ]}
165
-
166
- command1 = Command ("method" , "path" , DATA_EMPTY_LIST )
167
- command2 = Command ("method" , "path" , DATA_INT_LIST1 )
168
- combined = command1 + command2
169
- assert combined ._data == DATA_INT_LIST1
170
-
171
- # Duplicated keys are replaced if not dicts
172
- command1 = Command ("method" , "path" , DATA_INT_LIST1 )
173
- command2 = Command ("method" , "path" , DATA_INT_LIST2 )
174
- combined = command1 + command2
175
- assert combined ._data == DATA_INT_LIST2
176
-
177
-
178
- def test_combining_listed_dict_keys ():
179
- """Test combining of listed dict keys."""
180
- DATA_EMPTY_DICT = {"key_ldict" : [{}]}
181
- DATA_DICT_INT = {"key_ldict" : [{"key_int" : 0 }]}
182
- DATA_DICT_STRING = {"key_ldict" : [{"key_string" : "a" }]}
183
- DATA_DICT_INTSTRING = {"key_ldict" : [{"key_int" : 0 , "key_string" : "a" }]}
184
-
185
- command1 = Command ("method" , "path" , DATA_EMPTY_DICT )
186
- command2 = Command ("method" , "path" , DATA_DICT_INT )
187
- combined = command1 + command2
188
- assert combined ._data == DATA_DICT_INT
189
-
190
- command1 = Command ("method" , "path" , DATA_DICT_INT )
191
- command2 = Command ("method" , "path" , DATA_DICT_STRING )
192
- combined = command1 + command2
193
- assert combined ._data == DATA_DICT_INTSTRING
194
-
195
-
196
57
def test_add_unsupported ():
197
58
"""Test add unsupported causes error."""
198
59
command1 = Command ("method" , "path" , {})
0 commit comments