Ejemplo n.º 1
0
    def test_numeric(self):

        graph = Graph()
        graph.load("tests/data/numeric_unsorted.ttl", format="turtle")
        ots = OrderedTurtleSerializer(graph)
        out = BytesIO()
        ots.serialize(out)
        out = "\n".join([x for x in out.getvalue().decode("utf-8").split("\n") if x.startswith("<")])

        ref = open("tests/data/numeric_sorted.ttl").read()
        ref = "\n".join([x for x in ref.split("\n") if x.startswith("<")])

        assert ref.strip() == out.strip()
Ejemplo n.º 2
0
    def test_custom_sorter(self):

        graph = Graph()
        graph.load("tests/data/group_unsorted.ttl", format="turtle")
        ots = OrderedTurtleSerializer(graph)

        ots.sorters = [("(.*?)([0-9]+)$", lambda x: self.xhash(x[0]) + int(x[1]))]

        out = BytesIO()
        ots.serialize(out)
        out = "\n".join([x for x in out.getvalue().decode("utf-8").split("\n") if x.startswith("<")])

        ref = open("tests/data/group_sorted.ttl").read()
        ref = "\n".join([x for x in ref.split("\n") if x.startswith("<")])

        assert ref.strip() == out.strip()
Ejemplo n.º 3
0
    def test_dewey_sorter(self):

        graph = Graph()
        graph.load("tests/data/dewey_unsorted.ttl", format="turtle")
        ots = OrderedTurtleSerializer(graph)

        ots.sorters = [
            ("/([0-9A-Z\-]+)\-\-([0-9.\-;:]+)/e", lambda x: "T{0}--{0}".format(x[0], x[1])),  # table numbers
            ("/([0-9.\-;:]+)/e", lambda x: "A" + x[0]),  # standard schedule numbers
        ]

        out = BytesIO()
        ots.serialize(out)
        out = "\n".join([x for x in out.getvalue().decode("utf-8").split("\n") if x.startswith("<")])

        ref = open("tests/data/dewey_sorted.ttl").read()
        ref = "\n".join([x for x in ref.split("\n") if x.startswith("<")])

        assert ref.strip() == out.strip()