summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/helper.py4
-rw-r--r--src/tests/test_config_diff.py2
-rw-r--r--src/tests/test_config_parser.py2
-rw-r--r--src/tests/test_configd_inspect.py105
-rw-r--r--src/tests/test_configverify.py4
-rw-r--r--src/tests/test_dependency_graph.py4
-rw-r--r--src/tests/test_dict_search.py4
-rw-r--r--[-rwxr-xr-x]src/tests/test_find_device_file.py4
-rw-r--r--src/tests/test_initial_setup.py2
-rw-r--r--src/tests/test_op_mode.py5
-rw-r--r--src/tests/test_task_scheduler.py4
-rw-r--r--src/tests/test_template.py2
-rw-r--r--src/tests/test_utils.py4
-rw-r--r--src/tests/test_utils_network.py7
14 files changed, 114 insertions, 39 deletions
diff --git a/src/tests/helper.py b/src/tests/helper.py
index f7033148a..cc0710494 100644
--- a/src/tests/helper.py
+++ b/src/tests/helper.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2018 VyOS maintainers and contributors
+# Copyright (C) 2018-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
diff --git a/src/tests/test_config_diff.py b/src/tests/test_config_diff.py
index 61a2f3487..39e17613a 100644
--- a/src/tests/test_config_diff.py
+++ b/src/tests/test_config_diff.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-#
# Copyright (C) 2023-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
diff --git a/src/tests/test_config_parser.py b/src/tests/test_config_parser.py
index c69732daa..9a4f02859 100644
--- a/src/tests/test_config_parser.py
+++ b/src/tests/test_config_parser.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-#
# Copyright (C) 2018-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
diff --git a/src/tests/test_configd_inspect.py b/src/tests/test_configd_inspect.py
new file mode 100644
index 000000000..98552c8f3
--- /dev/null
+++ b/src/tests/test_configd_inspect.py
@@ -0,0 +1,105 @@
+# Copyright (C) 2020-2024 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import re
+import json
+
+import warnings
+import importlib.util
+from inspect import signature
+from inspect import getsource
+from functools import wraps
+from unittest import TestCase
+
+INC_FILE = 'data/configd-include.json'
+CONF_DIR = 'src/conf_mode'
+
+f_list = ['get_config', 'verify', 'generate', 'apply']
+
+def import_script(s):
+ path = os.path.join(CONF_DIR, s)
+ name = os.path.splitext(s)[0].replace('-', '_')
+ spec = importlib.util.spec_from_file_location(name, path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+# importing conf_mode scripts imports jinja2 with deprecation warning
+def ignore_deprecation_warning(f):
+ @wraps(f)
+ def decorated_function(*args, **kwargs):
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ f(*args, **kwargs)
+ return decorated_function
+
+class TestConfigdInspect(TestCase):
+ def setUp(self):
+ with open(INC_FILE) as f:
+ self.inc_list = json.load(f)
+
+ @ignore_deprecation_warning
+ def test_signatures(self):
+ for s in self.inc_list:
+ m = import_script(s)
+ for i in f_list:
+ f = getattr(m, i, None)
+ if not f:
+ continue
+ sig = signature(f)
+ par = sig.parameters
+ l = len(par)
+ self.assertEqual(l, 1,
+ f"'{s}': '{i}' incorrect signature")
+ if i == 'get_config':
+ for p in par.values():
+ self.assertTrue(p.default is None,
+ f"'{s}': '{i}' incorrect signature")
+
+ @ignore_deprecation_warning
+ def test_function_instance(self):
+ for s in self.inc_list:
+ m = import_script(s)
+ for i in f_list:
+ f = getattr(m, i, None)
+ if not f:
+ continue
+ str_f = getsource(f)
+ # Regex not XXXConfig() T3108
+ n = len(re.findall(r'[^a-zA-Z]Config\(\)', str_f))
+ if i == 'get_config':
+ self.assertEqual(n, 1,
+ f"'{s}': '{i}' no instance of Config")
+ if i != 'get_config':
+ self.assertEqual(n, 0,
+ f"'{s}': '{i}' instance of Config")
+
+ @ignore_deprecation_warning
+ def test_file_instance(self):
+ for s in self.inc_list:
+ m = import_script(s)
+ str_m = getsource(m)
+ # Regex not XXXConfig T3108
+ n = len(re.findall(r'[^a-zA-Z]Config\(\)', str_m))
+ self.assertEqual(n, 1,
+ f"'{s}' more than one instance of Config")
+
+ @ignore_deprecation_warning
+ def test_config_modification(self):
+ for s in self.inc_list:
+ m = import_script(s)
+ str_m = getsource(m)
+ n = str_m.count('my_set')
+ self.assertEqual(n, 0, f"'{s}' modifies config")
diff --git a/src/tests/test_configverify.py b/src/tests/test_configverify.py
index 15ccdf13d..f1ec65cd2 100644
--- a/src/tests/test_configverify.py
+++ b/src/tests/test_configverify.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2020 VyOS maintainers and contributors
+# Copyright (C) 2020-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
diff --git a/src/tests/test_dependency_graph.py b/src/tests/test_dependency_graph.py
index f682e87bb..f3f1db376 100644
--- a/src/tests/test_dependency_graph.py
+++ b/src/tests/test_dependency_graph.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2023 VyOS maintainers and contributors
+# Copyright (C) 2023-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
diff --git a/src/tests/test_dict_search.py b/src/tests/test_dict_search.py
index 2435d89c7..6b4bc933a 100644
--- a/src/tests/test_dict_search.py
+++ b/src/tests/test_dict_search.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2020 VyOS maintainers and contributors
+# Copyright (C) 2020-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
diff --git a/src/tests/test_find_device_file.py b/src/tests/test_find_device_file.py
index f18043d65..21fc113f9 100755..100644
--- a/src/tests/test_find_device_file.py
+++ b/src/tests/test_find_device_file.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2020 VyOS maintainers and contributors
+# Copyright (C) 2020-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
diff --git a/src/tests/test_initial_setup.py b/src/tests/test_initial_setup.py
index f85bf1265..4cd5fb169 100644
--- a/src/tests/test_initial_setup.py
+++ b/src/tests/test_initial_setup.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-#
# Copyright (C) 2018-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
diff --git a/src/tests/test_op_mode.py b/src/tests/test_op_mode.py
index 90963b3c5..23f709653 100644
--- a/src/tests/test_op_mode.py
+++ b/src/tests/test_op_mode.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2022 VyOS maintainers and contributors
+# Copyright (C) 2022-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -62,4 +60,3 @@ class TestVyOSOpMode(TestCase):
data = [1, False, "foo"]
self.assertEqual(_normalize_field_names(data), [1, False, "foo"])
-
diff --git a/src/tests/test_task_scheduler.py b/src/tests/test_task_scheduler.py
index 130f825e6..795ffeb9d 100644
--- a/src/tests/test_task_scheduler.py
+++ b/src/tests/test_task_scheduler.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2018-2023 VyOS maintainers and contributors
+# Copyright (C) 2018-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
diff --git a/src/tests/test_template.py b/src/tests/test_template.py
index dbb86b40b..6377f6da5 100644
--- a/src/tests/test_template.py
+++ b/src/tests/test_template.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-#
# Copyright (C) 2020-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
diff --git a/src/tests/test_utils.py b/src/tests/test_utils.py
index 9ae329ced..7bfd2618e 100644
--- a/src/tests/test_utils.py
+++ b/src/tests/test_utils.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2020-2023 VyOS maintainers and contributors
+# Copyright (C) 2020-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
diff --git a/src/tests/test_utils_network.py b/src/tests/test_utils_network.py
index 5a6dc2586..d68dec16f 100644
--- a/src/tests/test_utils_network.py
+++ b/src/tests/test_utils_network.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2020-2023 VyOS maintainers and contributors
+# Copyright (C) 2020-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -45,6 +43,3 @@ class TestVyOSUtilsNetwork(TestCase):
self.assertFalse(vyos.utils.network.is_loopback_addr('::2'))
self.assertFalse(vyos.utils.network.is_loopback_addr('192.0.2.1'))
-
-
-