summaryrefslogtreecommitdiff
path: root/tests/test_types.py
diff options
context:
space:
mode:
authorJohan Fleury <jfleury@arcaik.net>2018-10-08 12:58:12 -0400
committerJohan Fleury <jfleury@arcaik.net>2018-10-08 12:58:12 -0400
commit735c78d3ecb695dd16cb37879880f522c4b29c72 (patch)
tree8bfb2ecbd0f03730efa1540cc65d8490b67e8ddd /tests/test_types.py
Import upstream version 1.7.0
Diffstat (limited to 'tests/test_types.py')
-rw-r--r--tests/test_types.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test_types.py b/tests/test_types.py
new file mode 100644
index 0000000..de7db87
--- /dev/null
+++ b/tests/test_types.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+
+""" Unit test for pyKwalify - Rule """
+
+# python std lib
+import unittest
+
+# pykwalify imports
+from pykwalify import types
+
+
+class TestTypes(unittest.TestCase):
+
+ def test_types(self):
+ """
+ Test that all type helper methods works correctly
+ """
+ assert types.type_class("str") == str
+
+ assert types.is_builtin_type("str")
+
+ assert types.is_collection_type("map")
+ assert types.is_collection_type("seq")
+ assert not types.is_collection_type("str")
+
+ assert types.is_scalar_type("str")
+ assert not types.is_scalar_type("seq")
+ assert not types.is_scalar_type("map")
+
+ assert types.is_collection([])
+ assert types.is_collection({})
+ assert not types.is_collection("foo")
+
+ assert types.is_scalar("")
+ assert types.is_scalar(True)
+ assert not types.is_scalar([])
+
+ assert types.is_correct_type("", str)
+ assert types.is_correct_type({}, dict)
+
+ assert types.is_string("foo")
+ assert not types.is_string([])
+
+ assert types.is_int(1)
+ assert not types.is_int("foo")
+
+ assert types.is_bool(True)
+ assert not types.is_bool(1)
+ assert not types.is_bool("true")
+
+ assert types.is_float(1.0)
+ assert not types.is_float("foo")
+
+ assert types.is_number(1)
+ assert types.is_number(1.0)
+ assert not types.is_number("foo")
+
+ assert types.is_text("foo")
+ assert types.is_text(1)
+ assert types.is_text(1.0)
+ assert not types.is_text([])
+ assert not types.is_text(True)
+
+ assert types.is_any("foo")
+ assert types.is_any(True)
+ assert types.is_any(1)
+ assert types.is_any(1.0)
+ assert types.is_any({})
+ assert types.is_any([])
+
+ assert types.is_enum("foo")
+ assert not types.is_enum(1)
+
+ assert types.is_none(None)
+ assert not types.is_none("foo")