summaryrefslogtreecommitdiff
path: root/tests/unittests/config/test_schema.py
diff options
context:
space:
mode:
authorBrett Holman <bholman.devel@gmail.com>2021-12-08 14:27:37 -0700
committerGitHub <noreply@github.com>2021-12-08 15:27:37 -0600
commit65c2cfd7f21758746444c8c79444994a4638d563 (patch)
tree3b4c91b0ba35dbd8f043f779a9ea6b41f4665a16 /tests/unittests/config/test_schema.py
parentb21afb0a8ab64543715dffff490253db8ecefb9f (diff)
downloadvyos-cloud-init-65c2cfd7f21758746444c8c79444994a4638d563.tar.gz
vyos-cloud-init-65c2cfd7f21758746444c8c79444994a4638d563.zip
factor out function for getting top level directory of cloudinit (#1136)
Add a test helper to get top level directory Many tests need to get the location of files & dirs within the cloud-init project directory. Tests implement this in various different ways, and often those ways depend on the current working directory of the pytest invocation. Create helper functions (and tests) that gets the path of the top directory or any sub directory under the top directory. This function does not depend on the environment.
Diffstat (limited to 'tests/unittests/config/test_schema.py')
-rw-r--r--tests/unittests/config/test_schema.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py
index f90e0f62..ed7ab527 100644
--- a/tests/unittests/config/test_schema.py
+++ b/tests/unittests/config/test_schema.py
@@ -12,7 +12,6 @@ from pathlib import Path
from textwrap import dedent
from yaml import safe_load
-import cloudinit
from cloudinit.config.schema import (
CLOUD_CONFIG_HEADER,
SchemaValidationError,
@@ -27,7 +26,12 @@ from cloudinit.config.schema import (
MetaSchema,
)
from cloudinit.util import write_file
-from tests.unittests.helpers import CiTestCase, mock, skipUnlessJsonSchema
+from tests.unittests.helpers import (
+ CiTestCase,
+ mock,
+ skipUnlessJsonSchema,
+ cloud_init_project_dir,
+)
def get_schemas() -> dict:
@@ -50,7 +54,10 @@ def get_module_variable(var_name) -> dict:
"""Inspect modules and get variable from module matching var_name"""
schemas = {}
- files = list(Path("../../cloudinit/config/").glob("cc_*.py"))
+ files = list(
+ Path(cloud_init_project_dir("../../cloudinit/config/")).glob("cc_*.py")
+ )
+
modules = [mod.stem for mod in files]
for module in modules:
@@ -616,8 +623,7 @@ class TestMain:
def _get_meta_doc_examples():
- examples_dir = Path(
- cloudinit.__file__).parent.parent / 'doc' / 'examples'
+ examples_dir = Path(cloud_init_project_dir('doc/examples'))
assert examples_dir.is_dir()
all_text_files = (f for f in examples_dir.glob('cloud-config*.txt')