aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py7
-rw-r--r--tests/test_something.py39
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e8b0db2
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1,7 @@
+import unittest
+
+
+def all_tests():
+ test_loader = unittest.TestLoader()
+ test_suite = test_loader.discover('tests', pattern='test_*.py')
+ return test_suite
diff --git a/tests/test_something.py b/tests/test_something.py
new file mode 100644
index 0000000..8091f46
--- /dev/null
+++ b/tests/test_something.py
@@ -0,0 +1,39 @@
+import json
+from unittest import TestCase
+
+from configlib.model_impl import BaseConfig
+
+
+class Yeeah(object):
+ a: int
+
+
+class SomeConfig(BaseConfig):
+ something: str
+ ye: Yeeah
+
+
+test_dict = {
+ 'something': 'hmm',
+ 'ye': {
+ 'a': 1
+ }
+}
+
+
+def verify_test_dict(conf):
+ assert conf.something == 'hmm'
+ assert isinstance(conf, SomeConfig)
+ assert conf.ye.a == 1
+ assert isinstance(conf.ye, Yeeah)
+
+
+class TestSomething(TestCase):
+
+ def test_yeah(self):
+ conf: SomeConfig = SomeConfig.parse_dict(test_dict)
+ verify_test_dict(conf)
+
+ def test_text(self):
+ conf: SomeConfig = SomeConfig.loads(json.dumps(test_dict))
+ verify_test_dict(conf)