Merge branch 'cnfvar-deprecations'
[pyi2ncommon] / test / cnfvar / test_templates.py
diff --git a/test/cnfvar/test_templates.py b/test/cnfvar/test_templates.py
new file mode 100644 (file)
index 0000000..67d92fb
--- /dev/null
@@ -0,0 +1,59 @@
+# The software in this package is distributed under the GNU General
+# Public License version 2 (with a special exception described below).
+#
+# A copy of GNU General Public License (GPL) is included in this distribution,
+# in the file COPYING.GPL.
+#
+# As a special exception, if other files instantiate templates or use macros
+# or inline functions from this file, or you compile this file and link it
+# with other works to produce a work based on this file, this file
+# does not by itself cause the resulting work to be covered
+# by the GNU General Public License.
+#
+# However the source code for this file must still be made available
+# in accordance with section (3) of the GNU General Public License.
+#
+# This exception does not invalidate any other reasons why a work based
+# on this file might be covered by the GNU General Public License.
+#
+# Copyright (c) 2016-2022 Intra2net AG <info@intra2net.com>
+
+"""
+test_templates.py: unit tests for cnfvar/templates.py.
+
+Tests functions in cnfvar/templates.py
+
+For help see :py:mod:`unittest`
+"""
+
+import unittest
+from textwrap import dedent
+from types import SimpleNamespace
+from unittest.mock import patch, ANY
+
+from src.cnfvar import templates
+from src.cnfvar.model import Cnf
+
+
+class CnfTemplatesTest(unittest.TestCase):
+    """Test functions in cnfvar.templates."""
+
+    def test_template_calls(self):
+        """Tests calling each template to detect runtime breakage."""
+        template_cnf = templates.template("name", "value", instance=1, defaults={})
+        self.assertTrue(isinstance(template_cnf, Cnf))
+        attr_dict = templates.__dict__
+        for attr in attr_dict.keys():
+            if attr in ["Cnf", "CnfList"]:
+                continue
+            if attr == "template":
+                continue
+            if callable(attr_dict[attr]):
+                template_cnf = attr_dict[attr]("name", instance=1)
+                self.assertTrue(isinstance(template_cnf, Cnf))
+            elif attr.endswith("_defaults"):
+                self.assertTrue(isinstance(attr_dict[attr], dict))
+
+
+if __name__ == '__main__':
+    unittest.main()