Skip to content

Commit 77707e9

Browse files
committed
Testing for colours feature in netgen.
1 parent 1f72f69 commit 77707e9

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

gitnet/gitnet_tests/test_netgen.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,28 @@ def test_author_file(self):
209209
self.assertEqual(n[1],net2.node[n[0]])
210210
self.assertEqual(len(net),len(net2))
211211

212+
def test_no_colours(self):
213+
net = self.my_log.generate_network('author', 'files', colours=None)
214+
nodes = str(net.nodes(data=True))
215+
print(nodes)
216+
self.assertIn('Bob' and 'Alice', nodes)
217+
# self.assertIn(not 'colour', nodes)
218+
# self.assertIn(not 'lightcoral', nodes)
219+
# self.assertIn(not 'oldlace', nodes)
220+
221+
def test_simple_colours(self):
222+
net = self.my_log.generate_network('author', 'files', colours='simple')
223+
nodes = str(net.nodes(data=True))
224+
#print(nodes)
225+
self.assertIn("'id': 'readme.md'" and "'type': 'files'" and "'colour': 'lightcoral'", nodes)
226+
self.assertIn("'id': 'Alice'" and "'type': 'author'" and "'colour': 'oldlace'", nodes)
227+
228+
def test_complex_colours(self):
229+
net = self.my_log.generate_network('author', 'files', colours='complex')
230+
nodes = str(net.nodes(data=True))
231+
self.assertIn("'id': 'readme.md'" and "'type': 'files'" and "'colour': 'lightgrey'", nodes)
232+
self.assertIn("'id': 'Alice'" and "'type': 'author'" and "'colour': 'oldlace'", nodes)
233+
212234
def tearDown(self):
213235
sub.call(["rm","-rf",".git"])
214236

gitnet/log.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -804,21 +804,21 @@ def generate_network(self, mode1, mode2, colours=None, edge_helper=net_edges_sim
804804
if graph.node[n]['type'] == mode2:
805805
graph.node[n]['colour'] = 'lightcoral'
806806
elif colours == 'complex':
807-
for n in graph.nodes():
808-
if graph.node[n]['type'] == 'author':
809-
graph.node[n]['colour'] = 'oldlace'
810-
elif ".py" in graph.node[n]['id']:
811-
graph.node[n]['colour'] = 'springgreen'
812-
elif ".cc" in graph.node[n]['id']:
813-
graph.node[n]['colour'] = 'seagreen'
814-
elif ".md" in graph.node[n]['id']:
815-
graph.node[n]['colour'] = 'orange'
816-
elif ".sh" in graph.node[n]['id']:
817-
graph.node[n]["colour"] = "slateblue"
818-
elif ".html" in graph.node[n]["id"]:
819-
graph.node[n]["colour"] = "plum"
820-
else:
821-
graph.node[n]['colour'] = 'lightgrey'
807+
for n in graph.nodes():
808+
if graph.node[n]['type'] == 'author':
809+
graph.node[n]['colour'] = 'oldlace'
810+
elif ".py" in graph.node[n]['id']:
811+
graph.node[n]['colour'] = 'springgreen'
812+
elif ".cc" in graph.node[n]['id']:
813+
graph.node[n]['colour'] = 'seagreen'
814+
elif ".md" in graph.node[n]['id']:
815+
graph.node[n]['colour'] = 'orange'
816+
elif ".sh" in graph.node[n]['id']:
817+
graph.node[n]["colour"] = "slateblue"
818+
elif ".html" in graph.node[n]["id"]:
819+
graph.node[n]["colour"] = "plum"
820+
else:
821+
graph.node[n]['colour'] = 'lightgrey'
822822
return graph
823823

824824
def write_edges(self, fname, mode1, mode2, helper=net_edges_simple, edge_attribute=['weight', 'date']):

0 commit comments

Comments
 (0)