Add: Tests WIP
This commit is contained in:
parent
a24a311f23
commit
9341e47cb9
17
conftest.py
Normal file
17
conftest.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
TestCase = namedtuple("TestCase", ["args", "kwargs", "expected"])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(
|
||||||
|
params = [
|
||||||
|
TestCase('Simple string', ['bli-blah-bloh !?'], None),
|
||||||
|
TestCase('fqdn', ['this.is.my.domain'], None),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_case(request):
|
||||||
|
return request.param
|
||||||
|
|
||||||
4
run_jupyter.sh
Executable file
4
run_jupyter.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export KHEOPS_EXAMPLES_DIR=$PWD
|
||||||
|
jupyter notebook --notebook-dir=docs/jupyter/
|
||||||
6
run_tests.sh
Executable file
6
run_tests.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# Coverage:
|
||||||
|
pytest --cov=kheops tests/
|
||||||
|
|
||||||
|
pytest
|
||||||
27
tests/test_app.py
Normal file
27
tests/test_app.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
import kheops.app as Kheops
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_app_config():
|
||||||
|
|
||||||
|
# Testing missing namespace
|
||||||
|
for namespace in ['missing', '_weird_key' ]:
|
||||||
|
try:
|
||||||
|
config= 'examples/kheops.yml'
|
||||||
|
Kheops.Kheops(config=config, namespace=namespace)
|
||||||
|
assert False
|
||||||
|
except Exception:
|
||||||
|
assert True
|
||||||
|
|
||||||
|
# Testing unexisting config files
|
||||||
|
namespace = 'default'
|
||||||
|
for config in ['toto.yaml', 'toto.noext']:
|
||||||
|
try:
|
||||||
|
Kheops.Kheops(config=config, namespace=namespace)
|
||||||
|
assert False
|
||||||
|
except Exception:
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
68
tests/test_lib.py
Normal file
68
tests/test_lib.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from kheops.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"result,args,kwargs",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
['this', 'this/is', 'this/is/my', 'this/is/my/hierarchy'],
|
||||||
|
['this/is/my/hierarchy'],
|
||||||
|
{
|
||||||
|
'reverse': False,
|
||||||
|
'sep': '/',
|
||||||
|
'start_index': 0,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
['this/is/my', 'this/is/my/hierarchy'],
|
||||||
|
['this/is/my/hierarchy'],
|
||||||
|
{
|
||||||
|
'reverse': False,
|
||||||
|
'sep': '/',
|
||||||
|
'start_index': 3,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
['hierarchy', 'hierarchy/my', 'hierarchy/my/is', 'hierarchy/my/is/this'],
|
||||||
|
['this/is/my/hierarchy'],
|
||||||
|
{
|
||||||
|
'reverse': True,
|
||||||
|
'sep': '/',
|
||||||
|
'start_index': 0,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
['this', 'this/is', 'this/is/my', 'this/is/my/server', 'this/is/my/server/domaine'],
|
||||||
|
['this.is.my.server.domaine'],
|
||||||
|
{
|
||||||
|
'reverse': False,
|
||||||
|
'sep': '.',
|
||||||
|
'start_index': 0,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_path_assemble_hier2(result, args, kwargs):
|
||||||
|
|
||||||
|
res = path_assemble_hier(*args, **kwargs)
|
||||||
|
assert result == res
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"result,args",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
'hello super world',
|
||||||
|
['hello {{ world }}', {'world': 'super world'}]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_render_template(result, args):
|
||||||
|
|
||||||
|
res = render_template(*args)
|
||||||
|
assert res == result
|
||||||
|
|
||||||
|
|
||||||
34
tests/test_plugin_scope.py
Normal file
34
tests/test_plugin_scope.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from kheops.plugin.scope.loop import Plugin
|
||||||
|
|
||||||
|
|
||||||
|
lookups = [
|
||||||
|
{
|
||||||
|
'_run':{ 'scope': { 'my': 'scope'}},},
|
||||||
|
]
|
||||||
|
|
||||||
|
conf = {
|
||||||
|
'var': 'item_loop',
|
||||||
|
'data': {
|
||||||
|
"my": 'data',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
""
|
||||||
|
[
|
||||||
|
test_case("Validate simple loop",
|
||||||
|
[
|
||||||
|
lookups, conf,
|
||||||
|
],
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
])
|
||||||
|
def test_plugin():
|
||||||
|
|
||||||
|
plugin = Plugin()
|
||||||
|
ret = plugin.process_items()
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user