File: test_shacl.py

package info (click to toggle)
rudof 0.1.146%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 10,048 kB
  • sloc: python: 1,288; makefile: 32; sh: 1
file content (50 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import unittest

from pyrudof import Rudof, RudofConfig

class TestShacl(unittest.TestCase):
    def test_ok(self) -> None:
        rudof = Rudof(RudofConfig())
        data = """
        prefix : <http://example.org/>
        prefix sh:     <http://www.w3.org/ns/shacl#> 
        prefix xsd:    <http://www.w3.org/2001/XMLSchema#> 
                        
        :Person a sh:NodeShape; sh:targetNode :ok ;
         sh:property [                  
          sh:path     :name ; 
           sh:minCount 1; 
           sh:maxCount 1;
           sh:datatype xsd:string ;
        ] .
        :ok :name "alice" .          
        """
        rudof.read_data_str(data)
        result = rudof.validate_shacl()
        print(result.show())
        self.assertTrue(result.conforms())

    def test_ko(self) -> None:
        rudof = Rudof(RudofConfig())
        data = """
        prefix : <http://example.org/>
        prefix sh:     <http://www.w3.org/ns/shacl#> 
        prefix xsd:    <http://www.w3.org/2001/XMLSchema#> 
                        
        :Person a sh:NodeShape; sh:targetNode :ko ;
         sh:property [                  
          sh:path     :name ; 
           sh:minCount 1; 
           sh:maxCount 1;
           sh:datatype xsd:string ;
        ] .
        :ko :name 23 .    
        """
        rudof.read_data_str(data)
        result = rudof.validate_shacl()
        print(result.show())
        self.assertFalse(result.conforms())


if __name__ == "__main__":
    unittest.main()