Skip to content
This repository has been archived by the owner on Jun 28, 2019. It is now read-only.

Commit

Permalink
Add pytest compatible sanity check.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuk380y committed Jun 3, 2019
1 parent a96733f commit e1b844e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 74 deletions.
74 changes: 0 additions & 74 deletions general_sanity.py

This file was deleted.

Empty file added tests/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions tests/conftest.py
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)
74 changes: 74 additions & 0 deletions tests/test_stack_yaml.py
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

0 comments on commit e1b844e

Please sign in to comment.