summaryrefslogtreecommitdiff
path: root/tests/unittests/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r--tests/unittests/helpers.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index ccd56793..e9afbd36 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -12,10 +12,12 @@ import sys
import tempfile
import time
import unittest
+from pathlib import Path
from contextlib import ExitStack, contextmanager
from unittest import mock
from unittest.util import strclass
+import cloudinit
from cloudinit.config.schema import (
SchemaValidationError, validate_cloudconfig_schema)
from cloudinit import cloud
@@ -462,7 +464,7 @@ def wrap_and_call(prefix, mocks, func, *args, **kwargs):
def resourceLocation(subname=None):
- path = os.path.join('tests', 'data')
+ path = cloud_init_project_dir('tests/data')
if not subname:
return path
return os.path.join(path, subname)
@@ -504,4 +506,22 @@ if not hasattr(mock.Mock, 'assert_not_called'):
raise AssertionError(msg)
mock.Mock.assert_not_called = __mock_assert_not_called
+
+def get_top_level_dir() -> Path:
+ """Return the absolute path to the top cloudinit project directory
+
+ @return Path('<top-cloudinit-dir>')
+ """
+ return Path(cloudinit.__file__).parent.parent.resolve()
+
+
+def cloud_init_project_dir(sub_path: str) -> str:
+ """Get a path within the cloudinit project directory
+
+ @return str of the combined path
+
+ Example: cloud_init_project_dir("my/path") -> "/path/to/cloud-init/my/path"
+ """
+ return str(get_top_level_dir() / sub_path)
+
# vi: ts=4 expandtab