54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
# dabmodel (c) by chacha
|
|
#
|
|
# dabmodel is licensed under a
|
|
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
|
|
#
|
|
# You should have received a copy of the license along with this
|
|
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
|
|
|
|
import unittest
|
|
from typing import Annotated, Union, Optional
|
|
import sys
|
|
import subprocess
|
|
from os import chdir, environ
|
|
from pathlib import Path
|
|
|
|
print(__name__)
|
|
print(__package__)
|
|
|
|
from src import dabmodel as dm
|
|
|
|
testdir_path = Path(__file__).parent.resolve()
|
|
chdir(testdir_path.parent.resolve())
|
|
|
|
|
|
class AnnotationsWalkerTest(unittest.TestCase):
|
|
def setUp(self):
|
|
print("\n->", unittest.TestCase.id(self))
|
|
|
|
def test_validate(self):
|
|
ann = dict[int, list[int]] | dict[int, list[int | str]]
|
|
val = {1: [2], 2: ["a", [1]]}
|
|
|
|
res = dm.tools.AnnotationWalker(ann, (dm.tools.HorizontalValidationTrigger(val),))
|
|
res.run()
|
|
|
|
def test_simple(self):
|
|
print(isinstance(None, type(None)))
|
|
print("\n== From OBJs ==")
|
|
res = dm.tools.AnnotationWalker(Annotated[Optional[dict[int, list[str]]], "comment"], (dm.tools.LAMSchemaValidation(),))
|
|
print(f"res={res.run()}")
|
|
|
|
print("\n== From STRING ==")
|
|
res = dm.tools.AnnotationWalker('Annotated[Optional[dict[int, list[str]]], "comment"]', (dm.tools.LAMSchemaValidation(),))
|
|
print(f"res={res.run()}")
|
|
|
|
res = dm.tools.AnnotationWalker(Annotated[Optional[dict[int, list[None]]], "comment"], (dm.tools.LAMSchemaValidation(),))
|
|
print(f"res={res.run()}")
|
|
|
|
|
|
# ---------- main ----------
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|