mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-30 12:10:22 -07:00
Various tests using datafiles are being moved into the integration test framework (tests_new right now).
The unit test infrastructure will remain for things that are mocked out and testable with out filesystem side effects, and a few cases of things that might not be quite so much (like inventory) that can still benefit from heavy access to the API. See the 'tests_new/integration' directory, this will soon fold into tests_new.
This commit is contained in:
parent
0581746a80
commit
fe7d3773ae
42 changed files with 0 additions and 1607 deletions
|
@ -16,94 +16,6 @@ sys.setdefaultencoding("utf8")
|
|||
|
||||
class TestUtils(unittest.TestCase):
|
||||
|
||||
#####################################
|
||||
### varReplace function tests
|
||||
|
||||
def test_varReplace_var_complex_var(self):
|
||||
vars = {
|
||||
'x': '$y',
|
||||
'y': {
|
||||
'foo': 'result',
|
||||
},
|
||||
}
|
||||
template = '${x.foo}'
|
||||
res = template2.template(None, template, vars)
|
||||
assert res == 'result'
|
||||
|
||||
#####################################
|
||||
### template_ds function tests
|
||||
|
||||
def test_template_ds_basic(self):
|
||||
vars = {
|
||||
'data': {
|
||||
'var': [
|
||||
'foo',
|
||||
'bar',
|
||||
'baz',
|
||||
],
|
||||
'types': [
|
||||
'str',
|
||||
u'unicode',
|
||||
1,
|
||||
1L,
|
||||
1.2,
|
||||
],
|
||||
'alphas': '$alphas',
|
||||
},
|
||||
'alphas': [
|
||||
'abc',
|
||||
'def',
|
||||
'ghi',
|
||||
],
|
||||
}
|
||||
|
||||
template = '${data.var}'
|
||||
res = template2.template(None, template, vars)
|
||||
assert sorted(res) == sorted(vars['data']['var'])
|
||||
|
||||
template = '${data.types}'
|
||||
res = template2.template(None, template, vars)
|
||||
assert sorted(res) == sorted(vars['data']['types'])
|
||||
|
||||
template = '${data.alphas}'
|
||||
res = template2.template(None, template, vars)
|
||||
assert sorted(res) == sorted(vars['alphas'])
|
||||
|
||||
template = '${data.nonexisting}'
|
||||
res = template2.template(None, template, vars)
|
||||
assert res == template
|
||||
|
||||
#####################################
|
||||
### Template function tests
|
||||
|
||||
def test_template_basic(self):
|
||||
vars = {
|
||||
'who': 'world',
|
||||
}
|
||||
|
||||
res = template2.template_from_file("test", "template-basic", vars)
|
||||
|
||||
assert res == 'hello world'
|
||||
|
||||
def test_template_whitespace(self):
|
||||
vars = {
|
||||
'who': 'world',
|
||||
}
|
||||
|
||||
res = template2.template_from_file("test", "template-whitespace", vars)
|
||||
|
||||
assert res == 'hello world\n'
|
||||
|
||||
def test_template_unicode(self):
|
||||
vars = {
|
||||
'who': u'wórld',
|
||||
}
|
||||
|
||||
res = template2.template_from_file("test", "template-basic", vars)
|
||||
|
||||
assert res == u'hello wórld'
|
||||
|
||||
|
||||
#####################################
|
||||
### check_conditional tests
|
||||
|
||||
|
@ -204,44 +116,3 @@ class TestUtils(unittest.TestCase):
|
|||
assert (ansible.utils.parse_kv('a=simple b="with space" c="this=that"') ==
|
||||
{'a': 'simple', 'b': 'with space', 'c': 'this=that'})
|
||||
|
||||
#####################################
|
||||
### plugins
|
||||
|
||||
def test_loaders_expanduser_each_dir(self):
|
||||
# Test that PluginLoader will call expanduser on each path
|
||||
# when it splits its "config" argument.
|
||||
home_dir = os.path.expanduser("~")
|
||||
if home_dir == "~":
|
||||
raise SkipTest("your platform doesn't expand ~ in paths")
|
||||
elif not os.path.isdir(home_dir):
|
||||
raise SkipTest("~ expands to non-directory %r" % (home_dir,))
|
||||
elif not os.path.isabs(home_dir):
|
||||
raise SkipTest("~ expands to non-absolute path %r" % (home_dir,))
|
||||
# Unfortunately we have to create temporary directories in
|
||||
# your home directory; the directories have to exist for
|
||||
# PluginLoader to accept them.
|
||||
abs_dirs, tilde_dirs = [], []
|
||||
try:
|
||||
for _ in range(2):
|
||||
temp_dir = tempfile.mkdtemp(prefix="ansible", dir=home_dir)
|
||||
abs_dirs.append(temp_dir)
|
||||
# Convert mkdtemp's absolute path to one starting with "~".
|
||||
tilde_dir = os.path.join("~", os.path.relpath(temp_dir,
|
||||
home_dir))
|
||||
tilde_dirs.append(tilde_dir)
|
||||
loader = ansible.utils.plugins.PluginLoader(
|
||||
"",
|
||||
"",
|
||||
os.pathsep.join(tilde_dirs),
|
||||
"something_under_basedir"
|
||||
)
|
||||
loader_paths = loader.print_paths().split(os.pathsep)
|
||||
for abs_dir in abs_dirs:
|
||||
assert abs_dir in loader_paths, \
|
||||
"%r not in %r" % (abs_dir, loader_paths)
|
||||
finally:
|
||||
for a_dir in abs_dirs:
|
||||
try:
|
||||
os.rmdir(a_dir)
|
||||
except os.error:
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue