Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     if 1 == len(args) and isinstance(args[0], type(self)):
         items = copy.copy(args[0].items)
     elif 1 == len(args) and isinstance(args[0], dict):
         items = args[0].items()
         if sequencetools.all_are_pairs_of_types(items, int, dict):
             items = [(x, self.item_class(**y)) for x, y in items]
         assert sequencetools.all_are_pairs_of_types(
             items, int, self.item_class)
         items = dict(items)
     elif sequencetools.all_are_pairs_of_types(args, int, self.item_class):
         items = dict(args)
     elif sequencetools.all_are_pairs_of_types(args, int, dict):
         items = [(x, self.item_class(**y)) for x, y in args]
         items = dict(items)
     elif all(isinstance(x, self.item_class) for x in args):
         items = [(i, x) for i, x in enumerate(args)]
         items = dict(items)
     elif all(isinstance(x, dict) for x in args):
         items = [(i, self.item_class(**x)) for i, x in enumerate(args)]
         items = dict(items)
     else:
         raise ValueError
     if items:
         assert 0 <= min(items)
     self._items = dict(items)
     self._lookups = self._create_lookups()
def test_sequencetools_all_are_pairs_of_types_02():
    assert not all_are_pairs_of_types('foo', str, int)
    assert not all_are_pairs_of_types(1.5, str, int)
    assert not all_are_pairs_of_types([1, 2], str, int)
    assert not all_are_pairs_of_types([(1, 2), (3, 4), (5, 6, 7)], str, int)
    assert not all_are_pairs_of_types([('a', 1.1), ('b', 2.3), ('c', 3.5)], str, int)
    assert not all_are_pairs_of_types([('a', 1), ('b', 2), ('c', 3.3)], str, int)
def test_sequencetools_all_are_pairs_of_types_01():
    assert all_are_pairs_of_types([('a', 1), ('b', 2), ('c', 3), ('derp', 666)], str, int)
    assert all_are_pairs_of_types([], str, int)