def setUp(self):
        """
        ConfigHandlerTests class setup

        Load graph from graph.tgf file
        """

        self.graph1 = read_tgf(self._gpf_graph)

        self.graph2 = read_tgf(self._gpf_graph)
        self.graph2.directed = True
        self.graph2.remove_nodes([1, 2, 3, 4, 5])

        self.graph3 = read_tgf(self._gpf_graph)
        self.graph3.directed = True
        self.graph3.remove_nodes([6, 7, 8, 9, 10, 'eleven'])
예제 #2
0
    def test_format_export(self):
        """
        Test export of format
        """

        tgf_file = os.path.join(FILEPATH, 'graph.tgf')
        graph = read_tgf(tgf_file)

        # Export graph as TGF to file
        tgf = write_tgf(graph)
        outfile = os.path.join(FILEPATH, 'test_export.tgf')
        with open(outfile, 'w') as otf:
            otf.write(tgf)
            self.tempfiles.append(outfile)

        self.assertTrue(os.path.isfile(outfile))

        # Import again and compare source graph
        graph1 = read_tgf(outfile)

        self.assertTrue(graph1 == graph)
예제 #3
0
    def test_format_import(self):
        """
        Test import of format
        """

        tgf_file = os.path.join(FILEPATH, 'graph.tgf')
        graph = read_tgf(tgf_file)

        # Default graph attributes set
        self.assertEqual(len(graph), 11)
        self.assertEqual(len(graph.edges), 11)
        self.assertEqual(graph.directed, False)
        self.assertEqual(graph_directionality(graph), 'directional')
        self.assertEqual(graph.root, None)
        self.assertTrue(isinstance(graph, Graph))

        # auto_nid is False, arbitrary node ID's supported
        self.assertTrue('eleven' in graph.nodes)
        self.assertTrue(10 in graph.nodes)
예제 #4
0
    def test_format_custom_import(self):
        """
        Test TGF import with custom Graph instance
        """

        # Graph axis class with custom nid ID's
        graph = GraphAxis()
        graph.data.auto_nid = False
        graph.directed = True

        tgf_file = os.path.join(FILEPATH, 'graph.tgf')
        graph = read_tgf(tgf_file, graph=graph)

        # Custom graph attributes set and string based node IDs supported
        self.assertEqual(len(graph), 11)
        self.assertEqual(len(graph.edges), 11)
        self.assertEqual(graph.directed, True)
        self.assertEqual(graph_directionality(graph), 'directional')
        self.assertTrue(isinstance(graph, GraphAxis))
        self.assertTrue('eleven' in graph.nodes)
예제 #5
0
    def setUp(self):
        """
        ConfigHandlerTests class setup

        Load graph from file and assign custom classes to labels and register
        with the ORM.
        """

        self.graph = read_tgf(self._gpf_graph)

        self.orm = GraphORM()
        self.orm.edge_mapping.add(ORMtestMo, lambda x: x.get('label') == 'mo')
        self.orm.edge_mapping.add(ORMtestBi, lambda x: x.get('label') == 'bi')
        self.orm.node_mapping.add(ORMtestTgf6, lambda x: x.get('key') == 'six')
        self.orm.node_mapping.add(
            ORMtestTgf9,
            lambda x: x.get('key') == 'nine' or x.get('ids') == 'edi')

        self.graph.orm = self.orm
        self.graph.nodes[6]['add'] = 6
        self.graph.nodes[6]['ids'] = 'edi'