File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99from pathlib import Path
1010from typing import TextIO
1111
12- from pydantic import BaseModel
12+ from pydantic import BaseModel , ConfigDict
1313from typing_extensions import Self
1414
1515from .api import Reference
2424class Triple (BaseModel ):
2525 """A model for a triple of subject-predicate-object triple."""
2626
27+ model_config = ConfigDict (frozen = True )
28+
2729 subject : Reference
2830 predicate : Reference
2931 object : Reference
3032
33+ def as_curies (self ) -> tuple [str , str , str ]:
34+ """Get a three-tuple of strings representing this triple."""
35+ return self .subject .curie , self .predicate .curie , self .object .curie
36+
3137 @classmethod
3238 def from_curies (
3339 cls ,
Original file line number Diff line number Diff line change 55import unittest
66from pathlib import Path
77
8- from curies import Triple
8+ import pydantic
9+
10+ from curies import Reference , Triple
911from curies .triples import read_triples , write_triples
1012
13+ T1 = Triple .from_curies ("a:1" , "a:2" , "a:3" )
14+ T2 = Triple .from_curies ("a:1" , "a:2" , "a:4" )
15+
1116
1217class TestTriples (unittest .TestCase ):
1318 """Test triples."""
1419
20+ def test_immutable (self ) -> None :
21+ """Test immutable."""
22+ with self .assertRaises (pydantic .ValidationError ):
23+ T1 .subject = Reference .from_curie ("b:1" )
24+
25+ def test_as_curies (self ) -> None :
26+ """Test stringifying."""
27+ self .assertEqual (
28+ ("a:1" , "a:2" , "a:3" ),
29+ T1 .as_curies (),
30+ )
31+
1532 def test_roundtrip (self ) -> None :
1633 """Test roundtrip."""
17- triples = [
18- Triple .from_curies ("a:1" , "a:2" , "a:3" ),
19- Triple .from_curies ("a:1" , "a:2" , "a:4" ),
20- ]
34+ triples = [T1 , T2 ]
2135 with tempfile .TemporaryDirectory () as directory :
2236 paths = [
2337 Path (directory ).joinpath ("test.tsv.gz" ),
You can’t perform that action at this time.
0 commit comments