Skip to content

Commit

Permalink
Convert tests to use pytest instead of unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
UkuLoskit committed Jul 9, 2024
1 parent 24c50f5 commit 5f9ebbe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
- name: Static analysis
run: ${{ env.RUN }} "git init && git add -A && pre-commit run --all"
- name: Unit Tests
run: ${{ env.RUN }} "cd /project/examples; python -m unittest discover"
run: ${{ env.RUN }} "pytest"

docker_push:
name: docker push
runs-on: ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions examples/test_compare.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
import pytest
import os
import sys
import sympy as sp
import numpy as np
import unittest

if __name__ == '__main__': # generating sympy code
from rednose.helpers.ekf_sym import gen_code
Expand Down Expand Up @@ -83,7 +83,7 @@ def get_R(self, kind, n):
return R


class TestCompare(unittest.TestCase):
class TestCompare:
def test_compare(self):
np.random.seed(0)

Expand Down Expand Up @@ -115,9 +115,9 @@ def test_compare(self):
kf.filter_py.predict_and_update_batch(t, ObservationKind.POSITION, z, R)
kf.filter_pyx.predict_and_update_batch(t, ObservationKind.POSITION, z, R)

self.assertAlmostEqual(kf.filter_py.get_filter_time(), kf.filter_pyx.get_filter_time())
self.assertTrue(np.allclose(kf.filter_py.state(), kf.filter_pyx.state()))
self.assertTrue(np.allclose(kf.filter_py.covs(), kf.filter_pyx.covs()))
assert kf.filter_py.get_filter_time() == pytest.approx(kf.filter_pyx.get_filter_time())
assert np.allclose(kf.filter_py.state(), kf.filter_pyx.state())
assert np.allclose(kf.filter_py.covs(), kf.filter_pyx.covs())


if __name__ == "__main__":
Expand Down
13 changes: 8 additions & 5 deletions examples/test_kinematic_kf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import pytest
import os
import numpy as np
import unittest
import sys
sys.path.append(os.path.dirname(__file__))

from kinematic_kf import KinematicKalman, ObservationKind, States # pylint: disable=import-error

GENERATED_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'generated'))

class TestKinematic(unittest.TestCase):
class TestKinematic:
def test_kinematic_kf(self):
np.random.seed(0)

Expand Down Expand Up @@ -49,10 +52,10 @@ def test_kinematic_kf(self):

xs, xs_meas, xs_kf, vs_kf, xs_kf_std, vs_kf_std = (np.asarray(a) for a in (xs, xs_meas, xs_kf, vs_kf, xs_kf_std, vs_kf_std))

self.assertAlmostEqual(xs_kf[-1], -0.010866289677966417)
self.assertAlmostEqual(xs_kf_std[-1], 0.04477103863330089)
self.assertAlmostEqual(vs_kf[-1], -0.8553720537261753)
self.assertAlmostEqual(vs_kf_std[-1], 0.6695762270974388)
assert xs_kf[-1] == pytest.approx(-0.010866289677966417)
assert xs_kf_std[-1] == pytest.approx(0.04477103863330089)
assert vs_kf[-1] == pytest.approx(-0.8553720537261753)
assert vs_kf_std[-1] == pytest.approx(0.6695762270974388)

if "PLOT" in os.environ:
import matplotlib.pyplot as plt # pylint: disable=import-error
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cffi
scons
pre-commit
Cython
pytest

0 comments on commit 5f9ebbe

Please sign in to comment.