def test_NodeCollection(): """Test node collection""" nodes = NodeCollection() assert len(nodes) == 0 a = Node('a') nodes.add(a) assert len(nodes) == 1 assert nodes['a'] == a assert nodes[a] == a assert 'a' in nodes assert a in nodes assert 'a' in nodes.uids assert 'a' in nodes.keys() assert a in nodes.values() assert ('a', a) in nodes.items() assert {'a': a} == nodes.dict nodes.add('b', 'c') print(nodes) assert len(nodes) == 3 with pytest.raises(Exception): nodes.add('a') with pytest.raises(Exception): nodes.add(a) d = Node('d', color='blue') nodes.add(d) assert nodes['d']['color'] == 'blue' d['color'] = 'red' assert nodes['d']['color'] == 'red' nodes.add('e', ('f', 'g'), ['h', 'i']) assert len(nodes) == 9 nodes.remove(('e', 'f', 'g'), 'h', ['i']) assert len(nodes) == 4
def test_NodeCollection(): """Test node collection""" nodes = NodeCollection() assert len(nodes) == 0 a = Node('a') nodes.add(a) assert len(nodes) == 1 assert nodes['a'] == a assert nodes[a] == a assert 'a' in nodes assert a in nodes assert 'a' in nodes.uids assert 'a' in nodes.keys() assert a in nodes.values() assert ('a', a) in nodes.items() nodes.add(('b', 'c')) assert len(nodes) == 3 # with pytest.raises(Exception): # nodes.add('a') # with pytest.raises(Exception): # nodes.add(a) d = Node('d', color='blue') nodes.add(d) assert nodes['d']['color'] == 'blue' d['color'] = 'red' assert nodes['d']['color'] == 'red' nodes.add(['e', ('f', 'g'), ['h', 'i']]) assert len(nodes) == 9 nodes.remove(a) assert len(nodes) == 8 assert a not in nodes nodes.remove('b') assert len(nodes) == 7 assert 'b' not in nodes nodes.remove([('e', 'f', 'g'), 'h', ['i']]) assert len(nodes) == 2