예제 #1
0
    def test_import_from_path_loaded_edges_missing_properties_file(self):
        path = create_graph_mock_path()

        # deleted the edges properties file.
        os.remove(
            os.path.join(
                path,
                "edges",
                "knows",
                "0",
                "properties.json"
            )
        )

        graph = PersistentGraph(path)

        marko = graph.get_vertex(0)
        josh = graph.get_vertex(1)
        marko_josh = graph.get_edge(0)

        self.assertEqual(len(graph.edges), 1)
        self.assertEqual(marko_josh.head, marko)
        self.assertEqual(marko_josh.tail, josh)
        self.assertIsInstance(marko_josh, PersistentEdge)
        self.assertEqual(
            marko_josh.path,
            os.path.join(graph.edges_path, "knows", "0"),
        )
        self.assertDictEqual(marko_josh.properties, {})
예제 #2
0
    def test_import_from_path_loaded_edges_missing_properties_file(self):
        path = create_graph_mock_path()

        # deleted the edges properties file.
        os.remove(
            os.path.join(
                path,
                "edges",
                "knows",
                "0",
                "properties.json"
            )
        )

        graph = PersistentGraph(path)

        marko = graph.get_vertex(0)
        josh = graph.get_vertex(1)
        marko_josh = graph.get_edge(0)

        self.assertEqual(len(graph.edges), 1)
        self.assertEqual(marko_josh.head, marko)
        self.assertEqual(marko_josh.tail, josh)
        self.assertIsInstance(marko_josh, PersistentEdge)
        self.assertEqual(
            marko_josh.path,
            os.path.join(graph.edges_path, "knows", "0"),
        )
        self.assertDictEqual(marko_josh.properties, {})
예제 #3
0
 def test_import_with_vertices_missing_properties_file(self):
     path = create_graph_mock_path()
     os.remove(
         os.path.join(path, "vertices", "person", "0", "properties.json"))
     graph = PersistentGraph(path)
     vertex = graph.get_vertex(0)
     self.assertDictEqual(vertex.properties, {})
예제 #4
0
 def test_import_with_vertices_missing_properties_file(self):
     path = create_graph_mock_path()
     os.remove(
         os.path.join(
             path,
             "vertices",
             "person",
             "0",
             "properties.json"
         )
     )
     graph = PersistentGraph(path)
     vertex = graph.get_vertex(0)
     self.assertDictEqual(vertex.properties, {})
예제 #5
0
    def test_import_from_path_loaded_vertices(self):
        path = create_graph_mock_path()
        graph = PersistentGraph(path)

        self.assertEqual(len(graph.vertices), 2)

        # test marko was imported and has id 0
        marko = graph.get_vertex(0)
        self.assertIsInstance(marko, PersistentVertex)
        self.assertEqual(marko.path,
                         os.path.join(graph.vertices_path, "person", "0"))
        self.assertDictEqual(marko.properties, {"name": "Marko"})

        # test josh was imported and has id 1
        josh = graph.get_vertex(1)
        self.assertIsInstance(josh, PersistentVertex)
        self.assertEqual(josh.path,
                         os.path.join(graph.vertices_path, "person", "1"))
        self.assertDictEqual(josh.properties, {"name": "Josh"})

        # check that the next vertex has an id of 3
        spot = graph.add_vertex("dog", name="Spot")
        self.assertEqual(spot.ident, 2)
예제 #6
0
    def test_import_from_path_loaded_vertices(self):
        path = create_graph_mock_path()
        graph = PersistentGraph(path)

        self.assertEqual(len(graph.vertices), 2)

        # test marko was imported and has id 0
        marko = graph.get_vertex(0)
        self.assertIsInstance(marko, PersistentVertex)
        self.assertEqual(
            marko.path,
            os.path.join(graph.vertices_path, "person", "0")
        )
        self.assertDictEqual(
            marko.properties,
            {
                "name": "Marko"
            }
        )

        # test josh was imported and has id 1
        josh = graph.get_vertex(1)
        self.assertIsInstance(josh, PersistentVertex)
        self.assertEqual(
            josh.path,
            os.path.join(graph.vertices_path, "person", "1")
        )
        self.assertDictEqual(
            josh.properties,
            {
                "name": "Josh"
            }
        )

        # check that the next vertex has an id of 3
        spot = graph.add_vertex("dog", name="Spot")
        self.assertEqual(spot.ident, 2)