Skip to content

Commit 67cd2e9

Browse files
committed
Added correct path to documentation.
Added a test case, which has multiple failures. This test case should be copied to linkml to get all the ifabsent functions fixed.
1 parent 3bdbfec commit 67cd2e9

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

linkml_model/model/schema/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ slots:
13291329
inherited: true
13301330
description: |-
13311331
function that provides a default value for the slot. Possible values for this slot are defined in
1332-
linkml_runtime.utils.ifabsent_functions.default_library:
1332+
linkml.utils.ifabsent_functions.default_library:
13331333
* [Tt]rue -- boolean True
13341334
* [Ff]alse -- boolean False
13351335
* bnode -- blank node identifier

tests/test_ifabsent.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import unittest
2+
from contextlib import redirect_stdout
3+
from io import StringIO
4+
5+
from linkml.generators.pythongen import PythonGenerator
6+
from linkml_runtime.utils.compile_python import compile_python
7+
8+
model_txt = """
9+
id: https://example.org/ifabsent
10+
name: ifabsent_test
11+
12+
prefixes:
13+
linkml: https://w3id.org/linkml/
14+
ex: https://example.org/ifabsent/
15+
default_prefix: ex
16+
default_range: string
17+
18+
imports:
19+
- linkml:types
20+
21+
slots:
22+
bool_true_slot:
23+
range: boolean
24+
ifabsent: true
25+
bool_false_slot:
26+
range: boolean
27+
ifabsent: False
28+
bnode_slot:
29+
ifabsent: bnode
30+
class_curie_slot:
31+
ifabsent: class_curie
32+
class_uri_slot:
33+
range: uri
34+
ifabsent: class_uri
35+
default_ns_slot:
36+
ifabsent: default_ns
37+
default_range_slot:
38+
ifabsent: default_range
39+
int_42_slot:
40+
range: integer
41+
ifabsent: int(42)
42+
int_0_slot:
43+
range: integer
44+
# a zero int doesn't work
45+
# ifabsent: int(0)
46+
neg_int_slot:
47+
range: integer
48+
ifabsent: int(-117243)
49+
slot_uri_slot:
50+
range: uri
51+
ifabsent: slot_uri
52+
slot_curie_slot:
53+
ifabsent: slot_curie
54+
string_slot:
55+
ifabsent: string(s1)
56+
mt_string_slot:
57+
ifabsent: string()
58+
59+
classes:
60+
HighClass:
61+
slots:
62+
- bool_true_slot
63+
- bool_false_slot
64+
- bnode_slot
65+
- class_curie_slot
66+
- class_uri_slot
67+
- default_ns_slot
68+
- default_range_slot
69+
- int_42_slot
70+
- int_0_slot
71+
- neg_int_slot
72+
- slot_uri_slot
73+
- slot_curie_slot
74+
- string_slot
75+
- mt_string_slot
76+
"""
77+
78+
class IfAbsentTestCase(unittest.TestCase):
79+
def test_ifabsent(self):
80+
m = compile_python(PythonGenerator(model_txt).serialize())
81+
sample = m.HighClass()
82+
self.assertEqual(sample.bool_true_slot, True)
83+
self.assertEqual(sample.bool_false_slot, False)
84+
print("class_curie_slot fails")
85+
# self.assertEqual(sample.class_curie_slot, m.HighClass.class_class_curie)
86+
print("class_uri_slot fails")
87+
# self.assertEqual(sample.class_uri_slot, m.HighClass.class_class_uri)
88+
print("default_ns fails")
89+
# self.assertEqual(sample.default_ns_slot, 'ex')
90+
print("default_range fails")
91+
# self.assertEqual(sample.default_range_slot, 'string')
92+
print("int(0) fails")
93+
# self.assertEqual(sample.int_0_slot, 0)
94+
self.assertEqual(sample.int_42_slot, 42)
95+
self.assertEqual(sample.neg_int_slot, -117243)
96+
print("slot_curie fails")
97+
# self.assertEqual(sample.slot_curie_slot, m.slots.slot_curie_slot.curie)
98+
print("slot_uri fails")
99+
# self.assertEqual(sample.slot_uri_slot, m.slots.slot_uri_slot.uri)
100+
self.assertEqual(sample.string_slot, "s1")
101+
self.assertEqual(sample.mt_string_slot, "")
102+
103+
104+
if __name__ == '__main__':
105+
unittest.main()

0 commit comments

Comments
 (0)