File: test_turtle_sort_issue613.py

package info (click to toggle)
rdflib 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 38,248 kB
  • sloc: python: 39,216; sh: 153; makefile: 110
file content (40 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import rdflib

"""
In py3, some objects are not comparable. When the turtle serializer tries to sort them everything breaks.

* Timezone aware datetime objects and "naive" datetime objects are not comparable

https://github.com/RDFLib/rdflib/issues/648
https://github.com/RDFLib/rdflib/issues/613

* DocumentFragment
https://github.com/RDFLib/rdflib/issues/676

"""


def test_sort_dates():

    g = rdflib.Graph()
    y = """@prefix ex: <http://ex.org> .
ex:X ex:p "2016-01-01T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime>, "2016-01-01T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . """

    p = g.parse(data=y, format="turtle")
    p.serialize(format="turtle")


def test_sort_docfrag():

    g = rdflib.Graph()
    y = """@prefix ex: <http://ex.org> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ex:X ex:p "<h1>hi</h1>"^^rdf:HTML, "<h1>ho</h1>"^^rdf:HTML  . """

    p = g.parse(data=y, format="turtle")
    p.serialize(format="turtle")


if __name__ == "__main__":

    test_sort_docfrag()