summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2023-02-23 17:47:02 -0800
committerGitHub <noreply@github.com>2023-02-23 17:47:02 -0800
commita895cae5a1bf53607c8b538af8ea07decb1c7cc6 (patch)
tree30f90dcf51207205033164f96596d6d6796bd6eb
parent2f62db842d2afdfda0d050101d66f60a272d203a (diff)
downloadansible-a895cae5a1bf53607c8b538af8ea07decb1c7cc6.tar.gz
Relocate validate-modules unit tests (#80087)
This allows the validate-modules unit tests to run as part of the regular unit test suite.
-rw-r--r--test/units/ansible_test/test_validate_modules.py (renamed from test/ansible_test/validate-modules-unit/test_validate_modules_regex.py)21
1 files changed, 18 insertions, 3 deletions
diff --git a/test/ansible_test/validate-modules-unit/test_validate_modules_regex.py b/test/units/ansible_test/test_validate_modules.py
index 8c0b45ca3e..2316a14066 100644
--- a/test/ansible_test/validate-modules-unit/test_validate_modules_regex.py
+++ b/test/units/ansible_test/test_validate_modules.py
@@ -1,10 +1,22 @@
"""Tests for validate-modules regexes."""
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
+
+import mock
+import pathlib
+import sys
import pytest
-from validate_modules.main import TYPE_REGEX
+
+@pytest.fixture(autouse=True, scope='session')
+def validate_modules() -> None:
+ """Make validate_modules available on sys.path for unit testing."""
+ sys.path.insert(0, str(pathlib.Path(__file__).parent.parent.parent / 'lib/ansible_test/_util/controller/sanity/validate-modules'))
+
+ # Mock out voluptuous to facilitate testing without it, since tests aren't covering anything that uses it.
+
+ sys.modules['voluptuous'] = voluptuous = mock.MagicMock()
+ sys.modules['voluptuous.humanize'] = voluptuous.humanize = mock.MagicMock()
@pytest.mark.parametrize('cstring,cexpected', [
@@ -36,7 +48,10 @@ from validate_modules.main import TYPE_REGEX
])
def test_type_regex(cstring, cexpected): # type: (str, str) -> None
"""Check TYPE_REGEX against various examples to verify it correctly matches or does not match."""
+ from validate_modules.main import TYPE_REGEX
+
match = TYPE_REGEX.match(cstring)
+
if cexpected and not match:
assert False, "%s should have matched" % cstring
elif not cexpected and match: