Пример #1
0
    def test_get_neighbourhood(self):
        """
        Test get_neighbourhood method.
        """

        # test empty result
        neighbourhood = self.manager.get_neighbourhood(ids='')
        self.assertFalse(neighbourhood)

        # test all vertices
        neighbourhood = set(self.manager.get_neighbourhood())
        self.assertEqual(len(neighbourhood), len(self.elts))

        # let's play with few vertices, edges and graphs
        v0, v1, v2 = Vertice(type='0'), Vertice(type='1'), Vertice(type='2')
        e0, e1, e2 = Edge(type='0'), Edge(type='1'), Edge(type='2')
        g0, g1, g2 = Graph(type='0'), Graph(type='1'), Graph(type='2')

        # connect v0 to v1
        e0.directed = True
        e0.sources = [v0.id, v1.id, v2.id]
        e0.targets = [g0.id, g1.id, g2.id]

        # save all elements
        v0.save(self.manager), v1.save(self.manager), v2.save(self.manager)
        e0.save(self.manager), e1.save(self.manager), e2.save(self.manager)
        g0.save(self.manager), g1.save(self.manager), g2.save(self.manager)

        # test ids
        neighbourhood = set(self.manager.get_neighbourhood(ids=v0.id))
        self.assertEqual(neighbourhood, {g0, g1, g2})

        # test sources
        neighbourhood = set(self.manager.get_neighbourhood(
            ids=v0.id, sources=True))
        self.assertEqual(neighbourhood, {g0, g1, g2, v0, v1, v2})

        # test not targets
        neighbourhood = set(self.manager.get_neighbourhood(
            ids=v0.id, targets=False))
        self.assertEqual(neighbourhood, set())

        # test not directed
        e0.directed = False
        e0.save(self.manager)
        neighbourhood = set(self.manager.get_neighbourhood(
            ids=v0.id))
        self.assertEqual(neighbourhood, {g0, g1, g2, v0, v1, v2})
Пример #2
0
    def test_delete_orphans(self):
        """
        Test if graph vertices exist after deleting a graph.
        """

        graph = Graph()
        vertice = Vertice()
        graph.add_elts(vertice)

        graph.save(manager=self.manager)

        vertice = self.manager.get_elts(vertice.id)
        self.assertIsNotNone(vertice)

        graph.delete(manager=self.manager)
        vertice = self.manager.get_elts(vertice.id)
        self.assertIsNone(vertice)
Пример #3
0
 def test_orphans(self):
     """
     Test get orphans method.
     """
     # check if no orphans exist
     orphans = self.manager.get_orphans()
     self.assertFalse(orphans)
     # generate self.count vertices and edges
     [Vertice().save(self.manager) for i in range(self.count)]
     [Edge().save(self.manager) for i in range(self.count)]
     # check if previous vertices and edges are orphans
     orphans = self.manager.get_orphans()
     self.assertEqual(len(orphans), 2 * self.count)
     # create a graph and add orphans to the graph
     graph = Graph()
     graph.add_elts(orphans)
     graph.save(manager=self.manager)
     # check if only the graph is an orphan
     orphans = self.manager.get_orphans()
     self.assertEqual(len(orphans), 1)
     # delete the graph and check if vertices and edges became orphans
     graph.delete(manager=self.manager, del_orphans=False)
     orphans = self.manager.get_orphans()
     self.assertEqual(len(orphans), 2 * self.count)