diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..52729dd --- /dev/null +++ b/.gitignore @@ -0,0 +1,146 @@ + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +*.pyc + + + + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof + +# End of https://www.toptal.com/developers/gitignore/api/python diff --git a/enums.py b/enums.py index 5bc6548..4915c07 100644 --- a/enums.py +++ b/enums.py @@ -8,3 +8,6 @@ class GitHubActionsInput(str, Enum): STRICT = 'INPUT_STRICT' TEMPLATE = 'INPUT_TEMPLATE' VARIABLES = 'INPUT_VARIABLES' + + def __str__(self): + return self.value diff --git a/unit-tests.py b/unit-tests.py index a158940..43bb5f3 100644 --- a/unit-tests.py +++ b/unit-tests.py @@ -1,7 +1,69 @@ +import os import unittest +from enums import GitHubActionsInput +from main import Context + + class TestContext(unittest.TestCase): - pass + TEST_FILE = 'test_output' + + def test_load_from_env(self): + env_vars = { + 'foo': 'bar', + GitHubActionsInput.VARIABLES.value: 'name=John\nsurname=Doe' + } + + context = Context(env_vars) + context.load_from_env() + expected = {'env': env_vars} + + self.assertEqual(context._variables, expected) + + def test_load_from_input(self): + context = Context({GitHubActionsInput.VARIABLES.value: 'name=John\nsurname=Doe'}) + context.load_from_input() + + expected = { + 'name': 'John', + 'surname': 'Doe', + } + self.assertEqual(context._variables, expected) + + + def test_load_from_data_file(self): + context = Context({ + GitHubActionsInput.DATA_FILE.value: 'test/data-files/data.yml' + }) + + context.load_from_data_file() + + expected = { + 'foo': 'bar', + 'baz': 'cux', + } + self.assertEqual(context._variables, expected) + + def test_render_template(self): + context = Context({ + GitHubActionsInput.DATA_FILE.value: 'test/data-files/data.json', + GitHubActionsInput.OUTPUT_FILE.value: self.TEST_FILE, + GitHubActionsInput.TEMPLATE.value: 'test/many-variables/template', + }) + + context.load_from_data_file() + context.render_template() + + expected = "\nbar\ncux\n" + + with open('test_output', 'r') as file: + result = file.read() + self.assertEqual(result, expected) + @classmethod + def tearDownClass(cls): + if os.path.exists(cls.TEST_FILE): + os.remove(cls.TEST_FILE) + if __name__ == '__main__': unittest.main() \ No newline at end of file