def test_del(self): o = OrderedProperties() assert 'a' not in o o.a = 1 assert 'a' in o del o.a assert 'a' not in o
def test_del_item(self): o = OrderedProperties() assert 'a' not in o o.a = 1 assert 'a' in o del o['a'] assert 'a' not in o
def test_update(self): o = OrderedProperties() o.a = 1 o.update(dict(b=2)) assert o.b == 2 assert list(o) == [1, 2]
def test_basics(self): o = OrderedProperties() o.a = 1 o.b = 2 for i, attr in enumerate(o): if i == 0: assert attr == 1 else: assert attr == 2
def test_pickle(self): o = OrderedProperties() o.a = 1 o.b = 2 ostr = pickle.dumps(o, pickle.HIGHEST_PROTOCOL) po = pickle.loads(ostr) assert po.a == 1 assert po.b == 2 assert list(po) == [1, 2]
def test_initilization(self): o = OrderedProperties(initialize=False) o.a = 1 o._initialized = True o.b = 2 assert o.a == 1 assert list(o) == [2] del o.a try: o.a assert False, 'expected exception' except AttributeError: pass
def test_add(self): o1 = OrderedProperties() o2 = OrderedProperties() o1.a = 1 o1.c = 3 o2.b = 2 o2.d = 4 result = o1 + o2 assert result == [1, 3, 2, 4]
def test_del_attribute_error(self): o = OrderedProperties() with pytest.raises(AttributeError, match='foo'): del o.foo
def test_has_key(self): o = OrderedProperties() o.a = 1 assert 'a' in o
def test_clear(self): o = OrderedProperties() o.a = 1 assert 'a' in o o.clear() assert 'a' not in o
def test_list(self): o = OrderedProperties() o.a = 1 o.b = 2 assert list(o) == [1, 2]
def __init__(self, initialize=True): self._locked = False OrderedProperties.__init__(self, initialize)