Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: add coverage report #253

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ dist
# Terraform
.terraform
*.tfstate.backup

# Coverage results
*.coverage
test/coverage/results/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ include vars.mk
.PHONY: check
check: environment
pipenv run yapf -rd .
rm -rf test/coverage/results
mkdir test/coverage/results
$(MAKE) -C cli check
$(MAKE) -C services/controller check
BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) python3 test/run.py
RUN_WITH_COVERAGE=yes BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) python3 test/run.py
pipenv run test/coverage/coverage_report.sh
terraform fmt -check

.PHONY: format
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
coverage = "*"

[dev-packages]
yapf = "*"
Expand Down
42 changes: 40 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN python setup.py bdist_wheel
FROM python:3.6

COPY --from=builder /cli/dist/plz_cli-0.1.0-py3-none-any.whl /tmp/
RUN pip install /tmp/plz_cli-0.1.0-py3-none-any.whl
RUN pip install --find-links /tmp/ plz_cli[test]

ENV PYTHONUNBUFFERED 1
ENTRYPOINT ["plz"]
2 changes: 1 addition & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ check: test lint

.PHONY: test
test: environment
pipenv run nosetests
COVERAGE_FILE=../test/coverage/results/cli_nose_tests.coverage pipenv run coverage run --source=. -m nose
3 changes: 2 additions & 1 deletion cli/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ python_version = "3.6"

[packages]
"e1839a8" = {path = ".", editable = true}
yapf = "*"

[dev-packages]
flake8 = "*"
flask = "*"
nose = "*"
coverage = "*"
yapf = "*"
55 changes: 46 additions & 9 deletions cli/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
],
extras_require={
'test': [
'flake8==3.5.0',
'nose==1.3.7',
'flake8>=3.5.0',
'nose>=1.3.7',
'flask >= 1.0.2',
'coverage >= 4.5.3',
],
},
entry_points={
Expand Down
2 changes: 1 addition & 1 deletion services/controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ ARG BUILD_TIMESTAMP=0

RUN echo -n $BUILD_TIMESTAMP > ./src/plz/controller/BUILD_TIMESTAMP

HEALTHCHECK --interval=5s CMD curl -f http://localhost/
HEALTHCHECK --interval=5s --start-period=60s CMD curl -f http://localhost/

ENTRYPOINT ["/tini", "--", "./run"]
5 changes: 3 additions & 2 deletions services/controller/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pyhocon = "*"
urllib3 = ">=1.24.2"
redis = "*"
requests = ">=2.20.0"
yapf = "*"

[dev-packages]
"flake8" = "*"
coverage = "*"
flake8 = "*"
yapf = "*"
67 changes: 52 additions & 15 deletions services/controller/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions services/controller/run
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ if [[ "${CREATE_AWS_RESOURCES:-}" ]]; then
python src/plz/controller/utils/create_aws_resources.py
fi

exec gunicorn \
--bind="0.0.0.0:${PORT}" \
--workers=16 \
--timeout=2000 \
--pythonpath="${PYTHONPATH}" \
--capture-output \
--log-level="${LOG_LEVEL}" \
plz.controller.main:app \
-- $@
if [[ "${RUN_WITH_COVERAGE:-}" ]]; then
pipenv install --dev --system --deploy
COVERAGE_FILE=controller.coverage exec coverage run \
--source=. src/plz/controller/main.py
else
exec gunicorn \
--bind="0.0.0.0:${PORT}" \
--workers=16 \
--timeout=2000 \
--pythonpath="${PYTHONPATH}" \
--capture-output \
--log-level="${LOG_LEVEL}" \
plz.controller.main:app \
-- $@;
fi
4 changes: 2 additions & 2 deletions services/controller/src/plz/controller/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests
from flask import Flask, Response, abort, jsonify, request, stream_with_context

import plz.controller
from plz.controller import configuration
from plz.controller.api.exceptions import AbortedExecutionException, \
InstanceNotRunningException, JSONResponseException, \
Expand Down Expand Up @@ -40,8 +41,7 @@ def _setup_logging():
print(f'Setting log level to: {log_level}',
file=sys.stderr,
flush=True)
controller_logger = logging.getLogger('.'.join(
__name__.split('.')[:-1]))
controller_logger = logging.getLogger(plz.controller.__name__)
controller_logger.setLevel(log_level)


Expand Down
Loading