From 4902bac3a788a0acf40587316859da5439392f9e Mon Sep 17 00:00:00 2001 From: Edmond Chuc <37032744+edmondchuc@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:53:44 +1000 Subject: [PATCH] Add tests for pyoxigraph parse and serialize functions --- python/tests/test_io.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 python/tests/test_io.py diff --git a/python/tests/test_io.py b/python/tests/test_io.py new file mode 100644 index 00000000..d00c6d28 --- /dev/null +++ b/python/tests/test_io.py @@ -0,0 +1,44 @@ +import unittest +import io + +from pyoxigraph import * + + +class TestParse(unittest.TestCase): + def test_parse(self): + input = io.BytesIO(b'

"1" .') + result = list(parse(input, "text/turtle", base_iri="http://example.com/")) + + self.assertEqual( + result, + [ + Triple( + NamedNode("http://example.com/foo"), + NamedNode("http://example.com/p"), + Literal( + "1", + datatype=NamedNode("http://www.w3.org/2001/XMLSchema#string"), + ), + ) + ], + ) + + +class TestSerialize(unittest.TestCase): + def test_serialize(self): + output = io.BytesIO() + serialize( + [ + Triple( + NamedNode("http://example.com"), + NamedNode("http://example.com/p"), + Literal("1"), + ) + ], + output, + "text/turtle", + ) + + self.assertEqual( + output.getvalue(), b' "1" .\n' + )