comparison wsgraph/model.py @ 32:943a4b7097af

fix tests
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 13 Dec 2012 18:59:32 -0800
parents 5f14a4183bf2
children 16673636dcb6
comparison
equal deleted inserted replaced
31:5f14a4183bf2 32:943a4b7097af
11 WSGraph is interacted with by implementing 11 WSGraph is interacted with by implementing
12 wsgraph.model.Graph object for a desired interface 12 wsgraph.model.Graph object for a desired interface
13 """ 13 """
14 14
15 @abstractmethod 15 @abstractmethod
16 def node(self, name, **values): 16 def node(self, name, value=None):
17 """ 17 """
18 get or set a node 18 get or set a node
19 19
20 When setting a node, a value of `None` will pop the value from 20 When setting a node, a value of `None` will pop the value from
21 the nodal values 21 the nodal values
27 @abstractmethod 27 @abstractmethod
28 def nodes(self): 28 def nodes(self):
29 """returns a list of all nodes""" 29 """returns a list of all nodes"""
30 30
31 @abstractmethod 31 @abstractmethod
32 def edge(self, node1, node2, **values): 32 def edge(self, node1, node2, value=None):
33 """ 33 """
34 get or set edge from node1 to node2 34 get or set edge from node1 to node2
35 """ 35 """
36 36
37 @abstractmethod 37 @abstractmethod
90 90
91 def __init__(self): 91 def __init__(self):
92 self._edges = {} 92 self._edges = {}
93 self._nodes = {} 93 self._nodes = {}
94 94
95 def node(self, name, **values): 95 def node(self, name, value=None):
96 if values: 96 if value is not None:
97 # setter 97 # setter
98 self._nodes[name] = deepcopy(values) 98 self._nodes[name] = deepcopy(value)
99 else: 99 else:
100 # getter 100 # getter
101 # TODO: deepcopy 101 # TODO: deepcopy
102 return self._nodes.get(name, None) 102 return self._nodes.get(name, None)
103 103
104 def nodes(self): 104 def nodes(self):
105 return self._nodes.keys() 105 return self._nodes.keys()
106 106
107 def edge(self, node1, node2, **values): 107 def edge(self, node1, node2, value=None):
108 if values: 108 if value is not None:
109 # setter 109 # setter
110 self._edges[(node1, node2)] = deepcopy(values) 110 self._edges[(node1, node2)] = deepcopy(value)
111 for node in node1, node2:
112 self._nodes.setdefault(node, {})
111 else: 113 else:
112 # getter 114 # getter
113 # TODO: deepcopy 115 # TODO: deepcopy
114 return self._edges.get((node1, node2), None) 116 return self._edges.get((node1, node2), None)
115 117