Browse Source

Merge branch 'no_python' of scossu/lsup_rdf into master

scossu 1 day ago
parent
commit
5a622a0100
4 changed files with 12 additions and 123 deletions
  1. 6 1
      include/core.h
  2. 1 2
      src/graph.c
  3. 5 0
      src/term.c
  4. 0 120
      test/cpython_test.py

+ 6 - 1
include/core.h

@@ -101,12 +101,15 @@ typedef int LSUP_rc;
 #define LSUP_END            88803
 
 /** @brief Conflict warning.
+ *
  * An attempt to create or update a resource was made, but the resource existed
  * with a different form or value. The caller should find the value of the
  * existing resource to be different than the one that was attempted to store.
  * If this is returned from the iteration of multiple updates, it means that
  * other resources in the loop may have changed state and the operation as a
  * whole completed successfully.
+ *
+ * The error-level counterpart to this is #LSUP_CONFLICT_ERR.
  */
 #define LSUP_CONFLICT       88804
 
@@ -148,10 +151,12 @@ typedef int LSUP_rc;
  * is returned from the iteration of multiple updates, it means that the
  * operation has been interrupted and any state change within the loop prior to
  * the error has been rolled back.
+ *
+ * The warning-level counterpart to this is #LSUP_CONFLICT.
  */
 #define LSUP_CONFLICT_ERR   -88891
 
-/// Error while handling environment setup.
+/// Error while handling environment setup; or environment not initialized.
 #define LSUP_ENV_ERR        -88890
 ///@}  END defgroup return
 

+ 1 - 2
src/graph.c

@@ -248,6 +248,7 @@ LSUP_rc
 LSUP_graph_set_uri (LSUP_Graph *gr, const char *uri_str)
 {
     LSUP_rc rc = LSUP_OK;
+    LSUP_Buffer *old_sc = NULL, *new_sc = NULL;
 
     LSUP_Term *uri = LSUP_iriref_new (uri_str, gr->nsm);
     if (UNLIKELY (!uri)) {
@@ -256,8 +257,6 @@ LSUP_graph_set_uri (LSUP_Graph *gr, const char *uri_str)
     }
 
     // Update context for triples in the graph.
-    LSUP_Buffer *old_sc = NULL, *new_sc = NULL;
-
     if (gr->store->sif->features & LSUP_STORE_CTX) {
         old_sc = LSUP_term_serialize (gr->uri);
         new_sc = LSUP_term_serialize (uri);

+ 5 - 0
src/term.c

@@ -751,6 +751,11 @@ term_init (
         LSUP_Term *term, LSUP_TermType type,
         const char *data, void *metadata)
 {
+    // Exit early if environment is not initialized.
+    // EXCEPT for IRIRef which is used inside of LSUP_init().
+    if (!LSUP_IS_INIT && type != LSUP_TERM_IRIREF)
+        return LSUP_ENV_ERR;
+
     // Undefined type. Make quick work of it.
     if (type == LSUP_TERM_UNDEFINED) {
         term->type = type;

+ 0 - 120
test/cpython_test.py

@@ -1,120 +0,0 @@
-import unittest
-
-from os import path
-
-from lsup_rdf import env_init, term, triple, graph
-from lsup_rdf.term import IRIRef, Literal, BNode
-
-TEST_DIR = path.realpath(path.dirname(__file__))
-
-
-class TestTerm(unittest.TestCase):
-    def setUp(self):
-        self.s1 = IRIRef("urn:s:1")
-        self.p1 = IRIRef("urn:p:1")
-        self.o1 = IRIRef("urn:o:1")
-        self.s2 = IRIRef("urn:s:2")
-        self.p2 = IRIRef("urn:p:2")
-        self.o2 = IRIRef("urn:o:2")
-        self.s3 = IRIRef("urn:s:3")
-        self.p3 = IRIRef("urn:p:3")
-        self.o3 = IRIRef("urn:o:3")
-
-        self.t1 = triple.Triple(self.s1, self.p1, self.o1)
-        self.t2 = triple.Triple(self.s2, self.p2, self.o2)
-        self.t3 = triple.Triple(self.s3, self.p3, self.o3)
-        self.t4 = triple.Triple(self.s1, self.p1, self.o1)
-        self.t5 = triple.Triple(self.s1, self.p2, self.o1)
-
-    def test_iriref(self):
-        uri = IRIRef("urn:s:1")
-
-        self.assertTrue(isinstance(uri, term.Term))
-        self.assertEqual(uri.data, 'urn:s:1')
-        self.assertEqual(uri._type, term.TERM_IRIREF)
-        self.assertFalse(hasattr(uri, 'datatype'))
-        self.assertFalse(hasattr(uri, 'lang'))
-
-    def test_literal(self):
-        lit = Literal('Hello')
-
-        self.assertTrue(isinstance(lit, term.Term))
-        self.assertEqual(lit.data, 'Hello')
-        self.assertEqual(lit._type, term.TERM_LITERAL)
-        self.assertEqual(
-                lit.datatype.data, 'http://www.w3.org/2001/XMLSchema#string')
-        self.assertTrue(lit.lang is None)
-
-    def test_lt_literal(self):
-        lt_lit = Literal('Hola', lang='es-ES')
-
-        self.assertTrue(isinstance(lt_lit, term.Term))
-        self.assertEqual(lt_lit.data, 'Hola')
-        self.assertEqual(lt_lit._type, term.TERM_LT_LITERAL)
-        self.assertEqual(
-            lt_lit.datatype.data, 'http://www.w3.org/2001/XMLSchema#string'
-        )
-        self.assertEqual(lt_lit.lang, 'es-ES')
-
-    def test_bnode(self):
-        bn = BNode('1234')
-
-        self.assertTrue(isinstance(bn, term.Term))
-        self.assertEqual(bn.data, '1234')
-        self.assertEqual(bn._type, term.TERM_BNODE)
-        self.assertFalse(hasattr(bn, 'datatype'))
-        self.assertFalse(hasattr(bn, 'lang'))
-
-    def test_graph(self):
-        gr = graph.Graph(graph.STORE_HTABLE)
-        gr.uri = term.Term(term.TERM_IRIREF, 'urn:c:1')
-
-        self.assertEqual(gr.uri, 'urn:c:1')
-
-    def test_graph_ops(self):
-        gr = graph.Graph(graph.STORE_HTABLE)
-
-        print('Adding triples.')
-        gr.add([self.t1, self.t2])
-
-        self.assertEqual(len(gr), 2)
-        self.assertTrue(self.t1 in gr)
-        self.assertTrue(self.t2 in gr)
-        self.assertFalse(self.t3 in gr)
-        self.assertTrue(self.t4 in gr)
-
-        gr.remove(self.s1, None, None)
-
-        self.assertFalse(self.t1 in gr)
-        self.assertTrue(self.t2 in gr)
-
-        print('Encoded NT:')
-        for line in gr.to_rdf('nt'):
-            print(line)
-
-    def test_copy(self):
-        gr1 = graph.Graph(graph.STORE_HTABLE)
-        gr1.add([self.t1, self.t2, self.t3, self.t5])
-
-        gr2 = graph.Graph(graph.STORE_HTABLE)
-
-        gr1.copy(gr2, self.s1, None, None)
-
-        self.assertTrue(self.t1 in gr2)
-        self.assertTrue(self.t2 not in gr2)
-        self.assertTrue(self.t3 not in gr2)
-        self.assertTrue(self.t4 in gr2)
-        self.assertTrue(self.t5 in gr2)
-
-    def test_deserialize(self):
-        print('From file.')
-        with open(path.join(TEST_DIR, 'assets', 'test.nt'), 'rb') as fh:
-            gr2 = graph.Graph.from_rdf(fh, 'nt')
-
-        self.assertTrue(self.t1 in gr2)
-        self.assertTrue(self.t2 in gr2)
-
-
-if __name__ == '__main__':
-    env_init()
-    unittest.main()