This repository has been archived by the owner on Jun 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
74 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import yaml | ||
|
||
import pytest | ||
|
||
_real_stack_path = os.path.realpath('./stack.yml') | ||
with open(_real_stack_path, 'r') as stack_yaml: | ||
_stack_data = yaml.safe_load(stack_yaml) | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def stack_dir(): | ||
return os.path.dirname(_real_stack_path) | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def stack_data(): | ||
return _stack_data | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
if 'stack_function' in metafunc.fixturenames: | ||
data = [] | ||
for function, values in _stack_data['functions'].items(): | ||
values.setdefault('function', function) | ||
data.append(values) | ||
|
||
metafunc.parametrize('stack_function', | ||
data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import pytest | ||
|
||
|
||
def test_stack_functions(stack_data): | ||
errMsg = 'Error: \'stack.yml\' file does not contain any functions.' | ||
assert 'functions' in stack_data, errMsg | ||
|
||
|
||
def test_git_ignore(stack_dir): | ||
path = os.path.join(stack_dir, '.gitignore') | ||
errMsg = f'Error: No \'.gitignore\' file found in {stack_dir}.' | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_stack_handlers(stack_function, stack_dir): | ||
path = os.path.join(stack_dir, stack_function['handler']) | ||
errMsg = f'Error: No directory for {stack_function["handler"]}.' | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_stack_handlers_file(stack_function, stack_dir): | ||
path = os.path.join(stack_dir, stack_function['handler'], 'handler.py') | ||
errMsg = (f'Error: \'{stack_function["handler"]}\' does not contain ' | ||
'\'handler.py\' file.') | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_stack_handlers_requires(stack_function, stack_dir): | ||
path = os.path.join(stack_dir, stack_function['handler'], | ||
'requirements.txt') | ||
errMsg = (f'Error: \'{stack_function["handler"]}\' does not contain ' | ||
'\'requirements.txt\' file.') | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_stack_handlers_init(stack_function, stack_dir): | ||
path = os.path.join(stack_dir, stack_function['handler'], | ||
'__init__.py') | ||
errMsg = (f'Error: \'{stack_function["handler"]}\' does not contain ' | ||
'\'__init__.py\' file.') | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_stack_langs(stack_function, stack_dir): | ||
path = os.path.join(stack_dir, 'template', stack_function['lang']) | ||
errMsg = (f'Error: No directory for {stack_function["lang"]} is present in ' | ||
'\'template\' directory.') | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_stack_langs_dockerfile(stack_function, stack_dir): | ||
path = os.path.join(stack_dir, 'template', stack_function['lang'], | ||
'Dockerfile') | ||
errMsg = (f'Error: \'template/{stack_function["lang"]}/\' does not contain ' | ||
'\'Dockerfile\'.') | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_stack_langs_requires(stack_function, stack_dir): | ||
path = os.path.join(stack_dir, 'template', stack_function['lang'], | ||
'requirements.txt') | ||
errMsg = (f'Error: \'template/{stack_function["lang"]}/\' does not contain ' | ||
'\'requirements.txt\' file.') | ||
assert os.path.exists(os.path.realpath(path)), errMsg | ||
|
||
|
||
def test_only_langs(stack_data, stack_dir): | ||
lang_set = {v['lang'] for k, v in stack_data['functions'].items()} | ||
dir_set = set(os.listdir(os.path.join(stack_dir, 'template'))) | ||
warnMsg = ('Warning: Unused language templates are present in \'template\' ' | ||
'directory.') | ||
|
||
assert len(dir_set - lang_set) == 0, warnMsg |