Skip to content
Permalink
Browse files

feat(flow): add eq operator to the flow to enable comparison

  • Loading branch information...
hanxiao committed Oct 14, 2019
1 parent 9ca757b commit f6536c87642430526686e1a0f7bf308997dac3a0
Showing with 26 additions and 1 deletion.
  1. +22 −1 gnes/flow/__init__.py
  2. +4 −0 tests/test_gnes_flow.py
@@ -589,7 +589,7 @@ def _build_graph(self, copy_flow: bool) -> 'Flow':
raise FlowTopologyError('flow is empty?')

# close the loop
op_flow._service_nodes[op_flow._frontend]['incomes'].add(op_flow._last_changed_service[-1])
op_flow._service_nodes[op_flow._frontend]['incomes'] = {op_flow._last_changed_service[-1]}

# build all edges
for k, v in op_flow._service_nodes.items():
@@ -726,3 +726,24 @@ def __getstate__(self):
def __setstate__(self, d):
self.__dict__.update(d)
self.logger = set_logger(self.__class__.__name__)

def __eq__(self, other):
"""
Comparing the topology of a flow with another flow.
Identification is defined by whether two flows share the same set of edges.
:param other: the second flow object
:return:
"""

if self._build_level.value < Flow.BuildLevel.GRAPH.value:
a = self.build(backend=None, copy_flow=True)
else:
a = self

if other._build_level.value < Flow.BuildLevel.GRAPH.value:
b = other.build(backend=None, copy_flow=True)
else:
b = other

return a._service_edges == b._service_edges
@@ -212,3 +212,7 @@ def test_flow_add_set(self):
.build(backend=None))

print(f2.to_url())

self.assertEqual(f1, f2)

self.assertNotEqual(f1, f2.add_router('dummy', yaml_path='BaseRouter'))

0 comments on commit f6536c8

Please sign in to comment.
You can’t perform that action at this time.