Skip to content
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

Tests #7

Open
flaport opened this issue Oct 14, 2019 · 0 comments
Open

Tests #7

flaport opened this issue Oct 14, 2019 · 0 comments
Labels
good first issue Good for newcomers

Comments

@flaport
Copy link
Owner

flaport commented Oct 14, 2019

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.
  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant