-
Notifications
You must be signed in to change notification settings - Fork 66
Designing tests
To get doctest to work smoothly with PyCharm, have a look at François Durand's toy package.
Tests serve two distinct purposes in Scikit-network, there are:
-
functional tests which aim at ensuring that the code is running as intended. This makes it possible to develop new features while making sure all previous features still yield correct results.
-
examples which aim at providing the user with the intended use of a function.
Functional tests should be located in a folder named test
at the same level as their related module.
Such tests are defined using the unittest.TestCase
object.
Examples should be located in the doc next to the function at stake, using the doctest package.
Examples mainly consist of a copy of a console output:
>>> a = 1 # defining variables
>>> print(a) # test input
1 # expected output
Doctest then handles the tests on its own.
- Make sure that the outputs of your tests do not vary from one machine to another when using doctest (especially if the output of your function is a NumPy array). For instance when running some command
f(x)
, you might expectarray([0,1,2])
as a result with a Linux machine as opposed toarray([0,1,2], dtype=int64)
on a Windows machine. This makes it difficult to define such a test with doctest. To circumvent this issue, consider using the following structure:(f(x) == np.array([0,1,2])).all()
and expectTrue
to be returned.