summaryrefslogtreecommitdiff
path: root/test/test_nodepickler.py
blob: 31a667da9cd9ab3ceae6cf44815543e22d604dec (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
import unittest
import pickle

from rdflib.term import Literal

from rdflib.store import NodePickler

# same as nt/more_literals.nt
cases = [
    'no quotes',
    "single ' quote",
    'double " quote',
    'triple """ quotes',
    'mixed "\'""" quotes',
    '"',
    "'",
    '"\'"',
    '\\',  # len 1
    '\\"',  # len 2
    '\\\\"',  # len 3
    '\\"\\',  # len 3
    '<a some="typical" html="content">here</a>',
]


class UtilTestCase(unittest.TestCase):

    def test_to_bits_from_bits_round_trip(self):
        np = NodePickler()

        a = Literal(u'''A test with a \\n (backslash n), "\u00a9" , and newline \n and a second line.
''')
        b = np.loads(np.dumps(a))
        self.assertEqual(a, b)

    def test_literal_cases(self):
        np = NodePickler()

        for l in cases:
            a = Literal(l)
            b = np.loads(np.dumps(a))
            self.assertEqual(a, b)

    def test_pickle(self):
        np = NodePickler()
        dump = pickle.dumps(np)
        np2 = pickle.loads(dump)
        self.assertEqual(np._ids, np2._ids)
        self.assertEqual(np._objects, np2._objects)


if __name__ == '__main__':
    unittest.main()