Skip to content

Commit

Permalink
Added an easy script to run all the tests and checks locally (#725)
Browse files Browse the repository at this point in the history
Signed-off-by: Maria Masha Shugrina <mshugrina@nvidia.com>
Co-authored-by: Maria Masha Shugrina <mshugrina@nvidia.com>
  • Loading branch information
shumash and Maria Masha Shugrina committed May 26, 2023
1 parent 1834e57 commit e3716b2
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[html]
directory = .test_coverage
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _*/
# generated folders
kaolin/version.py
build/
build_docs/
kaolin.egg-info
*.so
*.egg
Expand All @@ -31,4 +32,9 @@ node_modules/
.vscode/settings.json
.vscode/tasks.json
*.sw*
*.ipynb_checkpoints

# tests
.test_logs/
.test_coverage/
.coverage
60 changes: 39 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Contributing guidelines

Contributions are welcome!
You can send us pull requests to help improve Kaolin, if you are just getting started, Gitlab has a [how to](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html).

Kaolin team members will be assigned to review your pull requests. Once your change passes the review and the continuous integration checks, a Kaolin member will approve and merge them to the repository.

If you want to contribute, [Gitlab issues](https://gitlab-master.nvidia.com/Toronto_DL_Lab/kaolin-reformat/-/issues) are a good starting point, especially the ones with the label [good first issue](https://gitlab-master.nvidia.com/Toronto_DL_Lab/kaolin-reformat/-/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=good%20first%20issue). If you started working on a issue, leave a comment so other people know that you're working on it, you can also coordinate with others on the issue comment threads.

## Pull Request Checklist

Before sending your pull requests, make sure you followed this list.
Expand All @@ -16,33 +23,54 @@ Before sending your pull requests, make sure you followed this list.

6) Send your Pull Request to the `master` branch

## How to become a contributor and submit your own code
## Guidelines for Contributing Code

### Running tests

In order to verify that your change does not break anything, a number of checks must be
passed. For example, running unit tests, making sure that all example
notebooks and recipes run without error, and docs build correctly. For unix-based
system, we provide a script to execute all of these tests locally:

```
pip install -r tools/ci_requirements.txt
pip install -r tools/doc_requirements.txt
bash tools/linux/run_tests.sh all
```

If you also want to run integration tests, see [tests/integration/](tests/integration/), specifically
[Dash3D tests](tests/integration/experimental/dash3d/README.md).

### Documentation

All new additions to the Kaolin API must be properly documented. Additional information
on documentation is provided in [our guide](docs/README.md).


### Signing your commits
Before we can take your patches we need to take care of legal concerns.

Please sign each commits using ``git commit -s``.
In case you forgot to sign previous commits you can amend previous commits using:
All commits must be signed using ``git commit -s``.
If you forgot to sign previous commits you can amend them as follows:
* ``git commit -s --amend`` for the last commit.
* ``git rebase --signoff`` for all the commits of your pull request.

### Contributing code
Contributions are welcome!
You can send us pull requests to help improve Kaolin, if you are just getting started, Gitlab has a [how to](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html).

Kaolin team members will be assigned to review your pull requests. Once they your change passes the review and the continuous integration checks, a Kaolin member will approve and merge them to the repository.

If you want to contribute, [Gitlab issues](https://gitlab-master.nvidia.com/Toronto_DL_Lab/kaolin-reformat/-/issues) are a good starting point, especially the ones with the label [good first issue](https://gitlab-master.nvidia.com/Toronto_DL_Lab/kaolin-reformat/-/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=good%20first%20issue). If you started working on a issue, leave a comment so other people know that you're working on it, you can also coordinate with others on the issue comment threads.

### Standards and Coding Style
#### General guidelines
* New features must include unit tests which help guarantee correctness in the present and future.
* API changes should be minimal and backward compatible. Any changes that break backward compatibility should be carefully considered and tracked so that they can be included in the release notes.
* New features may not accepted if the cost of maintenance is too high in comparison of its benefit, they may also be integrated to contrib subfolders for minimal support and maintenance before eventually being integrated to the core.

#### Writing Tests
All tests should use [pytest](https://docs.pytest.org/en/latest/) and [pytest-cov](https://pytest-cov.readthedocs.io/en/latest/) frameworks. The tests should be placed in [tests/python directory](tests/python/), which should follows the directory structure of [kaolin](kaolin/). For example,
test for `kaolin/io/obj.py` should be placed into `tests/pyhon/kaolin/io/test_obj.py`.

#### License
Include a license at the top of new files.



##### C/C++/CUDA
```cpp
// Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
Expand Down Expand Up @@ -241,14 +269,4 @@ On top of that we use prefixes (``packed\_``, ``padded\_``) to indicate that a m

[tests/python/kaolin/](tests/python/kaolin) should follows the same directory structure of [kaolin/](kaolin/). E.g. each module kaolin/path/to/mymodule.py should have a corresponding tests/python/kaolin/path/to/test\_mymodule.py.

#### Tests
We are applying [pytest](https://docs.pytest.org/en/latest/) on [tests/python directory](tests/python/), with [pytest-cov](https://pytest-cov.readthedocs.io/en/latest/), which should follows the directory structure of [kaolin](kaolin/).
To run these tests execute ``pytest --cov=kaolin/ tests/`` from the [root of kaolin](https://gitlab-master.nvidia.com/Toronto_DL_Lab/kaolin-reformat).

Additional integration tests are located in [tests/integration](tests/integration).
See that subdirectory for details.

#### Documentation
Contributors are encouraged to verify the generated documentation before each pull request.

To build your own documentation, follow the [guide](docs/README.md).
1 change: 1 addition & 0 deletions tools/ci_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ flake8-mypy==17.8.0
flake8-pyi==19.3.0
pytest==7.1.0
pytest-cov==3.0.0
nbmake==1.4.1
jupyter
175 changes: 175 additions & 0 deletions tools/linux/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#!/bin/bash
set -o nounset

USAGE="$0 <type of test(optional)>
Run some or all Kaolin tests, saving logs to file. Summary
will be printed at the end.
To ensure everything passes, export variables such as:
export KAOLIN_TEST_SHAPENETV2_PATH=/path/to/local/shapenet
To run all tests:
bash $0 all
To run only pytest tests:
bash $0 pytest
To run only notebooks:
bash $0 notebook
To run only recipes:
bash $0 recipes
To build the docs:
bash $0 docs
"

if [ $# -ne 1 ]; then
echo -e "$USAGE"
exit 1
fi

export CLI_COLOR=1
RED='\033[1;31m'
GREEN='\033[1;32m'
NOCOLOR='\033[0m'


SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KAOLIN_ROOT=$SCRIPT_DIR/../..
cd $KAOLIN_ROOT
KAOLIN_ROOT=`pwd`

LOG_DIR=$KAOLIN_ROOT/.test_logs
mkdir -p $LOG_DIR

RUN_PYTEST=0
RUN_NOTEBOOK=0
RUN_RECIPES=0
BUILD_DOCS=0
if [ $1 == "all" ]; then
RUN_PYTEST=1
RUN_NOTEBOOK=1
RUN_RECIPES=1
BUILD_DOCS=1
elif [ $1 == "pytest" ]; then
RUN_PYTEST=1
elif [ $1 == "notebook" ]; then
RUN_NOTEBOOK=1
elif [ $1 == "recipes" ]; then
RUN_RECIPES=1
elif [ $1 == "docs" ]; then
BUILD_DOCS=1
else
echo "$RED Unknown argument type $1 $NOCOLOR"
echo -e "$USAGE"
exit 1
fi

start_test_info() {
echo "***********************************************"
echo " Running $1 Tests "
echo "***********************************************"
echo
echo " ...running, see log: $LOG_DIR/log_$1.txt"
}

STATUS=0
end_test_info() {
if [ $1 -ne 0 ]; then
STATUS=1
echo -e "$RED FAILED: $NOCOLOR $2"
else
echo -e "$GREEN SUCCESS: $NOCOLOR $2"
fi
echo
}

maybe_open_url() {
which xdg-open
if [ $? -eq 0 ]; then
xdg-open $1
fi
}

PYTEST_LOG=$LOG_DIR/log_pytest.txt
if [ $RUN_PYTEST -eq "1" ]; then
echo "" > $PYTEST_LOG
start_test_info "pytest"

CMDLINE="pytest --import-mode=importlib --cov=kaolin -s --cov-report=html --cov-report term-missing tests/python/"
$CMDLINE >> $PYTEST_LOG 2>&1
RES=$?
COV_URL=".test_coverage/index.html"
echo " HTML line-by-line test coverage available in $COV_URL"
end_test_info $RES "$CMDLINE"
maybe_open_url $COV_URL >> $PYTEST_LOG 2>&1
fi


NOTEBOOK_LOG=$LOG_DIR/log_notebook.txt
if [ $RUN_NOTEBOOK -eq "1" ]; then
echo "" > $NOTEBOOK_LOG
start_test_info "notebook"

CMDLINE="pytest --nbmake --nbmake-timeout=3000 examples/**/*.ipynb"
$CMDLINE >> $NOTEBOOK_LOG 2>&1

end_test_info $? "$CMDLINE"
fi

RECIPES_LOG=$LOG_DIR/log_recipes.txt
if [ $RUN_RECIPES -eq "1" ]; then
echo "" > $RECIPES_LOG
start_test_info "recipes"

NFAIL=0
NPASS=0

cd $KAOLIN_ROOT/examples/recipes
for F in $(find . -name "*.py"); do

echo "Executing python $F" >> $RECIPES_LOG
python $F >> $RECIPES_LOG 2>&1
RES=$?
if [ $RES -ne 0 ]; then
echo -e "$RED failed : $NOCOLOR python $F"
NFAIL=$((NFAIL+1))
else
echo -e "$GREEN success: $NOCOLOR python $F"
NPASS=$((NPASS+1))
fi
done

end_test_info $NFAIL "python examples/recipes/**/*.py"
fi


DOCS_LOG=$LOG_DIR/log_docs.txt
if [ $BUILD_DOCS -eq "1" ]; then
echo "" > $DOCS_LOG
start_test_info "docs"

cd $KAOLIN_ROOT
rm -rf $KAOLIN_ROOT/docs/_build

echo " ...copying docs/ to build_docs/ to avoid git confusion" >> $DOCS_LOG 2>&1
mkdir -p build_docs
cp -r docs/* build_docs/.
cd build_docs
echo " ...replacing DOCS_MODULE_PATH in build_docs/kaolin_ext.py" >> $DOCS_LOG 2>&1
sed -i 's/"docs"/"build_docs"/g' kaolin_ext.py >> $DOCS_LOG 2>&1

echo " ...building docs in build_docs dir" >> $DOCS_LOG 2>&1
CMDLINE="python -m sphinx -T -E -W --keep-going -b html -d _build/doctrees -D language=en . _build/html"
$CMDLINE >> $DOCS_LOG 2>&1
RES=$?

cd $KAOLIN_ROOT
DOCS_URL="build_docs/_build/html/index.html"
echo " HTML written to $DOCS_URL"

end_test_info $RES "$CMDLINE"
maybe_open_url $DOCS_URL >> $DOCS_LOG 2>&1
fi

0 comments on commit e3716b2

Please sign in to comment.