File: test_memory_store.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 (59 lines) | stat: -rw-r--r-- 2,094 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import unittest
import rdflib

rdflib.plugin.register(
    "SimpleMemory", rdflib.store.Store, "rdflib.plugins.stores.memory", "SimpleMemory"
)
rdflib.plugin.register(
    "Memory", rdflib.store.Store, "rdflib.plugins.stores.memory", "Memory"
)


class SimpleStoreTestCase(unittest.TestCase):
    def test_memory_store(self):
        g = rdflib.Graph("SimpleMemory")
        subj1 = rdflib.URIRef("http://example.org/foo#bar1")
        pred1 = rdflib.URIRef("http://example.org/foo#bar2")
        obj1 = rdflib.URIRef("http://example.org/foo#bar3")
        triple1 = (subj1, pred1, obj1)
        triple2 = (
            subj1,
            rdflib.URIRef("http://example.org/foo#bar4"),
            rdflib.URIRef("http://example.org/foo#bar5"),
        )
        g.add(triple1)
        self.assertTrue(len(g) == 1)
        g.add(triple2)
        self.assertTrue(len(list(g.triples((subj1, None, None)))) == 2)
        self.assertTrue(len(list(g.triples((None, pred1, None)))) == 1)
        self.assertTrue(len(list(g.triples((None, None, obj1)))) == 1)
        g.remove(triple1)
        self.assertTrue(len(g) == 1)
        g.serialize()


class MemoryStoreTestCase(unittest.TestCase):
    def test_memory_store(self):
        g = rdflib.Graph("Memory")
        subj1 = rdflib.URIRef("http://example.org/foo#bar1")
        pred1 = rdflib.URIRef("http://example.org/foo#bar2")
        obj1 = rdflib.URIRef("http://example.org/foo#bar3")
        triple1 = (subj1, pred1, obj1)
        triple2 = (
            subj1,
            rdflib.URIRef("http://example.org/foo#bar4"),
            rdflib.URIRef("http://example.org/foo#bar5"),
        )
        g.add(triple1)
        self.assertTrue(len(g) == 1)
        g.add(triple2)
        self.assertTrue(len(list(g.triples((subj1, None, None)))) == 2)
        self.assertTrue(len(list(g.triples((None, pred1, None)))) == 1)
        self.assertTrue(len(list(g.triples((None, None, obj1)))) == 1)
        g.remove(triple1)
        self.assertTrue(len(g) == 1)
        g.serialize()


if __name__ == "__main__":
    unittest.main(defaultTest="test_suite")