-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:# This is a combination of 3 commits.
Addresses few comments - Refactors some class attributes and renames tests and methods - Removes _copy() - Refactors ionPyDict's constrcutor signature - Changes ion_type to be a class attribute
- Loading branch information
Showing
5 changed files
with
113 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from typing import Sequence, NamedTuple | ||
|
||
from amazon.ion.ion_py_objects import IonPyDict_new as Multimap | ||
|
||
from tests import parametrize | ||
|
||
|
||
class _P(NamedTuple): | ||
pairs: Sequence | ||
expected_all_values: Sequence | ||
expected_single_value: Sequence | ||
expected_total_len: int | ||
|
||
def __str__(self): | ||
return '{name}'.format(name=self.pairs) | ||
|
||
|
||
ALL_DATA = _P( | ||
pairs=[('a', 1), ('a', 2), ('a', 3), ('a', [4, 5, 6]), ('b', 0), ('c', {'x': 'z', 'r': 's'})], | ||
expected_all_values=[('a', [1, 2, 3, [4, 5, 6]]), ('b', [0]), ('c', [{'x': 'z', 'r': 's'}])], | ||
expected_single_value=[('a', [4, 5, 6]), ('b', 0), ('c', {'x': 'z', 'r': 's'})], | ||
expected_total_len=6 | ||
) | ||
|
||
|
||
def _create_multimap_with_items(pairs): | ||
m = Multimap() | ||
for pair in pairs: | ||
m.add_item(pair[0], pair[1]) | ||
return m | ||
|
||
|
||
@parametrize( | ||
ALL_DATA | ||
) | ||
def test_add_item(p): | ||
m = _create_multimap_with_items(p.pairs) | ||
for expected in p.expected_all_values: | ||
assert list([x for x in m.get_all_values(expected[0])]) == expected[1] | ||
for expected in p.expected_single_value: | ||
assert m[expected[0]] == expected[1] | ||
assert p.expected_total_len == len(m) | ||
|
||
|
||
@parametrize( | ||
(ALL_DATA, ["a"], 2), | ||
(ALL_DATA, ["b"], 5), | ||
(ALL_DATA, ["c"], 5), | ||
(ALL_DATA, ["a", "b"], 1), | ||
(ALL_DATA, ["a", "b", "c"], 0) | ||
) | ||
def test_delete_item(item): | ||
m = _create_multimap_with_items(item[0].pairs) | ||
p, items_to_remove, len_after_removal = item | ||
for to_remove in items_to_remove: | ||
del m[to_remove] | ||
assert len(m) == item[2] | ||
|
||
|
||
@parametrize( | ||
{}, | ||
{"a": 1}, | ||
{"a": 1, "b": 2, "c": [1, 2, {3: 4}]} | ||
) | ||
def test_constructor(d): | ||
m = Multimap(None, d) | ||
for k, v in iter(d.items()): | ||
assert m[k] == v | ||
assert len(m) == len(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters