aboutsummaryrefslogtreecommitdiffstats
path: root/selftest
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-05-21 15:40:57 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2020-05-21 15:41:14 +0200
commitd79e7198043f8b2a2c8c4e5651d2ce323fd84963 (patch)
treea9076b3408090ae206cba2951aaf93269bda3b14 /selftest
parent27b609f4d354b05688da9e663167ae8b42d1af14 (diff)
schema: Allow objects registering their own schema types
Diffstat (limited to 'selftest')
-rw-r--r--selftest/schema_test/schema_case_06.conf29
-rw-r--r--selftest/schema_test/schema_test.ok17
-rwxr-xr-xselftest/schema_test/schema_test.py7
3 files changed, 53 insertions, 0 deletions
diff --git a/selftest/schema_test/schema_case_06.conf b/selftest/schema_test/schema_case_06.conf
new file mode 100644
index 0000000..ea7f45f
--- /dev/null
+++ b/selftest/schema_test/schema_case_06.conf
@@ -0,0 +1,29 @@
+schema:
+ handover:
+ threshold: 'uint'
+ myvar: 'test_type'
+ anothervar: 'another_type'
+
+tests:
+ - foobar:
+ prefix:
+ handover:
+ myvar: 'valid_value1'
+ anothervar: 'unique_val_ok'
+ threshold: 2
+ - foobar:
+ prefix:
+ handover:
+ myvar: 'valid_value2'
+ - foobar:
+ prefix:
+ handover:
+ threshold: 0
+ - foobar:
+ prefix:
+ handover:
+ myvar: 'invalid_val'
+ - foobar:
+ prefix:
+ handover:
+ anothervar: 'another_invalid_val'
diff --git a/selftest/schema_test/schema_test.ok b/selftest/schema_test/schema_test.ok
index 2c4cd6a..846caae 100644
--- a/selftest/schema_test/schema_test.ok
+++ b/selftest/schema_test/schema_test.ok
@@ -61,3 +61,20 @@ validating tests[6]
--- -: ERR: ValueError: config item is a list, should be 'str': 'foobar.prefix.hey.ho.letsgo[]'
Validation: Error
----------------------
+schema_case_06.conf:
+{'foobar.prefix.handover.anothervar': 'another_type',
+ 'foobar.prefix.handover.myvar': 'test_type',
+ 'foobar.prefix.handover.threshold': 'uint'}
+validating tests[0]
+Validation: OK
+validating tests[1]
+Validation: OK
+validating tests[2]
+Validation: OK
+validating tests[3]
+--- foobar.prefix.handover.myvar: ERR: ValueError: Invalid value 'invalid_val' for schema type 'test_type' (validator: test_validator)
+Validation: Error
+validating tests[4]
+--- foobar.prefix.handover.anothervar: ERR: ValueError: Invalid value 'another_invalid_val' for schema type 'another_type' (validator: <lambda>)
+Validation: Error
+----------------------
diff --git a/selftest/schema_test/schema_test.py b/selftest/schema_test/schema_test.py
index 3cf2799..bffa601 100755
--- a/selftest/schema_test/schema_test.py
+++ b/selftest/schema_test/schema_test.py
@@ -25,6 +25,13 @@ def get_case_list(dir):
li.append(f)
return sorted(li)
+def test_validator(val):
+ return val in ('valid_value1', 'valid_value2')
+
+schema.register_schema_types({'test_type': test_validator,
+ 'another_type': lambda val: val == 'unique_val_ok'})
+
+
print('==== Testing dynamically generated schemas ====')
for f in get_case_list(_prep.script_dir):
print('%s:' % f)