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

Add unit tests #81

Open
felixbur opened this issue Oct 5, 2023 · 1 comment
Open

Add unit tests #81

felixbur opened this issue Oct 5, 2023 · 1 comment

Comments

@felixbur
Copy link
Owner

felixbur commented Oct 5, 2023

Here is an example

  • Add test parameters
  • Test for expected value
  • Add tests/test_to_db.py:
import numpy as np
import pytest

import spmath


@pytest.mark.parametrize(
    'x, expected_y',
    [
        (2, 6.0206),
        (.5, -6.0206),
        (0, -np.Inf),
        (-1, np.nan),
    ],
)
def test_to_db(x, expected_y):
    y = spmath.to_db(x)
    np.testing.assert_allclose(y, expected_y)
@bagustris
Copy link
Collaborator

bagustris commented Oct 11, 2024

Since Nkululeko is mainly a collection of Python CLI (not imported as modules), with argparse and configparser, the conventional way to use Python test is little bit difficult. There is a discussion here with many proposed solutions.

https://stackoverflow.com/questions/13493288/python-cli-program-unit-testing

With the current test using bash shell for each module, it will become very difficult in the future to test all functionalities. But test is a must. We should try or choose options than the current shell test. Perhaps to try pytest as you showed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants