Merge branch 'cnfvar-deprecations'
[pyi2ncommon] / test / cnfvar / test_templates.py
CommitLineData
1946dc1c
PD
1# The software in this package is distributed under the GNU General
2# Public License version 2 (with a special exception described below).
3#
4# A copy of GNU General Public License (GPL) is included in this distribution,
5# in the file COPYING.GPL.
6#
7# As a special exception, if other files instantiate templates or use macros
8# or inline functions from this file, or you compile this file and link it
9# with other works to produce a work based on this file, this file
10# does not by itself cause the resulting work to be covered
11# by the GNU General Public License.
12#
13# However the source code for this file must still be made available
14# in accordance with section (3) of the GNU General Public License.
15#
16# This exception does not invalidate any other reasons why a work based
17# on this file might be covered by the GNU General Public License.
18#
19# Copyright (c) 2016-2022 Intra2net AG <info@intra2net.com>
20
21"""
22test_templates.py: unit tests for cnfvar/templates.py.
23
24Tests functions in cnfvar/templates.py
25
26For help see :py:mod:`unittest`
27"""
28
29import unittest
30from textwrap import dedent
31from types import SimpleNamespace
32from unittest.mock import patch, ANY
33
34from src.cnfvar import templates
35from src.cnfvar.model import Cnf
36
37
38class CnfTemplatesTest(unittest.TestCase):
39 """Test functions in cnfvar.templates."""
40
41 def test_template_calls(self):
42 """Tests calling each template to detect runtime breakage."""
43 template_cnf = templates.template("name", "value", instance=1, defaults={})
44 self.assertTrue(isinstance(template_cnf, Cnf))
45 attr_dict = templates.__dict__
46 for attr in attr_dict.keys():
47 if attr in ["Cnf", "CnfList"]:
48 continue
49 if attr == "template":
50 continue
51 if callable(attr_dict[attr]):
52 template_cnf = attr_dict[attr]("name", instance=1)
53 self.assertTrue(isinstance(template_cnf, Cnf))
54 elif attr.endswith("_defaults"):
55 self.assertTrue(isinstance(attr_dict[attr], dict))
56
57
58if __name__ == '__main__':
59 unittest.main()