Skip to content

Commit 6a9f3f7

Browse files
committed
[test/validation] Add prop values cardinality test
1 parent 89c8538 commit 6a9f3f7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/test_validation.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,49 @@ def assertError(self, res, err, filter_rep=True, filter_map=False):
4141
return
4242
self.assertEqual(errs, err)
4343

44+
def test_property_values_cardinality(self):
45+
doc = odml.Document()
46+
sec = odml.Section(name="sec", type="sec_type", parent=doc)
47+
48+
# Test no caught warning on empty cardinality
49+
prop = odml.Property(name="prop_empty_cardinality", values=[1, 2, 3, 4], parent=sec)
50+
# Check that the current property is not in the list of validation warnings or errors
51+
for err in validate(doc).errors:
52+
self.assertNotEqual(err.obj.id, prop.id)
53+
54+
# Test no warning on valid cardinality
55+
prop = odml.Property(name="prop_valid_cardinality", values=[1, 2, 3, 4],
56+
val_cardinality=(2, 10), parent=sec)
57+
for err in validate(doc).errors:
58+
self.assertNotEqual(err.obj.id, prop.id)
59+
60+
# Test minimum value cardinality validation
61+
test_val = [1, 2, 3]
62+
test_card = 2
63+
64+
prop = odml.Property(name="prop_invalid_max_val", values=test_val,
65+
val_cardinality=test_card, parent=sec)
66+
67+
test_msg_base = "Property values cardinality violated"
68+
test_msg = "%s (maximum %s values, %s found)" % (test_msg_base, test_card, len(prop.values))
69+
for err in validate(doc).errors:
70+
if err.obj.id == prop.id:
71+
self.assertFalse(err.is_error)
72+
self.assertIn(test_msg, err.msg)
73+
74+
# Test maximum value cardinality validation
75+
test_val = "I am a nice text to test"
76+
test_card = (4, None)
77+
78+
prop = odml.Property(name="prop_invalid_min_val", values=test_val,
79+
val_cardinality=test_card, parent=sec)
80+
81+
test_msg = "%s (minimum %s values, %s found)" % (test_msg_base, test_card[0], len(prop.values))
82+
for err in validate(doc).errors:
83+
if err.obj.id == prop.id:
84+
self.assertFalse(err.is_error)
85+
self.assertIn(test_msg, err.msg)
86+
4487
def test_section_type(self):
4588
doc = samplefile.parse("""s1[undefined]""")
4689
res = validate(doc)

0 commit comments

Comments
 (0)