Beispiel #1
0
 def test_remove_hub_followed_by_others(self):
     g = GraphBackend().add_hub('h1', 'h2')\
         .link('h1', 'h2').link('h2', 'h1')
     g.remove_hub('h1')
     self.assertFalse(g.is_hub('h1'))
     self.assertTrue(g.is_hub('h2'))
     self.assertEqual(g.links('h2'), set(['h1']))
Beispiel #2
0
 def test_remove_hub_followed_by_others(self):
     g = GraphBackend().add_hub('h1', 'h2')\
         .link('h1', 'h2').link('h2', 'h1')
     g.remove_hub('h1')
     self.assertFalse(g.is_hub('h1'))
     self.assertTrue(g.is_hub('h2'))
     self.assertEqual(g.links('h2'), set(['h1']))
Beispiel #3
0
 def test_remove_hub_link(self):
     g = GraphBackend().add_hub('foo', 'bar').link('foo', 'bar')
     g.remove_hub('bar')
     self.assertTrue(g.is_hub('foo'))
     self.assertFalse(g.is_hub('bar'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set(['bar']))
Beispiel #4
0
 def test_remove_hub_link(self):
     g = GraphBackend().add_hub('foo', 'bar').link('foo', 'bar')
     g.remove_hub('bar')
     self.assertTrue(g.is_hub('foo'))
     self.assertFalse(g.is_hub('bar'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set(['bar']))
Beispiel #5
0
 def test_follow_follower(self):
     g = GraphBackend().add_hub('h1', 'h2').link('h1', 'h2')
     self.assertEqual(g.links('h1'), set(['h2']))
     self.assertEqual(g.links('h2'), set())
     self.assertTrue(g.is_hub('h1'))
     self.assertTrue(g.is_hub('h2'))
     g.link('h2', 'h1')
     self.assertEqual(g.links('h1'), set(['h2']))
     self.assertEqual(g.links('h2'), set(['h1']))
     self.assertTrue(g.is_hub('h1'))
     self.assertTrue(g.is_hub('h2'))
Beispiel #6
0
 def test_follow_follower(self):
     g = GraphBackend().add_hub('h1', 'h2').link('h1', 'h2')
     self.assertEqual(g.links('h1'), set(['h2']))
     self.assertEqual(g.links('h2'), set())
     self.assertTrue(g.is_hub('h1'))
     self.assertTrue(g.is_hub('h2'))
     g.link('h2', 'h1')
     self.assertEqual(g.links('h1'), set(['h2']))
     self.assertEqual(g.links('h2'), set(['h1']))
     self.assertTrue(g.is_hub('h1'))
     self.assertTrue(g.is_hub('h2'))
Beispiel #7
0
 def test_remove_node_link(self):
     g = GraphBackend()
     g.add_hub('foo')
     g.link('foo', 'bar')
     self.assertEqual(g.links('foo'), set(['bar']))
     self.assertEqual(g.links('bar'), set(['foo']))
     with self.assertRaises(Exception) as exc:
         g.remove_hub('foo')
     self.assertEqual(exc.exception.message,
                      "Can't remove hub with connected nodes")
     g.unlink('foo', 'bar')
     self.assertTrue(g.is_hub('foo'))
     self.assertFalse(g.is_hub('bar'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set())
Beispiel #8
0
 def test_add_node_link(self):
     g = GraphBackend()
     g.add_hub('foo')
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'foo')
     self.assertEqual(
         exc.exception.message,
         "Hub can't be linked to itself"
     )
     g.link('foo', 'bar')
     self.assertFalse(g.is_hub('bar'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set(['bar']))
     self.assertEqual(g.hub_links('foo'), set(['bar']))
     with self.assertRaises(Exception) as exc:
         g.hub_links('bar')
     self.assertEqual(
         exc.exception.message,
         "Hub 'bar' does not exist"
     )
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'bar')
     self.assertEqual(
         exc.exception.message,
         "Hub 'foo' is already connected to node 'bar'"
     )
Beispiel #9
0
 def test_remove_node_link(self):
     g = GraphBackend()
     g.add_hub('foo')
     g.link('foo', 'bar')
     self.assertEqual(g.links('foo'), set(['bar']))
     self.assertEqual(g.links('bar'), set(['foo']))
     with self.assertRaises(Exception) as exc:
         g.remove_hub('foo')
     self.assertEqual(
         exc.exception.message,
         "Can't remove hub with connected nodes"
     )
     g.unlink('foo', 'bar')
     self.assertTrue(g.is_hub('foo'))
     self.assertFalse(g.is_hub('bar'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set())
Beispiel #10
0
 def test_remove_hub_without_link(self):
     g = GraphBackend()
     with self.assertRaises(Exception) as exc:
         g.remove_hub('foo')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
     g.add_hub('foo')
     g.remove_hub('foo')
     # ensure hub is deleted
     self.assertFalse(g.is_hub('foo'))
     self.assertEqual(g.hubs(), set())
     # try to unlink a node from 'foo'
     with self.assertRaises(Exception) as exc:
         g.unlink('foo', 'bar')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
Beispiel #11
0
 def test_add_hub(self):
     g = GraphBackend()
     g.add_hub('foo')
     self.assertTrue(g.is_hub('foo'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set())
     self.assertEqual(g.hub_links('foo'), set())
     with self.assertRaises(Exception) as exc:
         g.add_hub('foo')
     self.assertEqual(exc.exception.message, "Hub 'foo' already exists")
     with self.assertRaises(Exception) as exc:
         g.unlink('foo', 'bar')
     self.assertEqual(exc.exception.message,
                      "Hub 'foo' is not connected to node 'bar'")
Beispiel #12
0
 def test_add_hub_link(self):
     g = GraphBackend().add_hub('foo', 'bar').link('foo', 'bar')
     self.assertTrue(g.is_hub('foo'))
     self.assertTrue(g.is_hub('bar'))
     self.assertEquals(g.links('foo'), set(['bar']))
     self.assertEquals(g.hub_links('foo'), set(['bar']))
     self.assertEquals(g.links('bar'), set())
     self.assertEquals(g.hub_links('bar'), set())
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'bar')
     self.assertEquals(exc.exception.message,
                       "Hub 'foo' is already connected to node 'bar'")
     g.link('bar', 'foo')
     self.assertEquals(g.links('foo'), set(['bar']))
     self.assertEquals(g.hub_links('foo'), set(['bar']))
     self.assertEquals(g.links('bar'), set(['foo']))
     self.assertEquals(g.hub_links('bar'), set(['foo']))
Beispiel #13
0
 def test_empty_graph(self):
     """ Test properties of an empty graph """
     g = GraphBackend()
     self.assertEqual(g.hubs(), set())
     with self.assertRaises(Exception) as exc:
         g.unlink('foo', 'bar')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
     with self.assertRaises(Exception) as exc:
         g.links('foo')
     self.assertEqual(exc.exception.message, "Unknown node 'foo'")
     with self.assertRaises(Exception) as exc:
         g.hub_links('foo')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
     self.assertFalse(g.is_hub('foo'))
     # try to link an unknown hub to an unknown node
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'bar')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
Beispiel #14
0
 def test_empty_graph(self):
     """ Test properties of an empty graph """
     g = GraphBackend()
     self.assertEqual(g.hubs(), set())
     with self.assertRaises(Exception) as exc:
         g.unlink('foo', 'bar')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
     with self.assertRaises(Exception) as exc:
         g.links('foo')
     self.assertEqual(exc.exception.message, "Unknown node 'foo'")
     with self.assertRaises(Exception) as exc:
         g.hub_links('foo')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
     self.assertFalse(g.is_hub('foo'))
     # try to link an unknown hub to an unknown node
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'bar')
     self.assertEqual(exc.exception.message, "Hub 'foo' does not exist")
Beispiel #15
0
 def test_add_hub(self):
     g = GraphBackend()
     g.add_hub('foo')
     self.assertTrue(g.is_hub('foo'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set())
     self.assertEqual(g.hub_links('foo'), set())
     with self.assertRaises(Exception) as exc:
         g.add_hub('foo')
     self.assertEqual(
         exc.exception.message,
         "Hub 'foo' already exists"
     )
     with self.assertRaises(Exception) as exc:
         g.unlink('foo', 'bar')
     self.assertEqual(
         exc.exception.message,
         "Hub 'foo' is not connected to node 'bar'"
     )
Beispiel #16
0
 def test_add_hub_link(self):
     g = GraphBackend().add_hub('foo', 'bar').link('foo', 'bar')
     self.assertTrue(g.is_hub('foo'))
     self.assertTrue(g.is_hub('bar'))
     self.assertEquals(g.links('foo'), set(['bar']))
     self.assertEquals(g.hub_links('foo'), set(['bar']))
     self.assertEquals(g.links('bar'), set())
     self.assertEquals(g.hub_links('bar'), set())
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'bar')
     self.assertEquals(
         exc.exception.message,
         "Hub 'foo' is already connected to node 'bar'"
     )
     g.link('bar', 'foo')
     self.assertEquals(g.links('foo'), set(['bar']))
     self.assertEquals(g.hub_links('foo'), set(['bar']))
     self.assertEquals(g.links('bar'), set(['foo']))
     self.assertEquals(g.hub_links('bar'), set(['foo']))
Beispiel #17
0
 def test_add_node_link(self):
     g = GraphBackend()
     g.add_hub('foo')
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'foo')
     self.assertEqual(exc.exception.message,
                      "Hub can't be linked to itself")
     g.link('foo', 'bar')
     self.assertFalse(g.is_hub('bar'))
     self.assertEqual(g.hubs(), set(['foo']))
     self.assertEqual(g.links('foo'), set(['bar']))
     self.assertEqual(g.hub_links('foo'), set(['bar']))
     with self.assertRaises(Exception) as exc:
         g.hub_links('bar')
     self.assertEqual(exc.exception.message, "Hub 'bar' does not exist")
     with self.assertRaises(Exception) as exc:
         g.link('foo', 'bar')
     self.assertEqual(exc.exception.message,
                      "Hub 'foo' is already connected to node 'bar'")
Beispiel #18
0
 def test_remove_hub_without_link(self):
     g = GraphBackend()
     with self.assertRaises(Exception) as exc:
         g.remove_hub('foo')
     self.assertEqual(
         exc.exception.message,
         "Hub 'foo' does not exist"
     )
     g.add_hub('foo')
     g.remove_hub('foo')
     # ensure hub is deleted
     self.assertFalse(g.is_hub('foo'))
     self.assertEqual(g.hubs(), set())
     # try to unlink a node from 'foo'
     with self.assertRaises(Exception) as exc:
         g.unlink('foo', 'bar')
     self.assertEqual(
         exc.exception.message,
         "Hub 'foo' does not exist"
     )