Ejemplo n.º 1
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']))
Ejemplo n.º 2
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']))
Ejemplo n.º 3
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']))
Ejemplo n.º 4
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'))
Ejemplo n.º 5
0
 def test_remove_node_link_with_several_hubs(self):
     g = GraphBackend()\
         .add_hub('h1').add_hub('h2')\
         .link('h1', 'node').link('h2', 'node')
     g.unlink('h1', 'node')
     self.assertEqual(g.hubs(), set(['h1', 'h2']))
     self.assertEqual(g.links('h1'), set())
     self.assertEqual(g.links('h2'), set(['node']))
     self.assertEqual(g.links('node'), set(['h2']))
Ejemplo n.º 6
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']))
Ejemplo n.º 7
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'))
Ejemplo n.º 8
0
 def test_remove_node_link_with_several_hubs(self):
     g = GraphBackend()\
         .add_hub('h1').add_hub('h2')\
         .link('h1', 'node').link('h2', 'node')
     g.unlink('h1', 'node')
     self.assertEqual(g.hubs(), set(['h1', 'h2']))
     self.assertEqual(g.links('h1'), set())
     self.assertEqual(g.links('h2'), set(['node']))
     self.assertEqual(g.links('node'), set(['h2']))
Ejemplo n.º 9
0
 def test_remove_hub_with_linked_hubs(self):
     g = GraphBackend().add_hub('h1', 'h2', 'h3')\
         .link('h1', 'h2').link('h1', 'h3').link('h2', 'h3')
     self.assertEqual(g.hub_links('h1'), set(['h2', 'h3']))
     self.assertEqual(g.hub_links('h2'), set(['h3']))
     self.assertEqual(g.hub_links('h3'), set())
     g.remove_hub('h1')  # remove node because nobody follows it
     self.assertFalse('h1' in g.hubs())
     with self.assertRaises(Exception) as exc:
         g.links('h1')
     self.assertEqual(exc.exception.message, "Unknown node 'h1'")
     self.assertEqual(g.links('h2'), set(['h3']))
     self.assertEqual(g.links('h3'), set())
     with self.assertRaises(Exception) as exc:
         g.hub_links('h1')
     self.assertEqual(exc.exception.message, "Hub 'h1' does not exist")
     g.unlink('h2', 'h3')
     self.assertTrue('h2' in g.hubs())
     self.assertTrue('h3' in g.hubs())
     self.assertEqual(g.links('h2'), set())
     self.assertEqual(g.links('h3'), set())
Ejemplo n.º 10
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")
Ejemplo n.º 11
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"
     )
Ejemplo n.º 12
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'"
     )
Ejemplo n.º 13
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']))
Ejemplo n.º 14
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']))
Ejemplo n.º 15
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())
Ejemplo n.º 16
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'")
Ejemplo n.º 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'"
     )
Ejemplo n.º 18
0
 def test_remove_hub_with_linked_hubs(self):
     g = GraphBackend().add_hub('h1', 'h2', 'h3')\
         .link('h1', 'h2').link('h1', 'h3').link('h2', 'h3')
     self.assertEqual(g.hub_links('h1'), set(['h2', 'h3']))
     self.assertEqual(g.hub_links('h2'), set(['h3']))
     self.assertEqual(g.hub_links('h3'), set())
     g.remove_hub('h1')  # remove node because nobody follows it
     self.assertFalse('h1' in g.hubs())
     with self.assertRaises(Exception) as exc:
         g.links('h1')
     self.assertEqual(exc.exception.message, "Unknown node 'h1'")
     self.assertEqual(g.links('h2'), set(['h3']))
     self.assertEqual(g.links('h3'), set())
     with self.assertRaises(Exception) as exc:
         g.hub_links('h1')
     self.assertEqual(exc.exception.message, "Hub 'h1' does not exist")
     g.unlink('h2', 'h3')
     self.assertTrue('h2' in g.hubs())
     self.assertTrue('h3' in g.hubs())
     self.assertEqual(g.links('h2'), set())
     self.assertEqual(g.links('h3'), set())
Ejemplo n.º 19
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())
Ejemplo n.º 20
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")
Ejemplo n.º 21
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")
Ejemplo n.º 22
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'")