Пример #1
0
def test_dict_construction_options():
    backend = BackendSQLite()
    d1 = yaupon.ydict(backend, one=2, two=3)
    d2 = yaupon.ydict(backend, {'one':2, 'two':3})
    d3 = yaupon.ydict(backend, zip(('one', 'two'), (2,3)))
    d4 = yaupon.ydict(backend, [['two', 3], ['one', 2]])
    expected_items = sorted([('one',2), ('two',3)])
    assert sorted([x for x in d1.iteritems()]) == expected_items
    assert sorted([x for x in d2.iteritems()]) == expected_items
    assert sorted([x for x in d3.iteritems()]) == expected_items
    assert sorted([x for x in d4.iteritems()]) == expected_items
Пример #2
0
 def __init__(self, backend=None, items=None, keys=None, cmp=cmp):
     self.nodes = ydict(backend=backend)
     # 'nodes' maps item -> [child, sibling, parent, key] 
     self.cmp = cmp
     self.head = None
     if items is not None:
         for item in items:
             self.insert(item)
     if keys is not None:
         for item, key in keys.iteritems():
             self.insert(item, key)