diff --git a/Dockerfile b/Dockerfile index f44b8ea..0aeb573 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,12 +17,12 @@ ENTRYPOINT ["/python/entrypoint.sh"] # Add convenient aliases # Install python packages -RUN echo "#!/bin/bash\n/python/entrypoint.sh startapp" >> /bin/startapp && chmod a+x /bin/startapp &&\ - echo "#!/bin/bash\n/python/entrypoint.sh developapp" >> /bin/developapp && chmod a+x /bin/developapp &&\ - echo "#!/bin/bash\n/python/entrypoint.sh validatecode" >> /bin/validatecode && chmod a+x /bin/validatecode &&\ - echo "#!/bin/bash\n/python/entrypoint.sh validatecodeonce" >> /bin/validatecodeonce && chmod a+x /bin/validatecodeonce &&\ - echo "#!/bin/bash\n/python/entrypoint.sh runtests" >> /bin/runtests && chmod a+x /bin/runtests &&\ - pip install -r /python/requirements.txt +RUN echo "#!/bin/bash\n/python/entrypoint.sh startapp \$@" >> /bin/startapp && chmod a+x /bin/startapp \ + && echo "#!/bin/bash\n/python/entrypoint.sh developapp \$@" >> /bin/developapp && chmod a+x /bin/developapp \ + && echo "#!/bin/bash\n/python/entrypoint.sh validatecode \$@" >> /bin/validatecode && chmod a+x /bin/validatecode \ + && echo "#!/bin/bash\n/python/entrypoint.sh validatecodeonce \$@" >> /bin/validatecodeonce && chmod a+x /bin/validatecodeonce \ + && echo "#!/bin/bash\n/python/entrypoint.sh runtests \$@" >> /bin/runtests && chmod a+x /bin/runtests \ + && pip install -r /python/requirements.txt # Change users USER python diff --git a/README.md b/README.md index 2532c51..a275f59 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,16 @@ plugin. This code validation command executes the `/python/test_suite.sh` script which can be overwritten with custom code validation. +Options:\ +`-h` Print help menu. +``` +validatecode -h +``` +`-k` Invoke Pytest option `-k` to run specific tests based on a substring match to the test name. +``` +validatecode -k test_get_products +``` + ### `validatecodeonce` Same as `validatecode` but executed once rather than continously running on @@ -135,6 +145,16 @@ code change. This can be used for CI/CD purposes since it generates report files in the `/python/reports` folder. +Options:\ +`-h` Print help menu. +``` +validatecodeonce -h +``` +`-k` Invoke Pytest option `-k` to run specific tests based on a substring match to the test name. +``` +validatecodeonce -k test_get_products +``` + ### `runtests` (DEPRECATED) **DEPRECATED**: Use `validatecodeonce` instead diff --git a/entrypoint.sh b/entrypoint.sh index bfdabd1..f9d5629 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,17 +45,56 @@ developapp() { validatecode() { + help() { + echo + echo "Usage: validatecode [-h|k]" + echo + echo "Automatically run code validation whenever the code changes." + echo + echo "Options:" + echo "h Print this help menu." + echo "k Invoke Pytest option -k to run specific tests based on a substring match to the test name." + echo + } + + while getopts ":h" option; do + case $option in + h) + help + exit;; + esac + done + echo -e "\nREADY TO RUN THE CODE VALIDATION SUITE\nSave a python file to trigger the checks." - loadconfig - watchmedo shell-command --patterns="*.py;*.txt" --recursive --command="/python/test_suite.sh" --drop . + watchmedo shell-command --patterns="*.py;*.txt" --recursive --command="/python/test_suite.sh \$@" --drop . } validatecodeonce() { + help() { + echo + echo "Usage: validatecodeonce [-h|k]" + echo + echo "Trigger a single run of code validation." + echo + echo "Options:" + echo "h Print this help menu." + echo "k Invoke Pytest option -k to run specific tests based on a substring match to the test name." + echo + } + + while getopts ":h" option; do + case $option in + h) + help + exit;; + esac + done + echo -e "\nTriggering single run of code validation." loadconfig - ../test_suite.sh reports + ../test_suite.sh $@ reports } diff --git a/test_suite.sh b/test_suite.sh index 7bc5327..4fb4e9a 100755 --- a/test_suite.sh +++ b/test_suite.sh @@ -3,6 +3,12 @@ REPORTS_FOLDER="/python/reports/" SECTION_PREFIX="\n#########" +while getopts ":k:" option; do + case $option in + k) + SPECIFIC_TESTS="-k ${OPTARG}" + esac +done reportvalidation() { if [ -z "$1" ] @@ -26,7 +32,7 @@ fi echo -ne "$SECTION_PREFIX RUN TESTS:\n\n" -python -m pytest -vv --durations=3 --cov ./ --cov-report term-missing $PYTEST_REPORTS; STATUS1=$? +python -m pytest -vv --durations=3 --cov ./ --cov-report term-missing $PYTEST_REPORTS $SPECIFIC_TESTS; STATUS1=$? echo -ne "$SECTION_PREFIX CHECK TYPING: " MYPYOUT=`mypy --no-error-summary . $MYPY_REPORTS` diff --git a/tests/webapp/main.py b/tests/webapp/main.py index 678aff5..eb2d891 100644 --- a/tests/webapp/main.py +++ b/tests/webapp/main.py @@ -5,4 +5,5 @@ @app.get('/') async def root(): + """A simple Hello World endpoint""" return {'message': 'Hello World'}