summaryrefslogtreecommitdiff
path: root/test/test_memory_store.py
blob: f579250efd68f3b4f21d056fb22a73754b38b33f (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
import unittest
import rdflib

rdflib.plugin.register('Memory', rdflib.store.Store,
                       'rdflib.plugins.memory', 'Memory')


class StoreTestCase(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')