@@ 242-273 (lines=32) @@ | ||
239 | assert munging.sort_dict_keys_from_reflist(data, ref) == expected |
|
240 | ||
241 | ||
242 | class TestSortDictValsFromReflist: |
|
243 | """All tests for sort_dict_vals_from_reflist function.""" |
|
244 | ||
245 | def test_sort_dict_vals_from_reflist(self): |
|
246 | """Test function.""" |
|
247 | data = dict(foo=1, bar=2, baz=3, quux=4) |
|
248 | ref = [4, 3, 1, 2] |
|
249 | expected = [('quux', 4), ('baz', 3), ('foo', 1), ('bar', 2)] |
|
250 | assert munging.sort_dict_vals_from_reflist(data, ref) == expected |
|
251 | ||
252 | def test_sort_dict_vals_from_reflist_nested(self): |
|
253 | """Test function.""" |
|
254 | data = dict(foo=dict(inner1=1, inner2=2), bar=2, baz=3, quux=4) |
|
255 | ref = [4, 3, {'inner1': 1, 'inner2': 2}, 2] |
|
256 | expected = [ |
|
257 | ('quux', 4), ('baz', 3), |
|
258 | ('foo', {'inner1': 1, 'inner2': 2}), ('bar', 2)] |
|
259 | assert munging.sort_dict_vals_from_reflist(data, ref) == expected |
|
260 | ||
261 | def test_sort_dict_vals_from_reflist_none(self): |
|
262 | """Test function.""" |
|
263 | data = dict(foo=None, bar=2, baz=3, quux=4) |
|
264 | ref = [4, 3, None, 2] |
|
265 | expected = [('quux', 4), ('baz', 3), ('foo', None), ('bar', 2)] |
|
266 | assert munging.sort_dict_vals_from_reflist(data, ref) == expected |
|
267 | ||
268 | def test_sort_dict_vals_from_reflist_missing_val(self): |
|
269 | """Test function.""" |
|
270 | data = dict(foo=1, bar=2, baz=3, quux=4) |
|
271 | ref = [4, 3, 1] |
|
272 | expected = [('quux', 4), ('baz', 3), ('foo', 1)] |
|
273 | assert munging.sort_dict_vals_from_reflist(data, ref) == expected |
|
274 | ||
@@ 208-239 (lines=32) @@ | ||
205 | assert item == obj_label |
|
206 | ||
207 | ||
208 | class TestSortDictKeysFromReflist: |
|
209 | """All tests for sort_dict_keys_from_reflist function.""" |
|
210 | ||
211 | def test_sort_dict_keys_from_reflist(self): |
|
212 | """Test function.""" |
|
213 | data = dict(foo=1, bar=2, baz=3, quux=4) |
|
214 | ref = ['quux', 'baz', 'foo', 'bar'] |
|
215 | expected = [('quux', 4), ('baz', 3), ('foo', 1), ('bar', 2)] |
|
216 | assert munging.sort_dict_keys_from_reflist(data, ref) == expected |
|
217 | ||
218 | def test_sort_dict_keys_from_reflist_nested(self): |
|
219 | """Test function.""" |
|
220 | data = dict(foo=dict(inner1=1, inner2=2), bar=2, baz=3, quux=4) |
|
221 | ref = ['quux', 'baz', 'foo', 'bar'] |
|
222 | expected = [ |
|
223 | ('quux', 4), ('baz', 3), |
|
224 | ('foo', {'inner1': 1, 'inner2': 2}), ('bar', 2)] |
|
225 | assert munging.sort_dict_keys_from_reflist(data, ref) == expected |
|
226 | ||
227 | def test_sort_dict_keys_from_reflist_none(self): |
|
228 | """Test function.""" |
|
229 | data = dict(foo=None, bar=2, baz=3, quux=4) |
|
230 | ref = ['quux', 'baz', 'foo', 'bar'] |
|
231 | expected = [('quux', 4), ('baz', 3), ('foo', None), ('bar', 2)] |
|
232 | assert munging.sort_dict_keys_from_reflist(data, ref) == expected |
|
233 | ||
234 | def test_sort_dict_keys_from_reflist_missing_val(self): |
|
235 | """Test function.""" |
|
236 | data = dict(foo=1, bar=2, baz=3, quux=4) |
|
237 | ref = ['quux', 'baz', 'foo'] |
|
238 | expected = [('quux', 4), ('baz', 3), ('foo', 1)] |
|
239 | assert munging.sort_dict_keys_from_reflist(data, ref) == expected |
|
240 | ||
241 | ||
242 | class TestSortDictValsFromReflist: |