Skip to content

Commit

Permalink
test: add the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulo Henrique Cuchi committed Oct 18, 2020
1 parent 29b3303 commit 5a62d10
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 1 deletion.
146 changes: 146 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ class GitHubActionsInput(str, Enum):
STRICT = 'INPUT_STRICT'
TEMPLATE = 'INPUT_TEMPLATE'
VARIABLES = 'INPUT_VARIABLES'

def __str__(self):
return self.value
64 changes: 63 additions & 1 deletion unit-tests.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 5a62d10

Please sign in to comment.