Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(flow): add eq operator to the flow to enable comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Oct 14, 2019
1 parent 9ca757b commit f6536c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 22 additions & 1 deletion gnes/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions tests/test_gnes_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.