diff options
Diffstat (limited to 'bindings/python/test_serd.py')
-rw-r--r-- | bindings/python/test_serd.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/bindings/python/test_serd.py b/bindings/python/test_serd.py index 74f125fd..712c21e5 100644 --- a/bindings/python/test_serd.py +++ b/bindings/python/test_serd.py @@ -588,6 +588,26 @@ class StatementTests(unittest.TestCase): self.g = serd.uri("http://example.org/g") self.cursor = serd.Cursor("foo.ttl", 1, 0) + def testGet(self): + s, p, o, g = self.s, self.p, self.o, self.g + statement = serd.Statement(s, p, o, g, self.cursor) + + self.assertEqual(statement[serd.Field.SUBJECT], s) + self.assertEqual(statement[serd.Field.PREDICATE], p) + self.assertEqual(statement[serd.Field.OBJECT], o) + self.assertEqual(statement[serd.Field.GRAPH], g) + + self.assertEqual(statement[0], s) + self.assertEqual(statement[1], p) + self.assertEqual(statement[2], o) + self.assertEqual(statement[3], g) + + with self.assertRaises(IndexError): + statement[-1] + + with self.assertRaises(IndexError): + statement[4] + def testAllFields(self): s, p, o, g = self.s, self.p, self.o, self.g statement = serd.Statement(s, p, o, g, self.cursor) @@ -806,6 +826,47 @@ class CursorTests(unittest.TestCase): ) +class EventTests(unittest.TestCase): + def testRepr(self): + base = serd.uri("http://example.org/base") + ns = serd.uri("http://example.org/ns") + + self.assertEqual( + repr(serd.Event.base(base)), + 'serd.Event.base("http://example.org/base")', + ) + + self.assertEqual( + repr(serd.Event.prefix("eg", ns)), + 'serd.Event.prefix("eg", "http://example.org/ns")', + ) + + s = serd.blank("s") + p = serd.uri("http://example.org/p") + o = serd.uri("http://example.org/o") + g = serd.uri("http://example.org/g") + statement = serd.Statement(s, p, o, g) + + self.assertEqual( + repr(serd.Event.statement(statement)), + 'serd.Event.statement(serd.Statement(serd.blank("s"), serd.uri("http://example.org/p"), serd.uri("http://example.org/o"), serd.uri("http://example.org/g")))', + ) + + self.assertEqual( + repr( + serd.Event.statement( + statement, + serd.StatementFlags.EMPTY_S | serd.StatementFlags.ANON_O, + ) + ), + 'serd.Event.statement(serd.Statement(serd.blank("s"), serd.uri("http://example.org/p"), serd.uri("http://example.org/o"), serd.uri("http://example.org/g")), serd.StatementFlags.EMPTY_S | serd.StatementFlags.ANON_O)', + ) + + self.assertEqual( + repr(serd.Event.end(s)), 'serd.Event.end(serd.blank("s"))' + ) + + class ReaderTests(unittest.TestCase): def setUp(self): self.world = serd.World() |