-
Notifications
You must be signed in to change notification settings - Fork 5
Colocate tests w/ objects tested; switch from unittest to pytest #89
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
Changes from all commits
5775973
e375013
7ad6114
5e0bd60
ede331b
e75aa74
4bc3764
bc1e655
7547e7e
6678a5e
ea74a84
087ec50
b45be9e
a4f3ba9
7cefe06
7861eb9
da4080e
cbc64b5
b441ae4
43e34c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,26 +2,30 @@ name: "Testing" | |
|
|
||
| on: | ||
| push: | ||
| paths-ignore: | ||
| - 'tutorials/**' | ||
| - 'README.md' | ||
| - '.gitignore' | ||
| - 'examples/**' | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python all python version | ||
| uses: actions/setup-python@v2 | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: 3.9 | ||
| python-version: 3.11 | ||
| architecture: x64 | ||
|
|
||
| - name: Install dependencies | ||
| run: pip install -r requirements.txt | ||
| run: | | ||
| python -m venv --upgrade-deps .venv | ||
| source .venv/bin/activate | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using a |
||
| pip install -r requirements.txt | ||
| pip install -r requirements-dev.txt | ||
|
|
||
| - name: Run Test | ||
| run: python -m unittest discover tests -v | ||
| run: | | ||
| source .venv/bin/activate | ||
| python -m pytest . | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # OS specific | ||
| .DS_Store | ||
|
|
||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
| *.py[cod] | ||
|
|
@@ -130,3 +133,4 @@ dmypy.json | |
|
|
||
| # data | ||
| raw_data | ||
| data | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this because that is where the tutorial and example notebooks often look. We could also rename all of those hardcoded paths to "raw_data" and not add a "data" field here. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import pytest | ||
| import torch | ||
|
|
||
| from sparsecoding.test_utils import ( | ||
| bars_datas_fixture, | ||
| bars_datasets_fixture, | ||
| bars_dictionary_fixture, | ||
| dataset_size_fixture, | ||
| patch_size_fixture, | ||
| priors_fixture, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def set_seed(): | ||
| torch.manual_seed(1997) | ||
|
|
||
|
|
||
| # We import and define all fixtures in this file. | ||
| # This allows users to avoid any dependency fixtures. | ||
| # NOTE: This means pytest should only be run from this directory. | ||
| __all__ = [ | ||
| "bars_datas_fixture", | ||
| "bars_datasets_fixture", | ||
| "bars_dictionary_fixture", | ||
| "dataset_size_fixture", | ||
| "patch_size_fixture", | ||
| "priors_fixture", | ||
| "set_seed", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,41 @@ | ||
| # Contributing | ||
|
|
||
| All contributions are welcome! | ||
|
|
||
| ## Bug Reporting | ||
| If you find a bug, submit a bug report on GitHub Issues. | ||
|
|
||
| If you find a bug, submit a bug report on GitHub Issues. | ||
|
|
||
| ## Adding Features/Fixing Bugs | ||
|
|
||
| If you have identified a new feature or bug that you can fix yourself, please follow the following procedure. | ||
|
|
||
| 1. Clone `main` branch. | ||
| 2. Create a new branch to contain your changes. | ||
| 2. `add`, `commit`, and `push` your changes to this branch. | ||
| 3. Create a pull request (PR). See more information on submitting a PR request below. | ||
| 1. Fork `main` branch. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cloning does not work because outside people do not have write permission. One has to fork to contribute, which is standard practice for open-source repos. |
||
| 2. Create a new branch to contain your changes. | ||
| 3. `add`, `commit`, and `push` your changes to this branch. | ||
| 4. Create a pull request (PR). See more information on submitting a PR request below. | ||
|
|
||
| ### Submitting a Pull Request | ||
| 1. If necessary, please **write your own unit tests** and add them to [the tests directory](https://github.com/rctn/sparsecoding/blob/main/docs/contributing.md). | ||
| 2. Verify that all tests are passed by running `python -m unittest tests/*`. | ||
| 3. Be sure that your PR follows formatting guidelines, [PEP8](https://peps.python.org/pep-0008/) and [flake8](https://flake8.pycqa.org/en/latest/). | ||
| 4. Make sure the title of your PR summarizes the features/issues resolved in your branch. | ||
| 5. Submit your pull request and add reviewers. | ||
|
|
||
| 1. If necessary, please **write your own unit tests** and place them near the code being tested. High-level tests, such as integration or example tests can be placed in the top-level "tests" folder. | ||
| 2. Verify that all tests are passed by running `python -m pytest .`. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using |
||
| 3. Be sure that your PR follows formatting guidelines, [PEP8](https://peps.python.org/pep-0008/) and [flake8](https://flake8.pycqa.org/en/latest/). | ||
| 4. Make sure the title of your PR summarizes the features/issues resolved in your branch. | ||
| 5. Submit your pull request and add reviewers. | ||
|
|
||
| ## Coding Style Guidelines | ||
| The following are some guidelines on how new code should be written. Of course, there are special cases, and there will be exceptions to these rules. | ||
|
|
||
| The following are some guidelines on how new code should be written. Of course, there are special cases, and there will be exceptions to these rules. | ||
|
|
||
| 1. Format code in accordance with [flake8](https://flake8.pycqa.org/en/latest/) standard. | ||
| 2. Use underscores to separate words in non-class names: `n_samples` rather than `nsamples`. | ||
| 3. Avoid single-character variable names. | ||
|
|
||
| ## Docstrings | ||
|
|
||
| When writing docstrings, please follow the following example. | ||
|
|
||
| ``` | ||
| ```py | ||
| def count_beans(self, baz, use_gpu=False, foo="vector" | ||
| bar=None): | ||
| """Write a one-line summary for the method. | ||
|
|
@@ -69,4 +75,4 @@ def count_beans(self, baz, use_gpu=False, foo="vector" | |
| quantum-mechanical description of physical reality be | ||
| considered complete?. Physical review, 47(10), 777. | ||
| """ | ||
| ``` | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| pylint | ||
| pytest | ||
| pyright |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will now run the tests after the PR was merged, which is a good failsafe for the production branch (
main)