Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/lhs_evaluation_test.py @ 1605:449746d1598f
WIP move evaluation to new file
author | drewp@bigasterisk.com |
---|---|
date | Mon, 06 Sep 2021 01:13:55 -0700 |
parents | |
children | 4fd9fdfcf16a |
comparison
equal
deleted
inserted
replaced
1604:e78464befd24 | 1605:449746d1598f |
---|---|
1 import unittest | |
2 | |
3 from rdflib import RDF, ConjunctiveGraph, Literal, Namespace | |
4 from rdflib.parser import StringInputSource | |
5 | |
6 from lhs_evaluation import _parseList | |
7 | |
8 EX = Namespace('http://example.com/') | |
9 | |
10 | |
11 def N3(txt: str): | |
12 g = ConjunctiveGraph() | |
13 prefix = """ | |
14 @prefix : <http://example.com/> . | |
15 """ | |
16 g.parse(StringInputSource((prefix + txt).encode('utf8')), format='n3') | |
17 return g | |
18 | |
19 | |
20 class TestParseList(unittest.TestCase): | |
21 | |
22 def test0Elements(self): | |
23 g = N3(":a :b () .") | |
24 bn = g.value(EX['a'], EX['b']) | |
25 elems, used = _parseList(g, bn) | |
26 self.assertEqual(elems, []) | |
27 self.assertFalse(used) | |
28 | |
29 def test1Element(self): | |
30 g = N3(":a :b (0) .") | |
31 bn = g.value(EX['a'], EX['b']) | |
32 elems, used = _parseList(g, bn) | |
33 self.assertEqual(elems, [Literal(0)]) | |
34 used = sorted(used) | |
35 self.assertEqual(used, [ | |
36 (bn, RDF.first, Literal(0)), | |
37 (bn, RDF.rest, RDF.nil), | |
38 ]) |