def test_sanitize_sequence(): d = {'a': 1, 'b': 2, 'c': 3} k = ['a', 'b', 'c'] v = [1, 2, 3] i = [('a', 1), ('b', 2), ('c', 3)] assert k == sorted(cbook.sanitize_sequence(d.keys())) assert v == sorted(cbook.sanitize_sequence(d.values())) assert i == sorted(cbook.sanitize_sequence(d.items())) assert i == cbook.sanitize_sequence(i) assert k == cbook.sanitize_sequence(k)
def test_sanitize_sequence(): d = {"a": 1, "b": 2, "c": 3} k = ["a", "b", "c"] v = [1, 2, 3] i = [("a", 1), ("b", 2), ("c", 3)] assert k == sorted(cbook.sanitize_sequence(d.keys())) assert v == sorted(cbook.sanitize_sequence(d.values())) assert i == sorted(cbook.sanitize_sequence(d.items())) assert i == cbook.sanitize_sequence(i) assert k == cbook.sanitize_sequence(k)
def _replacer(data, value): """ Either returns ``data[value]`` or passes ``data`` back, converts either to a sequence. """ try: # if key isn't a string don't bother if isinstance(value, str): # try to use __getitem__ value = data[value] except Exception: # key does not exist, silently fall back to key pass return sanitize_sequence(value)