Skip to content

Commit

Permalink
added vertex has_attr
Browse files Browse the repository at this point in the history
  • Loading branch information
tscizzle committed Oct 4, 2016
1 parent 6f90a51 commit baaef4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions graphpy/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def set(self, attr, value):
""" Set an attribute """
self._attrs[attr] = value

def has_attr(self, attr):
""" Check if an attribute exists """
return attr in self._attrs

def del_attr(self, attr):
""" Delete an attribute """
del self._attrs[attr]
Expand Down Expand Up @@ -170,6 +174,10 @@ def set(self, attr, value):
""" Set an attribute """
self._attrs[attr] = value

def has_attr(self, attr):
""" Check if an attribute exists """
return attr in self._attrs

def del_attr(self, attr):
""" Delete an attribute """
del self._attrs[attr]
Expand Down
22 changes: 22 additions & 0 deletions tests/test_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ def test_undirected_vertex_set(self):

self.assertEqual(v0.attrs, {'city': 'Modena', 0: 1})

def test_undirected_vertex_has_attr(self):
""" Check if an undirected vertex has a particular attribute """
v0 = UndirectedVertex(val='v0', attrs={'city': 'Modena', 0: 1})

self.assertTrue(v0.has_attr('city'))
self.assertFalse(v0.has_attr('town'))

v0.del_attr('city')

self.assertFalse(v0.has_attr('city'))

def test_undirected_vertex_del_attr(self):
""" Delete an attribute of an undirected vertex """
v0 = UndirectedVertex(val='v0', attrs={'city': 'Modena', 0: 1})
Expand Down Expand Up @@ -327,6 +338,17 @@ def test_directed_vertex_set(self):

self.assertEqual(v0.attrs, {'city': 'Modena', 0: 1})

def test_undirected_vertex_has_attr(self):
""" Check if a directed vertex has a particular attribute """
v0 = DirectedVertex(val='v0', attrs={'city': 'Modena', 0: 1})

self.assertTrue(v0.has_attr('city'))
self.assertFalse(v0.has_attr('town'))

v0.del_attr('city')

self.assertFalse(v0.has_attr('city'))

def test_directed_vertex_del_attr(self):
""" Delete an attribute of a directed vertex """
v0 = DirectedVertex(val='v0', attrs={'city': 'Modena', 0: 1})
Expand Down

0 comments on commit baaef4c

Please sign in to comment.