Debian Codegraph @

test/lib/ansible_test/_internal/provider/layout/ansible.py

raw
1 """Layout provider for Ansible source."""
2
3 from __future__ import annotations
4
5 import os
6
7 from . import (
8 ContentLayout,
9 LayoutProvider,
10 )
11
12 from ...util import (
13 ANSIBLE_SOURCE_ROOT,
14 ANSIBLE_TEST_ROOT,
15 )
16
17
18 class AnsibleLayout(LayoutProvider):
19 """Layout provider for Ansible source."""
20
21 @staticmethod
22 def is_content_root(path: str) -> bool:
23 """Return True if the given path is a content root for this provider."""
24 return os.path.isfile(os.path.join(path, 'pyproject.toml')) and os.path.isdir(os.path.join(path, 'test/lib/ansible_test'))
25
26 def create(self, root: str, paths: list[str]) -> ContentLayout:
27 """Create a Layout using the given root and paths."""
28 plugin_paths = dict((p, os.path.join('lib/ansible/plugins', p)) for p in self.PLUGIN_TYPES)
29
30 plugin_paths.update(
31 modules='lib/ansible/modules',
32 module_utils='lib/ansible/module_utils',
33 )
34
35 errors: list[str] = []
36
37 if root != ANSIBLE_SOURCE_ROOT:
38 errors.extend((
39 f'Cannot test "{root}" with ansible-test from "{ANSIBLE_TEST_ROOT}".',
40 '',
41 f'Did you intend to run "{root}/bin/ansible-test" instead?',
42 ))
43
44 return ContentLayout(
45 root,
46 paths,
47 plugin_paths=plugin_paths,
48 collection=None,
49 test_path='test',
50 results_path='test/results',
51 sanity_path='test/sanity',
52 sanity_messages=None,
53 integration_path='test/integration',
54 integration_targets_path='test/integration/targets',
55 integration_vars_path='test/integration/integration_config.yml',
56 integration_messages=None,
57 unit_path='test/units',
58 unit_module_path='test/units/modules',
59 unit_module_utils_path='test/units/module_utils',
60 unit_messages=None,
61 unsupported=errors,
62 )