Skip to content

Commit

Permalink
Use a separate varaible for controlling tests
Browse files Browse the repository at this point in the history
**What**
- add TEST_ENABLED build-arg to control if the tests are run or not.
  Should be easier to document and debug in the future.
- Copy the implementation to all of the python3 templates

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored and alexellis committed Mar 25, 2021
1 parent 19512d2 commit 91271bc
Show file tree
Hide file tree
Showing 23 changed files with 309 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

9 changes: 9 additions & 0 deletions template/python3-flask-armhf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ WORKDIR /home/app/
USER root
COPY function function
RUN chown -R app:app ./

ARG TEST_COMMAND=tox
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then \
echo "skipping tests";\
else \
eval "$TEST_COMMAND"; \
fi

USER app

ENV fprocess="python index.py"
Expand Down
10 changes: 10 additions & 0 deletions template/python3-flask-armhf/function/handler_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .handler import handle

# Test your handler here

# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args

def test_handle():
# assert handle("input") == "input"
pass
41 changes: 41 additions & 0 deletions template/python3-flask-armhf/function/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# If you would like to disable
# automated testing during faas-cli build,

# Replace the content of this file with
# [tox]
# skipsdist = true

# You can also edit, remove, or add additional test steps
# by editing, removing, or adding new testenv sections


# find out more about tox: https://tox.readthedocs.io/en/latest/
[tox]
envlist = lint,test
skipsdist = true

[testenv:test]
deps =
flask
pytest
-rrequirements.txt
commands =
# run unit tests with pytest
# https://docs.pytest.org/en/stable/
# configure by adding a pytest.ini to your handler
pytest

[testenv:lint]
deps =
flake8
commands =
flake8 .

[flake8]
count = true
max-line-length = 127
max-complexity = 10
statistics = true
# stop the build if there are Python syntax errors or undefined names
select = E9,F63,F7,F82
show-source = true
2 changes: 1 addition & 1 deletion template/python3-flask-armhf/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flask
waitress

tox==3.*
8 changes: 8 additions & 0 deletions template/python3-flask-debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ USER root
COPY function function
RUN chown -R app:app ./

ARG TEST_COMMAND=tox
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then \
echo "skipping tests";\
else \
eval "$TEST_COMMAND"; \
fi

#configure WSGI server and healthcheck
USER app

Expand Down
10 changes: 10 additions & 0 deletions template/python3-flask-debian/function/handler_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .handler import handle

# Test your handler here

# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args

def test_handle():
# assert handle("input") == "input"
pass
41 changes: 41 additions & 0 deletions template/python3-flask-debian/function/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# If you would like to disable
# automated testing during faas-cli build,

# Replace the content of this file with
# [tox]
# skipsdist = true

# You can also edit, remove, or add additional test steps
# by editing, removing, or adding new testenv sections


# find out more about tox: https://tox.readthedocs.io/en/latest/
[tox]
envlist = lint,test
skipsdist = true

[testenv:test]
deps =
flask
pytest
-rrequirements.txt
commands =
# run unit tests with pytest
# https://docs.pytest.org/en/stable/
# configure by adding a pytest.ini to your handler
pytest

[testenv:lint]
deps =
flake8
commands =
flake8 .

[flake8]
count = true
max-line-length = 127
max-complexity = 10
statistics = true
# stop the build if there are Python syntax errors or undefined names
select = E9,F63,F7,F82
show-source = true
2 changes: 1 addition & 1 deletion template/python3-flask-debian/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flask
waitress

tox==3.*
3 changes: 2 additions & 1 deletion template/python3-flask/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ COPY function/ .
RUN chown -R app:app ../

ARG TEST_COMMAND=tox
RUN if [ "x$TEST_COMMAND" = "xoff" ]; then \
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then \
echo "skipping tests";\
else \
eval "$TEST_COMMAND"; \
Expand Down
2 changes: 1 addition & 1 deletion template/python3-flask/function/handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Test your handler here

# To disable testing, you can set the build_arg `TEST_COMMAND=off` on the CLI or in your stack.yml
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args

def test_handle():
Expand Down
9 changes: 9 additions & 0 deletions template/python3-http-armhf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ WORKDIR /home/app/
USER root
COPY function function
RUN chown -R app:app ./

ARG TEST_COMMAND=tox
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then \
echo "skipping tests";\
else \
eval "$TEST_COMMAND"; \
fi

USER app

# Set up of-watchdog for HTTP mode
Expand Down
10 changes: 10 additions & 0 deletions template/python3-http-armhf/function/handler_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .handler import handle

# Test your handler here

# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args

def test_handle():
# assert handle("input") == "input"
pass
41 changes: 41 additions & 0 deletions template/python3-http-armhf/function/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# If you would like to disable
# automated testing during faas-cli build,

# Replace the content of this file with
# [tox]
# skipsdist = true

# You can also edit, remove, or add additional test steps
# by editing, removing, or adding new testenv sections


# find out more about tox: https://tox.readthedocs.io/en/latest/
[tox]
envlist = lint,test
skipsdist = true

[testenv:test]
deps =
flask
pytest
-rrequirements.txt
commands =
# run unit tests with pytest
# https://docs.pytest.org/en/stable/
# configure by adding a pytest.ini to your handler
pytest

[testenv:lint]
deps =
flake8
commands =
flake8 .

[flake8]
count = true
max-line-length = 127
max-complexity = 10
statistics = true
# stop the build if there are Python syntax errors or undefined names
select = E9,F63,F7,F82
show-source = true
3 changes: 2 additions & 1 deletion template/python3-http-armhf/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask
waitress
waitress
tox==3.*
9 changes: 9 additions & 0 deletions template/python3-http-debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ WORKDIR /home/app/
USER root
COPY function function
RUN chown -R app:app ./

ARG TEST_COMMAND=tox
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then \
echo "skipping tests";\
else \
eval "$TEST_COMMAND"; \
fi

USER app

# Set up of-watchdog for HTTP mode
Expand Down
10 changes: 10 additions & 0 deletions template/python3-http-debian/function/handler_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .handler import handle

# Test your handler here

# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args

def test_handle():
# assert handle("input") == "input"
pass
41 changes: 41 additions & 0 deletions template/python3-http-debian/function/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# If you would like to disable
# automated testing during faas-cli build,

# Replace the content of this file with
# [tox]
# skipsdist = true

# You can also edit, remove, or add additional test steps
# by editing, removing, or adding new testenv sections


# find out more about tox: https://tox.readthedocs.io/en/latest/
[tox]
envlist = lint,test
skipsdist = true

[testenv:test]
deps =
flask
pytest
-rrequirements.txt
commands =
# run unit tests with pytest
# https://docs.pytest.org/en/stable/
# configure by adding a pytest.ini to your handler
pytest

[testenv:lint]
deps =
flake8
commands =
flake8 .

[flake8]
count = true
max-line-length = 127
max-complexity = 10
statistics = true
# stop the build if there are Python syntax errors or undefined names
select = E9,F63,F7,F82
show-source = true
3 changes: 2 additions & 1 deletion template/python3-http-debian/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask
waitress
waitress
tox==3.*
8 changes: 8 additions & 0 deletions template/python3-http/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ USER root
COPY function function
RUN chown -R app:app ./

ARG TEST_COMMAND=tox
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then \
echo "skipping tests";\
else \
eval "$TEST_COMMAND"; \
fi

#configure WSGI server and healthcheck
USER app

Expand Down
10 changes: 10 additions & 0 deletions template/python3-http/function/handler_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .handler import handle

# Test your handler here

# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args

def test_handle():
# assert handle("input") == "input"
pass
41 changes: 41 additions & 0 deletions template/python3-http/function/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# If you would like to disable
# automated testing during faas-cli build,

# Replace the content of this file with
# [tox]
# skipsdist = true

# You can also edit, remove, or add additional test steps
# by editing, removing, or adding new testenv sections


# find out more about tox: https://tox.readthedocs.io/en/latest/
[tox]
envlist = lint,test
skipsdist = true

[testenv:test]
deps =
flask
pytest
-rrequirements.txt
commands =
# run unit tests with pytest
# https://docs.pytest.org/en/stable/
# configure by adding a pytest.ini to your handler
pytest

[testenv:lint]
deps =
flake8
commands =
flake8 .

[flake8]
count = true
max-line-length = 127
max-complexity = 10
statistics = true
# stop the build if there are Python syntax errors or undefined names
select = E9,F63,F7,F82
show-source = true
3 changes: 2 additions & 1 deletion template/python3-http/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask
waitress
waitress
tox==3.*

0 comments on commit 91271bc

Please sign in to comment.