Ejemplo n.º 1
0
    def test_get_media_graph(self):
        db = self.db

        media = get_media_network(db=db,
                                  timespans_id=self.timespan['timespans_id'])
        graph = get_media_graph(media=media)

        assert len(graph.nodes) == len(self.all_media)
        assert len(graph.edges) == len(self.connected_media) - 1

        media_id_attributes = nx.get_node_attributes(graph, 'media_id').items()
        assert len(media_id_attributes) == len(self.all_media)
        for (node, media_id) in media_id_attributes:
            assert node == media_id

        name_attributes = nx.get_node_attributes(graph, 'name').items()
        assert len(name_attributes) == len(self.all_media)
        for (node, name) in name_attributes:
            assert len(name) > 0

        media_inlink_count_attributes = nx.get_node_attributes(
            graph, 'media_inlink_count').items()
        assert len(media_inlink_count_attributes) == len(self.all_media)
        for (node, count) in media_inlink_count_attributes:
            assert count > 0
Ejemplo n.º 2
0
    def test_get_media_network(self):
        db = self.db

        got_media = get_media_network(
            db=db, timespans_id=self.timespan['timespans_id'])

        assert len(got_media) == len(self.all_media)

        for m in got_media:
            assert m['media_id'] in [m['media_id'] for m in self.all_media]
    def test_remove_platforms_from_graph(self):
        db = self.db

        media = get_media_network(db=db, timespans_id=self.timespan['timespans_id'])
        graph = get_media_graph(media=media)

        graph = remove_platforms_from_graph(graph=graph, platform_media_ids=[self.disconnected_media[0]['media_id'], ])

        assert len(graph.nodes) == len(self.all_media) - 1

        assert self.disconnected_media[0]['media_id'] not in graph.nodes
Ejemplo n.º 4
0
    def test_get_giant_component(self):
        db = self.db

        media = get_media_network(db=db,
                                  timespans_id=self.timespan['timespans_id'])
        graph = get_media_graph(media=media)

        assert len(graph.nodes) == len(self.all_media)

        graph = get_giant_component(graph=graph)

        assert len(graph.nodes) == len(self.connected_media)
    def test_prune_graph_by_distance(self):
        db = self.db

        media = get_media_network(db=db,
                                  timespans_id=self.timespan['timespans_id'])
        graph = get_media_graph(media=media)

        assert len(graph.nodes) == len(self.all_media)

        run_fa2_layout(graph=graph, memory_limit_mb=512)

        graph = prune_graph_by_distance(graph=graph)

        assert len(graph.nodes) == len(self.connected_media)