fdtd
fdtd copied to clipboard
Tests
The library needs tests to prevent bugs. This library uses pytest as test suite, which is by far the most user friendly test-suite for Python. This is great, because this means anyone can add tests; it's super easy! Moreover, it makes you acquainted with the code, which is why it's labeled a good first issue.
When adding tests, keep the following in mind:
- Add tests to the right file in the tests folder
- Each test case should be a function with a name starting with
test_
- Try to test only one single thing (a single assert) in each test case
- When repeating code over multiple tests, try to use pytest fixtures.
- Try to make the name of what you're testing as explicit as possible
- In case the function of a test is not clear from its name, add a docstring.
- Try to set a value for each argument and keyword argument. The default values might (and probably will) change, setting the values explicitly probably increases the lifetime of a test.
- Use black to typeset your code:
pip install black
black tests
- Never test floats directly; always use
pytest.approx
and similar. - Use common sense values when creating tests.
When running the tests:
- Make sure the fdtd library is in your path
- The easiest way to make this happen is by installing the library via
pip install -e
:pip uninstall fdtd # uninstall any previous version of the fdtd library git clone https://github.com/flaport/fdtd # if not cloned yet, clone the repository now. pip install -e fdtd # install as a development library
- When installed this way, pip will link this local version of the fdtd library into your python path; any change in this development library will from now on be reflected in the version you import by default with python.
- Note that
pip install -e
is executed in the folder containing the git repository NOT inside the git repository.
- The easiest way to make this happen is by installing the library via
- Now, from inside the git repository, run
pytest tests
- Or, if you want a coverage report (requires
pytest-cov
)pytest tests --cov-report html --cov fdtd
- The coverage report can be found in the newly created
htmlcov
folder.
- The coverage report can be found in the newly created