felixbur / nkululeko

Machine learning speaker characteristics
MIT License
32 stars 5 forks source link

Add unit tests #81

Open felixbur opened 1 year ago

felixbur commented 1 year ago

Here is an example

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 commented 1 month ago

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.