Skip to content

Commit

Permalink
Switch from opt-out to opt-in flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrussimon committed Nov 8, 2017
1 parent 63a27be commit d4cb69a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Changes to `requirements.txt` should always be by pull request.
- Add docstrings to all functions with a one-line description of its purpose.

### Format
Ensure that `./test/bin/lint.sh api` exits without errors.
Ensure that `./tests/bin/run-tests-docker.sh -- -l` exits without errors.

### Commit Messages
1. The subject line should be a phrase describing the commit and limited to 50 characters
Expand Down
12 changes: 7 additions & 5 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Run automated tests:
./test/bin/setup-integration-tests-ubuntu.sh
./test/bin/run-tests-ubuntu.sh
```
* To skip linting, use `--no-lint` (`-L`)
* To skip unit tests, use `--no-unit` (`-U`)
* To skip integration tests, use `--no-integ` (`-I`)
* To skip abao tests, use `--no-abao` (`-A`)
All tests are executed by default. Subsets can be run using the filtering options:

* To run linting, use `--lint` (`-l`)
* To run unit tests, use `--unit` (`-u`)
* To run integration tests, use `--integ` (`-i`)
* To run abao tests, use `--abao` (`-a`)
* To pass any arguments to `py.test`, use `-- PYTEST_ARGS`

See [py.test usage](https://docs.pytest.org/en/latest/usage.html) for more.
Expand All @@ -27,7 +29,7 @@ Build scitran-core image and run automated tests in a docker container:
#### Example
Without rebuilding the image, run only integration tests matching `foo`, use the highest verbosity level for test output and jump into a python debugger session in case an assertion fails:
```
./tests/bin/run-tests-docker.sh -B -- -L -U -A -- -k foo -vvv --pdb
./tests/bin/run-tests-docker.sh -B -- -i -- -k foo -vvv --pdb
```

### Tools
Expand Down
4 changes: 2 additions & 2 deletions tests/bin/run-tests-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ function main() {
shift
done

trap clean_up EXIT

if ${DOCKER_BUILD}; then
echo "Building scitran-core:run-tests ..."
docker build -t scitran-core:run-tests .
fi

trap clean_up EXIT

docker network create scitran-core-test-network

# Launch Mongo instance
Expand Down
55 changes: 31 additions & 24 deletions tests/bin/run-tests-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ Run scitran-core tests
Usage:
$0 [OPTION...]
Runs linting and all tests if no options are provided.
Runs subset of tests when using the filtering options.
Displays coverage report if all tests ran and passed.
Options:
-L, --no-lint Skip linting
-U, --no-unit Skip unit tests
-I, --no-integ Skip integration tests
-A, --no-abao Skip abao tests
-R, --no-report Skip coverage report
-h, --help Print this help and exit
-- PYTEST_ARGS Arguments passed to py.test
-l, --lint Run linting
-u, --unit Run unit tests
-i, --integ Run integration tests
-a, --abao Run abao tests
-h, --help Print this help and exit
-- PYTEST_ARGS Arguments passed to py.test
Envvars:
SCITRAN_PERSISTENT_DB_PORT (9001)
Expand All @@ -33,31 +36,35 @@ EOF


function main() {
local RUN_LINT=true
local RUN_UNIT=true
local RUN_INTEG=true
local RUN_ABAO=true
export RUN_ALL=true
local RUN_LINT=false
local RUN_UNIT=false
local RUN_INTEG=false
local RUN_ABAO=false
local PYTEST_ARGS=

export RUN_REPORT=true

while [[ "$#" > 0 ]]; do
case "$1" in
-L|--no-lint) RUN_LINT=false ;;
-U|--no-unit) RUN_UNIT=false ;;
-I|--no-integ) RUN_INTEG=false ;;
-A|--no-abao) RUN_ABAO=false ;;
-R|--no-report) RUN_REPORT=false ;;
-h|--help) usage; exit 0 ;;
--) PYTEST_ARGS="${@:2}"; break ;;
-l|--lint) RUN_ALL=false; RUN_LINT=true ;;
-u|--unit) RUN_ALL=false; RUN_UNIT=true ;;
-i|--integ) RUN_ALL=false; RUN_INTEG=true ;;
-a|--abao) RUN_ALL=false; RUN_ABAO=true ;;
-h|--help) usage; exit 0 ;;
--) PYTEST_ARGS="${@:2}"; break ;;
*) echo "Invalid argument: $1" >&2; usage; exit 1 ;;
esac
shift
done

if ! (${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG} && ${RUN_ABAO}); then
# Skip coverage report if any tests are skipped
RUN_REPORT=false
if ${RUN_ALL}; then
# No filtering options used, run everything by default
RUN_LINT=true
RUN_UNIT=true
RUN_INTEG=true
RUN_ABAO=true
elif ${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG} && ${RUN_ABAO}; then
# All filtering options were used, the same as none
RUN_ALL=true
fi

trap clean_up EXIT
Expand Down Expand Up @@ -164,7 +171,7 @@ function clean_up () {
wait 2> /dev/null
fi

if ${RUN_REPORT} && [[ "${TEST_RESULT_CODE}" == "0" ]]; then
if ${RUN_ALL} && [[ "${TEST_RESULT_CODE}" == "0" ]]; then
echo
echo "UNIT TEST COVERAGE:"
coverage report --skip-covered
Expand Down

0 comments on commit d4cb69a

Please sign in to comment.