Page MenuHomeDevCentral

D3685.id9537.diff
No OneTemporary

D3685.id9537.diff

diff --git a/_tests/Makefile b/_tests/Makefile
--- a/_tests/Makefile
+++ b/_tests/Makefile
@@ -1,9 +1,18 @@
+CURRENT_DIR != pwd
+MODULES_DIR = ${CURRENT_DIR}/../_modules
+
test: test-python test-bats
-test-python:
- python -m unittest discover modules
+test-python: test-modules test-pillar test-python-scripts
+
+test-modules:
+ PYTHONPATH="${CURRENT_DIR}:${MODULES_DIR}" python -m unittest discover modules
+
+test-pillar:
python -m unittest discover pillar
- python -m unittest discover scripts/python
+
+test-python-scripts:
+ PYTHONPATH="${CURRENT_DIR}" python -m unittest discover scripts/python
test-bats:
bats scripts/bats/test_edit_acme_dns_accounts.sh
diff --git a/_tests/helpers.py b/_tests/helpers.py
new file mode 100644
--- /dev/null
+++ b/_tests/helpers.py
@@ -0,0 +1,30 @@
+# -------------------------------------------------------------
+# Helper utilities for tests suite
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: 0BSD for import_from_path
+# Reference: http://docs.python.org/3/library/importlib.html
+# -------------------------------------------------------------
+
+
+import importlib.util
+import sys
+
+
+# -------------------------------------------------------------
+# Import mechanics
+#
+# Supersede importlib.machinery.SourceFileLoader load_module use
+# to maintain compatibility with Python 3.12+
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def import_from_path(module_name, file_path):
+ file_final_path = "../" + file_path
+ spec = importlib.util.spec_from_file_location(module_name, file_final_path)
+
+ module = importlib.util.module_from_spec(spec)
+ sys.modules[module_name] = module
+ spec.loader.exec_module(module)
+
+ return module
diff --git a/_tests/modules/test_convert.py b/_tests/modules/test_convert.py
--- a/_tests/modules/test_convert.py
+++ b/_tests/modules/test_convert.py
@@ -1,10 +1,9 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-convert = SourceFileLoader("rust", "../_modules/convert.py").load_module()
+import salt_test_case
+import convert
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/modules/test_forest.py b/_tests/modules/test_forest.py
--- a/_tests/modules/test_forest.py
+++ b/_tests/modules/test_forest.py
@@ -1,11 +1,9 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-forest = SourceFileLoader("forest", "../_modules/forest.py").load_module()
+import salt_test_case
+import forest
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/modules/test_jails.py b/_tests/modules/test_jails.py
--- a/_tests/modules/test_jails.py
+++ b/_tests/modules/test_jails.py
@@ -1,11 +1,9 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-jails = SourceFileLoader("jails", "../_modules/jails.py").load_module()
+import salt_test_case
+import jails
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/modules/test_nano.py b/_tests/modules/test_nano.py
--- a/_tests/modules/test_nano.py
+++ b/_tests/modules/test_nano.py
@@ -1,11 +1,9 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-nano = SourceFileLoader("nano", "../_modules/nano.py").load_module()
+import salt_test_case
+import nano
DATA_DIR = "data/nanorc_dir"
diff --git a/_tests/modules/test_network.py b/_tests/modules/test_network.py
--- a/_tests/modules/test_network.py
+++ b/_tests/modules/test_network.py
@@ -1,12 +1,10 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
from unittest_data_provider import data_provider
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-network = SourceFileLoader("network", "../_modules/network_utils.py").load_module()
+import salt_test_case
+import network_utils as network
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/modules/test_node.py b/_tests/modules/test_node.py
--- a/_tests/modules/test_node.py
+++ b/_tests/modules/test_node.py
@@ -1,12 +1,10 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
from unittest_data_provider import data_provider
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-node = SourceFileLoader("node", "../_modules/node.py").load_module()
+import salt_test_case
+import node
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/modules/test_paas_docker.py b/_tests/modules/test_paas_docker.py
--- a/_tests/modules/test_paas_docker.py
+++ b/_tests/modules/test_paas_docker.py
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import os
import unittest
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-docker = SourceFileLoader("docker", "../_modules/paas_docker.py").load_module()
+import salt_test_case
+import paas_docker as docker
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/modules/test_prometheus.py b/_tests/modules/test_prometheus.py
--- a/_tests/modules/test_prometheus.py
+++ b/_tests/modules/test_prometheus.py
@@ -1,10 +1,9 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-prometheus = SourceFileLoader("prometheus", "../_modules/prometheus.py").load_module()
+import salt_test_case
+import prometheus
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/modules/test_rabbitmq.py b/_tests/modules/test_rabbitmq.py
--- a/_tests/modules/test_rabbitmq.py
+++ b/_tests/modules/test_rabbitmq.py
@@ -1,16 +1,14 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-rabbitmq = SourceFileLoader("rabbitmq", "../_modules/rabbitmq_api.py").load_module()
+import salt_test_case
+import rabbitmq_api
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def test_compute_password_hash_with_salt(self):
self.assertEqual(
"kI3GCqW5JLMJa4iX1lo7X4D6XbYqlLgxIs30+P6tENUV2POR",
- rabbitmq.compute_password_hash_with_salt(0x908DC60A, "test12"),
+ rabbitmq_api.compute_password_hash_with_salt(0x908DC60A, "test12"),
)
diff --git a/_tests/modules/test_rust.py b/_tests/modules/test_rust.py
--- a/_tests/modules/test_rust.py
+++ b/_tests/modules/test_rust.py
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
from salt.modules import cmdmod
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-rust = SourceFileLoader("rust", "../_modules/rust.py").load_module()
+import salt_test_case
+import rust
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
diff --git a/_tests/salt_test_case.py b/_tests/salt_test_case.py
--- a/_tests/salt_test_case.py
+++ b/_tests/salt_test_case.py
@@ -1,13 +1,13 @@
-from importlib.machinery import SourceFileLoader
import yaml
+from mocks.dunder import dunder
+
class SaltTestCase:
def initialize_mocks(self):
- source = SourceFileLoader("dunder", "mocks/dunder.py").load_module()
- self.pillar = source.dunder()
- self.salt = source.dunder()
- self.grains = source.dunder()
+ self.pillar = dunder()
+ self.salt = dunder()
+ self.grains = dunder()
@staticmethod
def import_data_from_yaml(filename):
diff --git a/_tests/scripts/python/test_clear_video_queue.py b/_tests/scripts/python/test_clear_video_queue.py
--- a/_tests/scripts/python/test_clear_video_queue.py
+++ b/_tests/scripts/python/test_clear_video_queue.py
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
+from helpers import import_from_path
-path = "roles/paas-docker/containers/files/mastodon/clear-video-queue.py"
-script = SourceFileLoader("script", "../" + path).load_module()
+
+script_path = "roles/paas-docker/containers/files/mastodon/clear-video-queue.py"
+script = import_from_path("script", script_path)
class Testinstance(unittest.TestCase):
diff --git a/_tests/scripts/python/test_edit_acme_dns_accounts.py b/_tests/scripts/python/test_edit_acme_dns_accounts.py
--- a/_tests/scripts/python/test_edit_acme_dns_accounts.py
+++ b/_tests/scripts/python/test_edit_acme_dns_accounts.py
@@ -1,14 +1,17 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
+
import os
import unittest
+from helpers import import_from_path
-os.environ["ACME_ACCOUNTS"] = "/path/to/acmedns.json"
-path = "roles/core/certificates/files/edit-acme-dns-accounts.py"
-script = SourceFileLoader("script", "../" + path).load_module()
+script_path = "roles/core/certificates/files/edit-acme-dns-accounts.py"
+script = import_from_path("script", script_path)
+
+
+os.environ["ACME_ACCOUNTS"] = "/path/to/acmedns.json"
class TestInstance(unittest.TestCase):

File Metadata

Mime Type
text/plain
Expires
Fri, Sep 19, 03:16 (20 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2994987
Default Alt Text
D3685.id9537.diff (9 KB)

Event Timeline