From 233c7bea1029fcb9337ef66be4539aa677b55596 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Mon, 25 Nov 2024 17:03:15 -0500 Subject: [PATCH 01/21] Remove unittest from test_baseposelist.py, as precursor to using features from pytest; convert all self.assert* calls to bare assert statements. --- tests/test_baseposelist.py | 76 ++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/tests/test_baseposelist.py b/tests/test_baseposelist.py index 30da5681..9685abc0 100644 --- a/tests/test_baseposelist.py +++ b/tests/test_baseposelist.py @@ -1,4 +1,3 @@ -import unittest import numpy as np from spatialmath.baseposelist import BasePoseList @@ -20,23 +19,23 @@ def shape(self): def isvalid(x): return True -class TestBasePoseList(unittest.TestCase): +class TestBasePoseList: def test_constructor(self): x = X() - self.assertIsInstance(x, X) - self.assertEqual(len(x), 1) + assert isinstance(x, X) + assert len(x) == 1 x = X.Empty() - self.assertIsInstance(x, X) - self.assertEqual(len(x), 0) + assert isinstance(x, X) + assert len(x) == 0 x = X.Alloc(10) - self.assertIsInstance(x, X) - self.assertEqual(len(x), 10) + assert isinstance(x, X) + assert len(x) == 10 for xx in x: - self.assertEqual(xx.A, 0) + assert xx.A == 0 def test_setget(self): x = X.Alloc(10) @@ -44,14 +43,14 @@ def test_setget(self): x[i] = X(2 * i) for i,v in enumerate(x): - self.assertEqual(v.A, 2 * i) + assert v.A == 2 * i def test_append(self): x = X.Empty() for i in range(0, 10): x.append(X(i+1)) - self.assertEqual(len(x), 10) - self.assertEqual([xx.A for xx in x], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + assert len(x) == 10 + assert [xx.A for xx in x] == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def test_extend(self): x = X.Alloc(5) @@ -61,16 +60,16 @@ def test_extend(self): for i in range(0, 5): y[i] = X(i + 10) x.extend(y) - self.assertEqual(len(x), 10) - self.assertEqual([xx.A for xx in x], [1, 2, 3, 4, 5, 10, 11, 12, 13, 14]) + assert len(x) == 10 + assert [xx.A for xx in x] == [1, 2, 3, 4, 5, 10, 11, 12, 13, 14] def test_insert(self): x = X.Alloc(10) for i in range(0, 10): x[i] = X(i + 1) x.insert(5, X(100)) - self.assertEqual(len(x), 11) - self.assertEqual([xx.A for xx in x], [1, 2, 3, 4, 5, 100, 6, 7, 8, 9, 10]) + assert len(x) == 11 + assert [xx.A for xx in x] == [1, 2, 3, 4, 5, 100, 6, 7, 8, 9, 10] def test_pop(self): x = X.Alloc(10) @@ -78,69 +77,64 @@ def test_pop(self): x[i] = X(i + 1) y = x.pop() - self.assertEqual(len(y), 1) - self.assertEqual(y.A, 10) - self.assertEqual(len(x), 9) - self.assertEqual([xx.A for xx in x], [1, 2, 3, 4, 5, 6, 7, 8, 9]) + assert len(y) == 1 + assert y.A == 10 + assert len(x) == 9 + assert [xx.A for xx in x] == [1, 2, 3, 4, 5, 6, 7, 8, 9] def test_clear(self): x = X.Alloc(10) x.clear() - self.assertEqual(len(x), 0) + assert len(x) == 0 def test_reverse(self): x = X.Alloc(5) for i in range(0, 5): x[i] = X(i + 1) x.reverse() - self.assertEqual(len(x), 5) - self.assertEqual([xx.A for xx in x], [5, 4, 3, 2, 1]) + assert len(x) == 5 + assert [xx.A for xx in x] == [5, 4, 3, 2, 1] def test_binop(self): x = X(2) y = X(3) # singelton x singleton - self.assertEqual(x.binop(y, lambda x, y: x * y), [6]) - self.assertEqual(x.binop(y, lambda x, y: x * y, list1=False), 6) + assert x.binop(y, lambda x, y: x * y) == [6] + assert x.binop(y, lambda x, y: x * y, list1=False) == 6 y = X.Alloc(5) for i in range(0, 5): y[i] = X(i + 1) # singelton x non-singleton - self.assertEqual(x.binop(y, lambda x, y: x * y), [2, 4, 6, 8, 10]) - self.assertEqual(x.binop(y, lambda x, y: x * y, list1=False), [2, 4, 6, 8, 10]) + assert x.binop(y, lambda x, y: x * y) == [2, 4, 6, 8, 10] + assert x.binop(y, lambda x, y: x * y, list1=False) == [2, 4, 6, 8, 10] # non-singelton x singleton - self.assertEqual(y.binop(x, lambda x, y: x * y), [2, 4, 6, 8, 10]) - self.assertEqual(y.binop(x, lambda x, y: x * y, list1=False), [2, 4, 6, 8, 10]) + assert y.binop(x, lambda x, y: x * y) == [2, 4, 6, 8, 10] + assert y.binop(x, lambda x, y: x * y, list1=False) == [2, 4, 6, 8, 10] # non-singelton x non-singleton - self.assertEqual(y.binop(y, lambda x, y: x * y), [1, 4, 9, 16, 25]) - self.assertEqual(y.binop(y, lambda x, y: x * y, list1=False), [1, 4, 9, 16, 25]) + assert y.binop(y, lambda x, y: x * y) == [1, 4, 9, 16, 25] + assert y.binop(y, lambda x, y: x * y, list1=False) == [1, 4, 9, 16, 25] def test_unop(self): x = X(2) f = lambda x: 2 * x - self.assertEqual(x.unop(f), [4]) - self.assertEqual(x.unop(f, matrix=True), np.r_[4]) + assert x.unop(f) == [4] + assert x.unop(f, matrix=True) == np.r_[4] x = X.Alloc(5) for i in range(0, 5): x[i] = X(i + 1) - self.assertEqual(x.unop(f), [2, 4, 6, 8, 10]) + assert x.unop(f) == [2, 4, 6, 8, 10] y = x.unop(f, matrix=True) - self.assertEqual(y.shape, (5,1)) - self.assertTrue(np.all(y - np.c_[2, 4, 6, 8, 10].T == 0)) + assert y.shape == (5,1) + assert np.all(y - np.c_[2, 4, 6, 8, 10].T == 0) def test_arghandler(self): pass - -# ---------------------------------------------------------------------------------------# -if __name__ == '__main__': - - unittest.main() \ No newline at end of file From f4685cd68f538f2e9d41ce362d91ed2f3a31d731 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Mon, 25 Nov 2024 17:29:13 -0500 Subject: [PATCH 02/21] Split up non-atomic tests in test_baseposelist.py; for unop and binop, used parametrized tests --- tests/test_baseposelist.py | 84 +++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/tests/test_baseposelist.py b/tests/test_baseposelist.py index 9685abc0..bb7ac573 100644 --- a/tests/test_baseposelist.py +++ b/tests/test_baseposelist.py @@ -1,11 +1,16 @@ import numpy as np +import pytest from spatialmath.baseposelist import BasePoseList -# create a subclass to test with, its value is a scalar +# create a subclass to test with, its value is a list class X(BasePoseList): - def __init__(self, value=0, check=False): + def __init__(self, value=None, check=False): + if value is None: + value = [0] + elif not isinstance(value, list): + value = [value] super().__init__() - self.data = [value] + self.data = value @staticmethod def _identity(): @@ -27,10 +32,12 @@ def test_constructor(self): assert isinstance(x, X) assert len(x) == 1 + def test_empty(self): x = X.Empty() assert isinstance(x, X) assert len(x) == 0 + def test_alloc(self): x = X.Alloc(10) assert isinstance(x, X) assert len(x) == 10 @@ -95,46 +102,37 @@ def test_reverse(self): assert len(x) == 5 assert [xx.A for xx in x] == [5, 4, 3, 2, 1] - def test_binop(self): - x = X(2) - y = X(3) - - # singelton x singleton - assert x.binop(y, lambda x, y: x * y) == [6] - assert x.binop(y, lambda x, y: x * y, list1=False) == 6 - - y = X.Alloc(5) - for i in range(0, 5): - y[i] = X(i + 1) - - # singelton x non-singleton - assert x.binop(y, lambda x, y: x * y) == [2, 4, 6, 8, 10] - assert x.binop(y, lambda x, y: x * y, list1=False) == [2, 4, 6, 8, 10] - - # non-singelton x singleton - assert y.binop(x, lambda x, y: x * y) == [2, 4, 6, 8, 10] - assert y.binop(x, lambda x, y: x * y, list1=False) == [2, 4, 6, 8, 10] - - # non-singelton x non-singleton - assert y.binop(y, lambda x, y: x * y) == [1, 4, 9, 16, 25] - assert y.binop(y, lambda x, y: x * y, list1=False) == [1, 4, 9, 16, 25] - - def test_unop(self): - x = X(2) - - f = lambda x: 2 * x - - assert x.unop(f) == [4] - assert x.unop(f, matrix=True) == np.r_[4] - - x = X.Alloc(5) - for i in range(0, 5): - x[i] = X(i + 1) - - assert x.unop(f) == [2, 4, 6, 8, 10] - y = x.unop(f, matrix=True) - assert y.shape == (5,1) - assert np.all(y - np.c_[2, 4, 6, 8, 10].T == 0) + @pytest.mark.parametrize( + 'x,y,list1,expected', + [ + (X(2), X(3), True, [6]), + (X(2), X(3), False, 6), + (X(2), X([1,2,3,4,5]), True, [2,4,6,8,10]), + (X(2), X([1,2,3,4,5]), False, [2,4,6,8,10]), + (X([1,2,3,4,5]), X(2), True, [2,4,6,8,10]), + (X([1,2,3,4,5]), X(2), False, [2,4,6,8,10]), + (X([1,2,3,4,5]), X([1,2,3,4,5]), True, [1,4,9,16,25]), + (X([1,2,3,4,5]), X([1,2,3,4,5]), False, [1,4,9,16,25]), + ], + ) + def test_binop(self, x, y, list1, expected): + assert x.binop(y, lambda x, y: x * y, list1=list1) == expected + + @pytest.mark.parametrize( + 'x,matrix,expected', + [ + (X(2), False, [4]), + (X(2), True, np.array(4)), + (X([1,2,3,4,5]), False, [2,4,6,8,10]), + (X([1,2,3,4,5]), True, np.array([[2,4,6,8,10]]).T), + ], + ) + def test_unop(self, x, matrix, expected): + result = x.unop(lambda x: 2*x, matrix=matrix) + if isinstance(result, np.ndarray): + assert (result == expected).all() + else: + assert result == expected def test_arghandler(self): pass From 8a5a1b9d783a1745a28cdda1e4cd6d3f36e16572 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Mon, 25 Nov 2024 17:31:09 -0500 Subject: [PATCH 03/21] Remove test_arghandler in test_baseposelist.py : a test that says nothing but `pass` isn't testing anything. --- tests/test_baseposelist.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_baseposelist.py b/tests/test_baseposelist.py index bb7ac573..433fe1f4 100644 --- a/tests/test_baseposelist.py +++ b/tests/test_baseposelist.py @@ -133,6 +133,3 @@ def test_unop(self, x, matrix, expected): assert (result == expected).all() else: assert result == expected - - def test_arghandler(self): - pass From e705d61866fd60400f67ff9ca7c20cacf89fb9e8 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Mon, 25 Nov 2024 17:41:25 -0500 Subject: [PATCH 04/21] Convert from unittest to pytest --- tests/base/test_argcheck.py | 278 ++++++++++++++++++------------------ 1 file changed, 136 insertions(+), 142 deletions(-) diff --git a/tests/base/test_argcheck.py b/tests/base/test_argcheck.py index 685393b5..4dec0889 100755 --- a/tests/base/test_argcheck.py +++ b/tests/base/test_argcheck.py @@ -6,34 +6,33 @@ @author: corkep """ -import unittest import numpy as np import numpy.testing as nt - +import pytest from spatialmath.base.argcheck import * -class Test_check(unittest.TestCase): +class Test_check: def test_ismatrix(self): a = np.eye(3, 3) - self.assertTrue(ismatrix(a, (3, 3))) - self.assertFalse(ismatrix(a, (4, 3))) - self.assertFalse(ismatrix(a, (3, 4))) - self.assertFalse(ismatrix(a, (4, 4))) + assert ismatrix(a, (3, 3)) + assert not ismatrix(a, (4, 3)) + assert not ismatrix(a, (3, 4)) + assert not ismatrix(a, (4, 4)) - self.assertTrue(ismatrix(a, (-1, 3))) - self.assertTrue(ismatrix(a, (3, -1))) - self.assertTrue(ismatrix(a, (-1, -1))) + assert ismatrix(a, (-1, 3)) + assert ismatrix(a, (3, -1)) + assert ismatrix(a, (-1, -1)) - self.assertFalse(ismatrix(1, (-1, -1))) + assert not ismatrix(1, (-1, -1)) def test_assertmatrix(self): - with self.assertRaises(TypeError): + with pytest.raises(TypeError): assertmatrix(3) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): assertmatrix("not a matrix") - with self.assertRaises(TypeError): + with pytest.raises(TypeError): a = np.eye(3, 3, dtype=complex) assertmatrix(a) @@ -44,89 +43,89 @@ def test_assertmatrix(self): assertmatrix(a, (None, 3)) assertmatrix(a, (3, None)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): assertmatrix(a, (4, 3)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): assertmatrix(a, (4, None)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): assertmatrix(a, (None, 4)) def test_getmatrix(self): a = np.random.rand(4, 3) - self.assertEqual(getmatrix(a, (4, 3)).shape, (4, 3)) - self.assertEqual(getmatrix(a, (None, 3)).shape, (4, 3)) - self.assertEqual(getmatrix(a, (4, None)).shape, (4, 3)) - self.assertEqual(getmatrix(a, (None, None)).shape, (4, 3)) - with self.assertRaises(ValueError): + assert getmatrix(a, (4, 3)).shape == (4, 3) + assert getmatrix(a, (None, 3)).shape == (4, 3) + assert getmatrix(a, (4, None)).shape == (4, 3) + assert getmatrix(a, (None, None)).shape == (4, 3) + with pytest.raises(ValueError): m = getmatrix(a, (5, 3)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (5, None)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (None, 4)) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): m = getmatrix({}, (4, 3)) a = np.r_[1, 2, 3, 4] - self.assertEqual(getmatrix(a, (1, 4)).shape, (1, 4)) - self.assertEqual(getmatrix(a, (4, 1)).shape, (4, 1)) - self.assertEqual(getmatrix(a, (2, 2)).shape, (2, 2)) - with self.assertRaises(ValueError): + assert getmatrix(a, (1, 4)).shape == (1, 4) + assert getmatrix(a, (4, 1)).shape == (4, 1) + assert getmatrix(a, (2, 2)).shape == (2, 2) + with pytest.raises(ValueError): m = getmatrix(a, (5, None)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (None, 5)) a = [1, 2, 3, 4] - self.assertEqual(getmatrix(a, (1, 4)).shape, (1, 4)) - self.assertEqual(getmatrix(a, (4, 1)).shape, (4, 1)) - self.assertEqual(getmatrix(a, (2, 2)).shape, (2, 2)) - with self.assertRaises(ValueError): + assert getmatrix(a, (1, 4)).shape == (1, 4) + assert getmatrix(a, (4, 1)).shape == (4, 1) + assert getmatrix(a, (2, 2)).shape == (2, 2) + with pytest.raises(ValueError): m = getmatrix(a, (5, None)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (None, 5)) a = 7 - self.assertEqual(getmatrix(a, (1, 1)).shape, (1, 1)) - self.assertEqual(getmatrix(a, (None, None)).shape, (1, 1)) - with self.assertRaises(ValueError): + assert getmatrix(a, (1, 1)).shape == (1, 1) + assert getmatrix(a, (None, None)).shape == (1, 1) + with pytest.raises(ValueError): m = getmatrix(a, (2, 1)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (1, 2)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (None, 2)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (2, None)) a = 7.0 - self.assertEqual(getmatrix(a, (1, 1)).shape, (1, 1)) - self.assertEqual(getmatrix(a, (None, None)).shape, (1, 1)) - with self.assertRaises(ValueError): + assert getmatrix(a, (1, 1)).shape == (1, 1) + assert getmatrix(a, (None, None)).shape == (1, 1) + with pytest.raises(ValueError): m = getmatrix(a, (2, 1)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (1, 2)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (None, 2)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): m = getmatrix(a, (2, None)) def test_verifymatrix(self): - with self.assertRaises(TypeError): + with pytest.raises(TypeError): assertmatrix(3) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): verifymatrix([3, 4]) a = np.eye(3, 3) verifymatrix(a, (3, 3)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): verifymatrix(a, (3, 4)) def test_unit(self): - self.assertIsInstance(getunit(1), np.ndarray) - self.assertIsInstance(getunit([1, 2]), np.ndarray) - self.assertIsInstance(getunit((1, 2)), np.ndarray) - self.assertIsInstance(getunit(np.r_[1, 2]), np.ndarray) - self.assertIsInstance(getunit(1.0, dim=0), float) + assert isinstance(getunit(1), np.ndarray) + assert isinstance(getunit([1, 2]), np.ndarray) + assert isinstance(getunit((1, 2)), np.ndarray) + assert isinstance(getunit(np.r_[1, 2]), np.ndarray) + assert isinstance(getunit(1.0, dim=0), float) nt.assert_equal(getunit(5, "rad"), 5) nt.assert_equal(getunit(5, "deg"), 5 * math.pi / 180.0) @@ -148,31 +147,31 @@ def test_unit(self): def test_isvector(self): # no length specified - self.assertTrue(isvector(2)) - self.assertTrue(isvector(2.0)) - self.assertTrue(isvector([1, 2, 3])) - self.assertTrue(isvector((1, 2, 3))) - self.assertTrue(isvector(np.array([1, 2, 3]))) - self.assertTrue(isvector(np.array([[1, 2, 3]]))) - self.assertTrue(isvector(np.array([[1], [2], [3]]))) + assert isvector(2) + assert isvector(2.0) + assert isvector([1, 2, 3]) + assert isvector((1, 2, 3)) + assert isvector(np.array([1, 2, 3])) + assert isvector(np.array([[1, 2, 3]])) + assert isvector(np.array([[1], [2], [3]])) # length specified - self.assertTrue(isvector(2, 1)) - self.assertTrue(isvector(2.0, 1)) - self.assertTrue(isvector([1, 2, 3], 3)) - self.assertTrue(isvector((1, 2, 3), 3)) - self.assertTrue(isvector(np.array([1, 2, 3]), 3)) - self.assertTrue(isvector(np.array([[1, 2, 3]]), 3)) - self.assertTrue(isvector(np.array([[1], [2], [3]]), 3)) + assert isvector(2, 1) + assert isvector(2.0, 1) + assert isvector([1, 2, 3], 3) + assert isvector((1, 2, 3), 3) + assert isvector(np.array([1, 2, 3]), 3) + assert isvector(np.array([[1, 2, 3]]), 3) + assert isvector(np.array([[1], [2], [3]]), 3) # wrong length specified - self.assertFalse(isvector(2, 4)) - self.assertFalse(isvector(2.0, 4)) - self.assertFalse(isvector([1, 2, 3], 4)) - self.assertFalse(isvector((1, 2, 3), 4)) - self.assertFalse(isvector(np.array([1, 2, 3]), 4)) - self.assertFalse(isvector(np.array([[1, 2, 3]]), 4)) - self.assertFalse(isvector(np.array([[1], [2], [3]]), 4)) + assert not isvector(2, 4) + assert not isvector(2.0, 4) + assert not isvector([1, 2, 3], 4) + assert not isvector((1, 2, 3), 4) + assert not isvector(np.array([1, 2, 3]), 4) + assert not isvector(np.array([[1, 2, 3]]), 4) + assert not isvector(np.array([[1], [2], [3]]), 4) def test_isvector(self): l = [1, 2, 3] @@ -187,43 +186,43 @@ def test_getvector(self): # input is list v = getvector(l) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(l, 3) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(l, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(l, 3, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(l, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(l, 3, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(l, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(l, 3, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(l, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) v = getvector(l, 3, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) nt.assert_raises(ValueError, getvector, l, 4) @@ -235,43 +234,43 @@ def test_getvector(self): # input is tuple v = getvector(t) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(t, 3) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(t, out="sequence") - self.assertIsInstance(v, tuple) + assert isinstance(v, tuple) nt.assert_equal(len(v), 3) v = getvector(t, 3, out="sequence") - self.assertIsInstance(v, tuple) + assert isinstance(v, tuple) nt.assert_equal(len(v), 3) v = getvector(t, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(t, 3, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(t, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(t, 3, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(t, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) v = getvector(t, 3, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) nt.assert_raises(ValueError, getvector, t, 4) @@ -283,43 +282,43 @@ def test_getvector(self): # input is array v = getvector(a) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(a, 3) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(a, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(a, 3, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(a, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(a, 3, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(a, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(a, 3, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(a, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) v = getvector(a, 3, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) nt.assert_raises(ValueError, getvector, a, 4) @@ -331,43 +330,43 @@ def test_getvector(self): # input is row v = getvector(r) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(r, 3) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(r, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(r, 3, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(r, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(r, 3, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(r, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(r, 3, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(r, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) v = getvector(r, 3, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) nt.assert_raises(ValueError, getvector, r, 4) @@ -379,43 +378,43 @@ def test_getvector(self): # input is col v = getvector(c) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(c, 3) - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(len(v), 3) v = getvector(c, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(c, 3, out="sequence") - self.assertIsInstance(v, list) + assert isinstance(v, list) nt.assert_equal(len(v), 3) v = getvector(c, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(c, 3, out="array") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3,)) v = getvector(c, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(c, 3, out="row") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (1, 3)) v = getvector(c, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) v = getvector(c, 3, out="col") - self.assertIsInstance(v, np.ndarray) + assert isinstance(v, np.ndarray) nt.assert_equal(v.shape, (3, 1)) nt.assert_raises(ValueError, getvector, c, 4) @@ -435,30 +434,25 @@ def test_isnumberlist(self): def test_isvectorlist(self): a = [np.r_[1, 2], np.r_[3, 4], np.r_[5, 6]] - self.assertTrue(isvectorlist(a, 2)) + assert isvectorlist(a, 2) a = [(1, 2), (3, 4), (5, 6)] - self.assertFalse(isvectorlist(a, 2)) + assert not isvectorlist(a, 2) a = [np.r_[1, 2], np.r_[3, 4], np.r_[5, 6, 7]] - self.assertFalse(isvectorlist(a, 2)) + assert not isvectorlist(a, 2) def test_islistof(self): a = [3, 4, 5] - self.assertTrue(islistof(a, int)) - self.assertFalse(islistof(a, float)) - self.assertTrue(islistof(a, lambda x: isinstance(x, int))) + assert islistof(a, int) + assert not islistof(a, float) + assert islistof(a, lambda x: isinstance(x, int)) - self.assertTrue(islistof(a, int, 3)) - self.assertFalse(islistof(a, int, 2)) + assert islistof(a, int, 3) + assert not islistof(a, int, 2) a = [3, 4.5, 5.6] - self.assertFalse(islistof(a, int)) - self.assertTrue(islistof(a, (int, float))) + assert not islistof(a, int) + assert islistof(a, (int, float)) a = [[1, 2], [3, 4], [5, 6]] - self.assertTrue(islistof(a, lambda x: islistof(x, int, 2))) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": # pragma: no cover - unittest.main() + assert islistof(a, lambda x: islistof(x, int, 2)) From 4ec1894173b5ae775b28f6e5167a8404cf9facf0 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 09:36:43 -0500 Subject: [PATCH 05/21] Use matplotlib backed AGG in tests; use movie=True for animations (adding in **kwargs as necessary); produces several warnings now. --- spatialmath/spline.py | 3 ++- tests/base/test_graphics.py | 3 ++- tests/base/test_transforms.py | 2 ++ tests/base/test_transforms2d.py | 2 ++ tests/base/test_transforms3d_plot.py | 8 +++++--- tests/base/test_transformsNd.py | 2 ++ tests/base/test_vectors.py | 2 ++ tests/base/test_velocity.py | 2 ++ tests/test_pose2d.py | 2 ++ tests/test_pose3d.py | 2 ++ tests/test_spline.py | 8 +++++--- tests/test_twist.py | 2 ++ 12 files changed, 30 insertions(+), 8 deletions(-) diff --git a/spatialmath/spline.py b/spatialmath/spline.py index 0a472ecc..d1aed154 100644 --- a/spatialmath/spline.py +++ b/spatialmath/spline.py @@ -34,6 +34,7 @@ def visualize( animate: bool = False, repeat: bool = True, ax: Optional[plt.Axes] = None, + **kwargs, # pass through to tranimate ) -> None: """Displays an animation of the trajectory with the control poses against an optional input trajectory. @@ -62,7 +63,7 @@ def visualize( if animate: tranimate( - samples, length=pose_marker_length, wait=True, repeat=repeat + samples, length=pose_marker_length, wait=True, repeat=repeat, **kwargs, ) # animate pose along trajectory else: plt.show() diff --git a/tests/base/test_graphics.py b/tests/base/test_graphics.py index 552ebdb0..c8b999ad 100644 --- a/tests/base/test_graphics.py +++ b/tests/base/test_graphics.py @@ -1,5 +1,7 @@ import unittest import numpy as np +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt import pytest import sys @@ -8,7 +10,6 @@ # test graphics primitives # TODO check they actually create artists - class TestGraphics(unittest.TestCase): def teardown_method(self, method): plt.close("all") diff --git a/tests/base/test_transforms.py b/tests/base/test_transforms.py index 71b01bb3..d74a048e 100755 --- a/tests/base/test_transforms.py +++ b/tests/base/test_transforms.py @@ -18,6 +18,8 @@ from spatialmath.base import * from spatialmath.base import sym +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt diff --git a/tests/base/test_transforms2d.py b/tests/base/test_transforms2d.py index ff099930..ce73dd01 100755 --- a/tests/base/test_transforms2d.py +++ b/tests/base/test_transforms2d.py @@ -29,6 +29,8 @@ ) from spatialmath.base.numeric import numjac +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt diff --git a/tests/base/test_transforms3d_plot.py b/tests/base/test_transforms3d_plot.py index f250df4a..9e92e4ab 100755 --- a/tests/base/test_transforms3d_plot.py +++ b/tests/base/test_transforms3d_plot.py @@ -20,6 +20,8 @@ from spatialmath.base.transforms3d import * from spatialmath.base.transformsNd import isR, t2r, r2t, rt2tr +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt @@ -76,11 +78,11 @@ def test_plot(self): reason="tkinter bug with mac", ) def test_animate(self): - tranimate(transl(1, 2, 3), repeat=False, wait=True) + tranimate(transl(1, 2, 3), repeat=False, wait=True, movie=True) - tranimate(transl(1, 2, 3), repeat=False, wait=True) + tranimate(transl(1, 2, 3), repeat=False, wait=True, movie=True) # run again, with axes already created - tranimate(transl(1, 2, 3), repeat=False, wait=True, dims=[0, 10, 0, 10, 0, 10]) + tranimate(transl(1, 2, 3), repeat=False, wait=True, dims=[0, 10, 0, 10, 0, 10], movie=True) plt.close("all") # test animate with line not arrow, text, test with SO(3) diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index 92d9e2a3..db561d6b 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -25,6 +25,8 @@ from spatialmath.base.symbolic import symbol except ImportError: _symbolics = False +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index 592c2d16..797111a9 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -24,6 +24,8 @@ _symbolics = True except ImportError: _symbolics = False +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt from math import pi diff --git a/tests/base/test_velocity.py b/tests/base/test_velocity.py index 13ee35e8..8dd96b93 100644 --- a/tests/base/test_velocity.py +++ b/tests/base/test_velocity.py @@ -19,6 +19,8 @@ from spatialmath.base.numeric import * from spatialmath.base.transformsNd import isR, t2r, r2t, rt2tr +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index d6d96813..796987f4 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -1,4 +1,6 @@ import numpy.testing as nt +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt import unittest import sys diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index d6a941c3..c9fd3da2 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -1,4 +1,6 @@ import numpy.testing as nt +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt import unittest import sys diff --git a/tests/test_spline.py b/tests/test_spline.py index 361bc28f..1d4277cb 100644 --- a/tests/test_spline.py +++ b/tests/test_spline.py @@ -1,5 +1,7 @@ import numpy.testing as nt import numpy as np +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt import unittest @@ -27,7 +29,7 @@ def test_evaluation(self): def test_visualize(self): spline = BSplineSE3(self.control_poses) - spline.visualize(sample_times= np.linspace(0, 1.0, 100), animate=True, repeat=False) + spline.visualize(sample_times= np.linspace(0, 1.0, 100), animate=True, repeat=False, movie=True) class TestInterpSplineSE3: waypoints = [ @@ -62,7 +64,7 @@ def test_small_delta_t(self): def test_visualize(self): spline = InterpSplineSE3(self.times, self.waypoints) - spline.visualize(sample_times= np.linspace(0, self.time_horizon, 100), animate=True, repeat=False) + spline.visualize(sample_times= np.linspace(0, self.time_horizon, 100), animate=True, repeat=False, movie=True) class TestSplineFit: @@ -92,4 +94,4 @@ def test_spline_fit(self): assert( fit.max_angular_error() < np.deg2rad(5.0) ) assert( fit.max_angular_error() < 0.1 ) - spline.visualize(sample_times= np.linspace(0, self.time_horizon, 100), animate=True, repeat=False) \ No newline at end of file + spline.visualize(sample_times= np.linspace(0, self.time_horizon, 100), animate=True, repeat=False, movie=True) diff --git a/tests/test_twist.py b/tests/test_twist.py index 12660c7d..14623f96 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -1,4 +1,6 @@ import numpy.testing as nt +import matplotlib +matplotlib.use("AGG") import matplotlib.pyplot as plt import unittest From 5e33b0cb7543e2ce17b68c063b2246c97b8e5af2 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:02:49 -0500 Subject: [PATCH 06/21] Replace all usage of assertIsInstance with a bare assertion --- tests/base/test_numeric.py | 6 +- tests/base/test_transforms2d.py | 2 +- tests/base/test_transforms3d.py | 8 +- tests/base/test_vectors.py | 8 +- tests/test_dualquaternion.py | 6 +- tests/test_geom2d.py | 4 +- tests/test_geom3d.py | 6 +- tests/test_pose2d.py | 66 +++++------ tests/test_pose3d.py | 190 ++++++++++++++++---------------- tests/test_quaternion.py | 72 ++++++------ tests/test_spatialvector.py | 120 ++++++++++---------- tests/test_twist.py | 32 +++--- 12 files changed, 260 insertions(+), 260 deletions(-) diff --git a/tests/base/test_numeric.py b/tests/base/test_numeric.py index e6b9de50..ff2fcc0f 100755 --- a/tests/base/test_numeric.py +++ b/tests/base/test_numeric.py @@ -26,7 +26,7 @@ def test_array2str(self): x = [1.2345678] s = array2str(x) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s, "[ 1.23 ]") s = array2str(x, fmt="{:.5f}") @@ -54,9 +54,9 @@ def test_array2str(self): def test_bresenham(self): x, y = bresenham((-10, -10), (20, 10)) - self.assertIsInstance(x, np.ndarray) + assert isinstance(x, np.ndarray) self.assertEqual(x.ndim, 1) - self.assertIsInstance(y, np.ndarray) + assert isinstance(y, np.ndarray) self.assertEqual(y.ndim, 1) self.assertEqual(len(x), len(y)) diff --git a/tests/base/test_transforms2d.py b/tests/base/test_transforms2d.py index ce73dd01..84f6f91c 100755 --- a/tests/base/test_transforms2d.py +++ b/tests/base/test_transforms2d.py @@ -182,7 +182,7 @@ def test_print2(self): T = transl2(1, 2) @ trot2(0.3) s = trprint2(T, file=None) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 15) def test_checks(self): diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index 2f1e6049..74cf848f 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -539,24 +539,24 @@ def test_tr2angvec(self): def test_print(self): R = rotx(0.3) @ roty(0.4) s = trprint(R, file=None) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 30) T = transl(1, 2, 3) @ trotx(0.3) @ troty(0.4) s = trprint(T, file=None) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 42) self.assertTrue("rpy" in s) self.assertTrue("zyx" in s) s = trprint(T, file=None, orient="rpy/xyz") - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 39) self.assertTrue("rpy" in s) self.assertTrue("xyz" in s) s = trprint(T, file=None, orient="eul") - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 37) self.assertTrue("eul" in s) self.assertFalse("zyx" in s) diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index 797111a9..be04c8ab 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -271,23 +271,23 @@ def test_iszero(self): def test_angdiff(self): self.assertEqual(angdiff(0, 0), 0) - self.assertIsInstance(angdiff(0, 0), float) + assert isinstance(angdiff(0, 0), float) self.assertEqual(angdiff(pi, 0), -pi) self.assertEqual(angdiff(-pi, pi), 0) x = angdiff([0, -pi, pi], 0) nt.assert_array_almost_equal(x, [0, -pi, -pi]) - self.assertIsInstance(x, np.ndarray) + assert isinstance(x, np.ndarray) nt.assert_array_almost_equal(angdiff([0, -pi, pi], pi), [-pi, 0, 0]) x = angdiff(0, [0, -pi, pi]) nt.assert_array_almost_equal(x, [0, -pi, -pi]) - self.assertIsInstance(x, np.ndarray) + assert isinstance(x, np.ndarray) nt.assert_array_almost_equal(angdiff(pi, [0, -pi, pi]), [-pi, 0, 0]) x = angdiff([1, 2, 3], [1, 2, 3]) nt.assert_array_almost_equal(x, [0, 0, 0]) - self.assertIsInstance(x, np.ndarray) + assert isinstance(x, np.ndarray) def test_wrap(self): self.assertAlmostEqual(wrap_0_2pi(0), 0) diff --git a/tests/test_dualquaternion.py b/tests/test_dualquaternion.py index 39c5fc03..450ba9a6 100644 --- a/tests/test_dualquaternion.py +++ b/tests/test_dualquaternion.py @@ -40,8 +40,8 @@ def test_pure(self): def test_strings(self): dq = DualQuaternion(Quaternion([1.,2,3,4]), Quaternion([5.,6,7,8])) - self.assertIsInstance(str(dq), str) - self.assertIsInstance(repr(dq), str) + assert isinstance(str(dq), str) + assert isinstance(repr(dq), str) def test_conj(self): dq = DualQuaternion(Quaternion([1.,2,3,4]), Quaternion([5.,6,7,8])) @@ -69,7 +69,7 @@ def test_matrix(self): dq1 = DualQuaternion(Quaternion([1.,2,3,4]), Quaternion([5.,6,7,8])) M = dq1.matrix() - self.assertIsInstance(M, np.ndarray) + assert isinstance(M, np.ndarray) self.assertEqual(M.shape, (8,8)) def test_multiply(self): diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index 49aa1d8b..29dbe2a0 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -20,7 +20,7 @@ class Polygon2Test(unittest.TestCase): # Primitives def test_constructor1(self): p = Polygon2([(1, 2), (3, 2), (2, 4)]) - self.assertIsInstance(p, Polygon2) + assert isinstance(p, Polygon2) self.assertEqual(len(p), 3) self.assertEqual(str(p), "Polygon2 with 4 vertices") nt.assert_array_equal(p.vertices(), np.array([[1, 3, 2], [2, 2, 4]])) @@ -224,7 +224,7 @@ def test_FromPoints(self): def test_misc(self): e = Ellipse(radii=(1, 2), theta=np.pi / 2) - self.assertIsInstance(str(e), str) + assert isinstance(str(e), str) self.assertAlmostEqual(e.area, np.pi * 2) diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 7a743dd5..baf2fbfd 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -25,13 +25,13 @@ def test_constructor1(self): L = Line3([1, 2, 3, 4, 5, 6], check=True) L = Line3([1, 2, 3, 4, 5, 6], check=False) - self.assertIsInstance(L, Line3) + assert isinstance(L, Line3) nt.assert_array_almost_equal(L.v, np.r_[1, 2, 3]) nt.assert_array_almost_equal(L.w, np.r_[4, 5, 6]) # construct from object L2 = Line3(L, check=False) - self.assertIsInstance(L, Line3) + assert isinstance(L, Line3) nt.assert_array_almost_equal(L2.v, np.r_[1, 2, 3]) nt.assert_array_almost_equal(L2.w, np.r_[4, 5, 6]) @@ -272,7 +272,7 @@ def test_char(self): L = Line3.Join(P, Q) s = str(L) - self.assertIsInstance(s, str) + assert isinstance(s, str) def test_plane(self): xyplane = [0, 0, 1, 0] diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index 796987f4..584bb041 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -40,7 +40,7 @@ def tearDownClass(cls): def test_constructor(self): # null case x = SO2() - self.assertIsInstance(x, SO2) + assert isinstance(x, SO2) self.assertEqual(len(x), 1) array_compare(x.A, np.eye(2, 2)) @@ -83,14 +83,14 @@ def test_concat(self): x = SO2() xx = SO2([x, x, x, x]) - self.assertIsInstance(xx, SO2) + assert isinstance(xx, SO2) self.assertEqual(len(xx), 4) def test_primitive_convert(self): # char s = str(SO2()) - self.assertIsInstance(s, str) + assert isinstance(s, str) def test_shape(self): a = SO2() @@ -119,13 +119,13 @@ def test_isa(self): def test_resulttype(self): r = SO2() - self.assertIsInstance(r, SO2) + assert isinstance(r, SO2) - self.assertIsInstance(r * r, SO2) + assert isinstance(r * r, SO2) - self.assertIsInstance(r / r, SO2) + assert isinstance(r / r, SO2) - self.assertIsInstance(r.inv(), SO2) + assert isinstance(r.inv(), SO2) def test_multiply(self): vx = np.r_[1, 0] @@ -190,7 +190,7 @@ def test_divide(self): def test_conversions(self): T = SO2(pi / 2).SE2() - self.assertIsInstance(T, SE2) + assert isinstance(T, SE2) ## Lie stuff th = 0.3 @@ -212,11 +212,11 @@ def test_printline(self): R.printline() # s = R.printline(file=None) - # self.assertIsInstance(s, str) + # assert isinstance(s, str) R = SO2([0.3, 0.4, 0.5]) s = R.printline(file=None) - # self.assertIsInstance(s, str) + # assert isinstance(s, str) # self.assertEqual(s.count('\n'), 2) @pytest.mark.skipif( @@ -243,47 +243,47 @@ def tearDownClass(cls): plt.close("all") def test_constructor(self): - self.assertIsInstance(SE2(), SE2) + assert isinstance(SE2(), SE2) ## null array_compare(SE2().A, np.eye(3, 3)) # from x,y x = SE2(2, 3) - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 1) array_compare(x.A, np.array([[1, 0, 2], [0, 1, 3], [0, 0, 1]])) x = SE2([2, 3]) - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 1) array_compare(x.A, np.array([[1, 0, 2], [0, 1, 3], [0, 0, 1]])) # from x,y,theta x = SE2(2, 3, pi / 2) - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 1) array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) x = SE2([2, 3, pi / 2]) - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 1) array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) x = SE2(2, 3, 90, unit="deg") - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 1) array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) x = SE2([2, 3, 90], unit="deg") - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 1) array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) ## T T = transl2(1, 2) @ trot2(0.3) x = SE2(T) - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 1) array_compare(x.A, T) @@ -299,7 +299,7 @@ def test_constructor(self): T2 = transl2(1, -2) @ trot2(-0.4) x = SE2([T1, T2, T1, T2]) - self.assertIsInstance(x, SE2) + assert isinstance(x, SE2) self.assertEqual(len(x), 4) array_compare(x[0], T1) array_compare(x[1], T2) @@ -312,7 +312,7 @@ def test_concat(self): x = SE2() xx = SE2([x, x, x, x]) - self.assertIsInstance(xx, SE2) + assert isinstance(xx, SE2) self.assertEqual(len(xx), 4) def test_constructor_Exp(self): @@ -337,17 +337,17 @@ def test_isa(self): def test_resulttype(self): t = SE2() - self.assertIsInstance(t, SE2) - self.assertIsInstance(t * t, SE2) - self.assertIsInstance(t / t, SE2) - self.assertIsInstance(t.inv(), SE2) - self.assertIsInstance(t + t, np.ndarray) - self.assertIsInstance(t + 1, np.ndarray) - self.assertIsInstance(t - 1, np.ndarray) - self.assertIsInstance(1 + t, np.ndarray) - self.assertIsInstance(1 - t, np.ndarray) - self.assertIsInstance(2 * t, np.ndarray) - self.assertIsInstance(t * 2, np.ndarray) + assert isinstance(t, SE2) + assert isinstance(t * t, SE2) + assert isinstance(t / t, SE2) + assert isinstance(t.inv(), SE2) + assert isinstance(t + t, np.ndarray) + assert isinstance(t + 1, np.ndarray) + assert isinstance(t - 1, np.ndarray) + assert isinstance(1 + t, np.ndarray) + assert isinstance(1 - t, np.ndarray) + assert isinstance(2 * t, np.ndarray) + assert isinstance(t * 2, np.ndarray) def test_inverse(self): T1 = transl2(1, 2) @ trot2(0.3) @@ -452,7 +452,7 @@ def test_interp(self): I = SE2() z = I.interp(TT, s=0) - self.assertIsInstance(z, SE2) + assert isinstance(z, SE2) array_compare(I.interp(TT, s=0), I) array_compare(I.interp(TT, s=1), TT) @@ -475,7 +475,7 @@ def test_miscellany(self): self.assertTrue(TT.isSE) - self.assertIsInstance(TT, SE2) + assert isinstance(TT, SE2) def test_display(self): T1 = SE2.Rand() diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index c9fd3da2..8485a5bb 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -39,50 +39,50 @@ def test_constructor(self): R = SO3() nt.assert_equal(len(R), 1) array_compare(R, np.eye(3)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # empty constructor R = SO3.Empty() nt.assert_equal(len(R), 0) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # construct from matrix R = SO3(rotx(0.2)) nt.assert_equal(len(R), 1) array_compare(R, rotx(0.2)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # construct from canonic rotation R = SO3.Rx(0.2) nt.assert_equal(len(R), 1) array_compare(R, rotx(0.2)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.Ry(0.2) nt.assert_equal(len(R), 1) array_compare(R, roty(0.2)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.Rz(0.2) nt.assert_equal(len(R), 1) array_compare(R, rotz(0.2)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # OA R = SO3.OA([0, 1, 0], [0, 0, 1]) nt.assert_equal(len(R), 1) array_compare(R, np.eye(3)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) np.random.seed(32) # random R = SO3.Rand() nt.assert_equal(len(R), 1) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # random constrained R = SO3.Rand(theta_range=(0.1, 0.7)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) self.assertEqual(R.A.shape, (3, 3)) self.assertLessEqual(R.angvec()[0], 0.7) self.assertGreaterEqual(R.angvec()[0], 0.1) @@ -97,27 +97,27 @@ def test_constructor_Eul(self): R = SO3.Eul([0.1, 0.2, 0.3]) nt.assert_equal(len(R), 1) array_compare(R, eul2r([0.1, 0.2, 0.3])) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.Eul(0.1, 0.2, 0.3) nt.assert_equal(len(R), 1) array_compare(R, eul2r([0.1, 0.2, 0.3])) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.Eul(np.r_[0.1, 0.2, 0.3]) nt.assert_equal(len(R), 1) array_compare(R, eul2r([0.1, 0.2, 0.3])) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.Eul([10, 20, 30], unit="deg") nt.assert_equal(len(R), 1) array_compare(R, eul2r([10, 20, 30], unit="deg")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.Eul(10, 20, 30, unit="deg") nt.assert_equal(len(R), 1) array_compare(R, eul2r([10, 20, 30], unit="deg")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # matrix input @@ -125,14 +125,14 @@ def test_constructor_Eul(self): [[0.1, 0.2, 0.3], [0.2, 0.3, 0.4], [0.3, 0.4, 0.5], [0.4, 0.5, 0.6]] ) R = SO3.Eul(angles) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) nt.assert_equal(len(R), 4) for i in range(4): array_compare(R[i], eul2r(angles[i, :])) angles *= 10 R = SO3.Eul(angles, unit="deg") - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) nt.assert_equal(len(R), 4) for i in range(4): array_compare(R[i], eul2r(angles[i, :], unit="deg")) @@ -141,50 +141,50 @@ def test_constructor_RPY(self): R = SO3.RPY(0.1, 0.2, 0.3, order="zyx") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([0.1, 0.2, 0.3], order="zyx")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.RPY(10, 20, 30, unit="deg", order="zyx") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([10, 20, 30], order="zyx", unit="deg")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.RPY([0.1, 0.2, 0.3], order="zyx") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([0.1, 0.2, 0.3], order="zyx")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.RPY(np.r_[0.1, 0.2, 0.3], order="zyx") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([0.1, 0.2, 0.3], order="zyx")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # check default R = SO3.RPY([0.1, 0.2, 0.3]) nt.assert_equal(len(R), 1) array_compare(R, rpy2r([0.1, 0.2, 0.3], order="zyx")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # XYZ order R = SO3.RPY(0.1, 0.2, 0.3, order="xyz") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([0.1, 0.2, 0.3], order="xyz")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.RPY(10, 20, 30, unit="deg", order="xyz") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([10, 20, 30], order="xyz", unit="deg")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.RPY([0.1, 0.2, 0.3], order="xyz") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([0.1, 0.2, 0.3], order="xyz")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.RPY(np.r_[0.1, 0.2, 0.3], order="xyz") nt.assert_equal(len(R), 1) array_compare(R, rpy2r([0.1, 0.2, 0.3], order="xyz")) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) # matrix input @@ -192,14 +192,14 @@ def test_constructor_RPY(self): [[0.1, 0.2, 0.3], [0.2, 0.3, 0.4], [0.3, 0.4, 0.5], [0.4, 0.5, 0.6]] ) R = SO3.RPY(angles, order="zyx") - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) nt.assert_equal(len(R), 4) for i in range(4): array_compare(R[i], rpy2r(angles[i, :], order="zyx")) angles *= 10 R = SO3.RPY(angles, unit="deg", order="zyx") - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) nt.assert_equal(len(R), 4) for i in range(4): array_compare(R[i], rpy2r(angles[i, :], unit="deg", order="zyx")) @@ -209,12 +209,12 @@ def test_constructor_AngVec(self): R = SO3.AngVec(0.2, [1, 0, 0]) nt.assert_equal(len(R), 1) array_compare(R, rotx(0.2)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) R = SO3.AngVec(0.3, [0, 1, 0]) nt.assert_equal(len(R), 1) array_compare(R, roty(0.3)) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) def test_constructor_TwoVec(self): # Randomly selected vectors @@ -224,21 +224,21 @@ def test_constructor_TwoVec(self): # x and y given R = SO3.TwoVectors(x=v1, y=v2) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) nt.assert_almost_equal(R.det(), 1, 5) # x axis should equal normalized x vector nt.assert_almost_equal(R.R[:, 0], v1 / np.linalg.norm(v1), 5) # y and z given R = SO3.TwoVectors(y=v2, z=v3) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) nt.assert_almost_equal(R.det(), 1, 5) # y axis should equal normalized y vector nt.assert_almost_equal(R.R[:, 1], v2 / np.linalg.norm(v2), 5) # x and z given R = SO3.TwoVectors(x=v3, z=v1) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) nt.assert_almost_equal(R.det(), 1, 5) # x axis should equal normalized x vector nt.assert_almost_equal(R.R[:, 0], v3 / np.linalg.norm(v3), 5) @@ -269,11 +269,11 @@ def test_str(self): R = SO3() s = str(R) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 3) s = repr(R) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 2) def test_printline(self): @@ -281,11 +281,11 @@ def test_printline(self): R.printline() # s = R.printline(file=None) - # self.assertIsInstance(s, str) + # assert isinstance(s, str) R = SO3.Rx([0.3, 0.4, 0.5]) s = R.printline(file=None) - # self.assertIsInstance(s, str) + # assert isinstance(s, str) # self.assertEqual(s.count('\n'), 2) @pytest.mark.skipif( @@ -310,7 +310,7 @@ def test_listpowers(self): R.append(R1) R.append(R2) nt.assert_equal(len(R), 3) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) array_compare(R[0], np.eye(3)) array_compare(R[1], R1) @@ -318,14 +318,14 @@ def test_listpowers(self): R = SO3([rotx(0.1), rotx(0.2), rotx(0.3)]) nt.assert_equal(len(R), 3) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) array_compare(R[0], rotx(0.1)) array_compare(R[1], rotx(0.2)) array_compare(R[2], rotx(0.3)) R = SO3([SO3.Rx(0.1), SO3.Rx(0.2), SO3.Rx(0.3)]) nt.assert_equal(len(R), 3) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) array_compare(R[0], rotx(0.1)) array_compare(R[1], rotx(0.2)) array_compare(R[2], rotx(0.3)) @@ -406,7 +406,7 @@ def test_arith(self): R = SO3() a = R * R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) array_compare(a, R) a = R * 2 @@ -419,7 +419,7 @@ def test_arith(self): R = SO3() R *= SO3.Rx(pi / 2) - self.assertIsInstance(R, SO3) + assert isinstance(R, SO3) array_compare(R, rotx(pi / 2)) R = SO3() @@ -458,7 +458,7 @@ def cv(v): # divide R = SO3.Ry(0.3) a = R / R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) array_compare(a, np.eye(3)) a = R / 2 @@ -492,21 +492,21 @@ def test_arith_vect(self): # multiply R = SO3([rx, ry, rz]) a = R * rx - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * rx) array_compare(a[2], rz * rx) a = rx * R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], rx * ry) array_compare(a[2], rx * rz) a = R * R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * ry) @@ -528,7 +528,7 @@ def test_arith_vect(self): a = R a *= rx - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * rx) @@ -536,7 +536,7 @@ def test_arith_vect(self): a = rx a *= R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], rx * ry) @@ -544,7 +544,7 @@ def test_arith_vect(self): a = R a *= R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * ry) @@ -576,21 +576,21 @@ def test_arith_vect(self): # divide R = SO3([rx, ry, rz]) a = R / rx - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], ry / rx) array_compare(a[2], rz / rx) a = rx / R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], rx / ry) array_compare(a[2], rx / rz) a = R / R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], np.eye(3)) array_compare(a[1], np.eye(3)) @@ -605,7 +605,7 @@ def test_arith_vect(self): a = R a /= rx - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], ry / rx) @@ -613,7 +613,7 @@ def test_arith_vect(self): a = rx a /= R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], rx / ry) @@ -621,7 +621,7 @@ def test_arith_vect(self): a = R a /= R - self.assertIsInstance(a, SO3) + assert isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], np.eye(3)) array_compare(a[1], np.eye(3)) @@ -733,111 +733,111 @@ def test_constructor(self): R = SE3() nt.assert_equal(len(R), 1) array_compare(R, np.eye(4)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) # construct from matrix R = SE3(trotx(0.2)) nt.assert_equal(len(R), 1) array_compare(R, trotx(0.2)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) # construct from canonic rotation R = SE3.Rx(0.2) nt.assert_equal(len(R), 1) array_compare(R, trotx(0.2)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.Ry(0.2) nt.assert_equal(len(R), 1) array_compare(R, troty(0.2)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.Rz(0.2) nt.assert_equal(len(R), 1) array_compare(R, trotz(0.2)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) # construct from canonic translation R = SE3.Tx(0.2) nt.assert_equal(len(R), 1) array_compare(R, transl(0.2, 0, 0)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.Ty(0.2) nt.assert_equal(len(R), 1) array_compare(R, transl(0, 0.2, 0)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.Tz(0.2) nt.assert_equal(len(R), 1) array_compare(R, transl(0, 0, 0.2)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) # triple angle R = SE3.Eul([0.1, 0.2, 0.3]) nt.assert_equal(len(R), 1) array_compare(R, eul2tr([0.1, 0.2, 0.3])) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.Eul(np.r_[0.1, 0.2, 0.3]) nt.assert_equal(len(R), 1) array_compare(R, eul2tr([0.1, 0.2, 0.3])) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.Eul([10, 20, 30], unit="deg") nt.assert_equal(len(R), 1) array_compare(R, eul2tr([10, 20, 30], unit="deg")) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.RPY([0.1, 0.2, 0.3]) nt.assert_equal(len(R), 1) array_compare(R, rpy2tr([0.1, 0.2, 0.3])) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.RPY(np.r_[0.1, 0.2, 0.3]) nt.assert_equal(len(R), 1) array_compare(R, rpy2tr([0.1, 0.2, 0.3])) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.RPY([10, 20, 30], unit="deg") nt.assert_equal(len(R), 1) array_compare(R, rpy2tr([10, 20, 30], unit="deg")) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.RPY([0.1, 0.2, 0.3], order="xyz") nt.assert_equal(len(R), 1) array_compare(R, rpy2tr([0.1, 0.2, 0.3], order="xyz")) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) # angvec R = SE3.AngVec(0.2, [1, 0, 0]) nt.assert_equal(len(R), 1) array_compare(R, trotx(0.2)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) R = SE3.AngVec(0.3, [0, 1, 0]) nt.assert_equal(len(R), 1) array_compare(R, troty(0.3)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) # OA R = SE3.OA([0, 1, 0], [0, 0, 1]) nt.assert_equal(len(R), 1) array_compare(R, np.eye(4)) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) np.random.seed(65) # random R = SE3.Rand() nt.assert_equal(len(R), 1) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) # random T = SE3.Rand() R = T.R t = T.t T = SE3.Rt(R, t) - self.assertIsInstance(T, SE3) + assert isinstance(T, SE3) self.assertEqual(T.A.shape, (4, 4)) nt.assert_equal(T.R, R) @@ -860,7 +860,7 @@ def test_constructor(self): # random constrained T = SE3.Rand(theta_range=(0.1, 0.7)) - self.assertIsInstance(T, SE3) + assert isinstance(T, SE3) self.assertEqual(T.A.shape, (4, 4)) self.assertLessEqual(T.angvec()[0], 0.7) self.assertGreaterEqual(T.angvec()[0], 0.1) @@ -874,13 +874,13 @@ def test_constructor(self): # SO3 T = SE3(SO3()) nt.assert_equal(len(T), 1) - self.assertIsInstance(T, SE3) + assert isinstance(T, SE3) nt.assert_equal(T.A, np.eye(4)) # SE2 T = SE3(SE2(1, 2, 0.4)) nt.assert_equal(len(T), 1) - self.assertIsInstance(T, SE3) + assert isinstance(T, SE3) self.assertEqual(T.A.shape, (4, 4)) nt.assert_equal(T.t, [1, 2, 0]) @@ -902,7 +902,7 @@ def test_listpowers(self): R.append(R1) R.append(R2) nt.assert_equal(len(R), 3) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) array_compare(R[0], np.eye(4)) array_compare(R[1], R1) @@ -910,14 +910,14 @@ def test_listpowers(self): R = SE3([trotx(0.1), trotx(0.2), trotx(0.3)]) nt.assert_equal(len(R), 3) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) array_compare(R[0], trotx(0.1)) array_compare(R[1], trotx(0.2)) array_compare(R[2], trotx(0.3)) R = SE3([SE3.Rx(0.1), SE3.Rx(0.2), SE3.Rx(0.3)]) nt.assert_equal(len(R), 3) - self.assertIsInstance(R, SE3) + assert isinstance(R, SE3) array_compare(R[0], trotx(0.1)) array_compare(R[1], trotx(0.2)) array_compare(R[2], trotx(0.3)) @@ -1022,7 +1022,7 @@ def test_arith(self): T = SE3(1, 2, 3) a = T * T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) array_compare(a, transl(2, 4, 6)) a = T * 2 @@ -1035,7 +1035,7 @@ def test_arith(self): T = SE3(1, 2, 3) T *= SE3.Ry(pi / 2) - self.assertIsInstance(T, SE3) + assert isinstance(T, SE3) array_compare( T, np.array([[0, 0, 1, 1], [0, 1, 0, 2], [-1, 0, 0, 3], [0, 0, 0, 1]]) ) @@ -1073,7 +1073,7 @@ def cv(v): # divide T = SE3.Ry(0.3) a = T / T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) array_compare(a, np.eye(4)) a = T / 2 @@ -1089,21 +1089,21 @@ def test_arith_vect(self): # multiply T = SE3([rx, ry, rz]) a = T * rx - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * rx) array_compare(a[2], rz * rx) a = rx * T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], rx * ry) array_compare(a[2], rx * rz) a = T * T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * ry) @@ -1125,7 +1125,7 @@ def test_arith_vect(self): a = T a *= rx - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * rx) @@ -1133,7 +1133,7 @@ def test_arith_vect(self): a = rx a *= T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], rx * ry) @@ -1141,7 +1141,7 @@ def test_arith_vect(self): a = T a *= T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * rx) array_compare(a[1], ry * ry) @@ -1173,21 +1173,21 @@ def test_arith_vect(self): # divide T = SE3([rx, ry, rz]) a = T / rx - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], ry / rx) array_compare(a[2], rz / rx) a = rx / T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], rx / ry) array_compare(a[2], rx / rz) a = T / T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], np.eye(4)) array_compare(a[1], np.eye(4)) @@ -1202,7 +1202,7 @@ def test_arith_vect(self): a = T a /= rx - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], ry / rx) @@ -1210,7 +1210,7 @@ def test_arith_vect(self): a = rx a /= T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / rx) array_compare(a[1], rx / ry) @@ -1218,7 +1218,7 @@ def test_arith_vect(self): a = T a /= T - self.assertIsInstance(a, SE3) + assert isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], np.eye(4)) array_compare(a[1], np.eye(4)) diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index 73c1b090..71271257 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -51,13 +51,13 @@ def test_constructor_variants(self): np.random.seed(73) q = UnitQuaternion.Rand(theta_range=(0.1, 0.7)) - self.assertIsInstance(q, UnitQuaternion) + assert isinstance(q, UnitQuaternion) self.assertLessEqual(q.angvec()[0], 0.7) self.assertGreaterEqual(q.angvec()[0], 0.1) q = UnitQuaternion.Rand(theta_range=(0.1, 0.7)) - self.assertIsInstance(q, UnitQuaternion) + assert isinstance(q, UnitQuaternion) self.assertLessEqual(q.angvec()[0], 0.7) self.assertGreaterEqual(q.angvec()[0], 0.1) @@ -184,20 +184,20 @@ def test_concat(self): u = UnitQuaternion() uu = UnitQuaternion([u, u, u, u]) - self.assertIsInstance(uu, UnitQuaternion) + assert isinstance(uu, UnitQuaternion) self.assertEqual(len(uu), 4) def test_string(self): u = UnitQuaternion() s = str(u) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertTrue(s.endswith(" >>")) self.assertEqual(s.count("\n"), 0) q = UnitQuaternion.Rx([0.3, 0.4, 0.5]) s = str(q) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 2) def test_properties(self): @@ -363,38 +363,38 @@ def test_resulttype(self): q = Quaternion([2, 0, 0, 0]) u = UnitQuaternion() - self.assertIsInstance(q * q, Quaternion) - self.assertIsInstance(q * u, Quaternion) - self.assertIsInstance(u * q, Quaternion) - self.assertIsInstance(u * u, UnitQuaternion) + assert isinstance(q * q, Quaternion) + assert isinstance(q * u, Quaternion) + assert isinstance(u * q, Quaternion) + assert isinstance(u * u, UnitQuaternion) - # self.assertIsInstance(u.*u, UnitQuaternion) + # assert isinstance(u.*u, UnitQuaternion) # other combos all fail, test this? - self.assertIsInstance(u / u, UnitQuaternion) + assert isinstance(u / u, UnitQuaternion) - self.assertIsInstance(u.conj(), UnitQuaternion) - self.assertIsInstance(u.inv(), UnitQuaternion) - self.assertIsInstance(u.unit(), UnitQuaternion) - self.assertIsInstance(q.unit(), UnitQuaternion) + assert isinstance(u.conj(), UnitQuaternion) + assert isinstance(u.inv(), UnitQuaternion) + assert isinstance(u.unit(), UnitQuaternion) + assert isinstance(q.unit(), UnitQuaternion) - self.assertIsInstance(q.conj(), Quaternion) + assert isinstance(q.conj(), Quaternion) - self.assertIsInstance(q + q, Quaternion) - self.assertIsInstance(q - q, Quaternion) + assert isinstance(q + q, Quaternion) + assert isinstance(q - q, Quaternion) - self.assertIsInstance(u + u, Quaternion) - self.assertIsInstance(u - u, Quaternion) + assert isinstance(u + u, Quaternion) + assert isinstance(u - u, Quaternion) - # self.assertIsInstance(q+u, Quaternion) - # self.assertIsInstance(u+q, Quaternion) + # assert isinstance(q+u, Quaternion) + # assert isinstance(u+q, Quaternion) - # self.assertIsInstance(q-u, Quaternion) - # self.assertIsInstance(u-q, Quaternion) + # assert isinstance(q-u, Quaternion) + # assert isinstance(u-q, Quaternion) # TODO test for ValueError in these cases - self.assertIsInstance(u.SO3(), SO3) - self.assertIsInstance(u.SE3(), SE3) + assert isinstance(u.SO3(), SO3) + assert isinstance(u.SE3(), SE3) def test_multiply(self): vx = np.r_[1, 0, 0] @@ -747,7 +747,7 @@ class TestQuaternion(unittest.TestCase): def test_constructor(self): q = Quaternion() self.assertEqual(len(q), 1) - self.assertIsInstance(q, Quaternion) + assert isinstance(q, Quaternion) nt.assert_array_almost_equal(Quaternion().vec, [0, 0, 0, 0]) @@ -797,14 +797,14 @@ def test_string(self): u = Quaternion() s = str(u) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertTrue(s.endswith(" >")) self.assertEqual(s.count("\n"), 0) self.assertEqual(len(s), 37) q = Quaternion([u, u, u]) s = str(q) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 2) def test_properties(self): @@ -834,7 +834,7 @@ def test_concat(self): u = Quaternion() uu = Quaternion([u, u, u, u]) - self.assertIsInstance(uu, Quaternion) + assert isinstance(uu, Quaternion) self.assertEqual(len(uu), 4) def primitive_test_convert(self): @@ -854,15 +854,15 @@ def primitive_test_convert(self): def test_resulttype(self): q = Quaternion([2, 0, 0, 0]) - self.assertIsInstance(q, Quaternion) + assert isinstance(q, Quaternion) # other combos all fail, test this? - self.assertIsInstance(q.conj(), Quaternion) - self.assertIsInstance(q.unit(), UnitQuaternion) + assert isinstance(q.conj(), Quaternion) + assert isinstance(q.unit(), UnitQuaternion) - self.assertIsInstance(q + q, Quaternion) - self.assertIsInstance(q + q, Quaternion) + assert isinstance(q + q, Quaternion) + assert isinstance(q + q, Quaternion) def test_multiply(self): q1 = Quaternion([1, 2, 3, 4]) @@ -1009,7 +1009,7 @@ def test_miscellany(self): # unit qu = q.unit() uu = UnitQuaternion() - self.assertIsInstance(q, Quaternion) + assert isinstance(q, Quaternion) nt.assert_array_almost_equal(qu.vec, v / np.linalg.norm(v)) qcompare(Quaternion([q, u, q]).unit(), UnitQuaternion([qu, uu, qu])) diff --git a/tests/test_spatialvector.py b/tests/test_spatialvector.py index bca0f4c3..92505349 100644 --- a/tests/test_spatialvector.py +++ b/tests/test_spatialvector.py @@ -16,175 +16,175 @@ def test_list_powers(self): self.assertEqual(len(x), 2) y = x[0] - self.assertIsInstance(y, SpatialVelocity) + assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) self.assertTrue(all(y.A == np.r_[1, 2, 3, 4, 5, 6])) y = x[1] - self.assertIsInstance(y, SpatialVelocity) + assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) self.assertTrue(all(y.A == np.r_[7, 8, 9, 10, 11, 12])) x.insert(0, SpatialVelocity([20, 21, 22, 23, 24, 25])) y = x[0] - self.assertIsInstance(y, SpatialVelocity) + assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) self.assertTrue(all(y.A == np.r_[20, 21, 22, 23, 24, 25])) y = x[1] - self.assertIsInstance(y, SpatialVelocity) + assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) self.assertTrue(all(y.A == np.r_[1, 2, 3, 4, 5, 6])) def test_velocity(self): a = SpatialVelocity([1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialVelocity) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialM6) + assert isinstance(a, SpatialVelocity) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) a = SpatialVelocity(np.r_[1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialVelocity) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialM6) + assert isinstance(a, SpatialVelocity) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) self.assertTrue(s.startswith("SpatialVelocity")) r = np.random.rand(6, 10) a = SpatialVelocity(r) - self.assertIsInstance(a, SpatialVelocity) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialM6) + assert isinstance(a, SpatialVelocity) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialM6) self.assertEqual(len(a), 10) b = a[3] - self.assertIsInstance(b, SpatialVelocity) - self.assertIsInstance(b, SpatialVector) - self.assertIsInstance(b, SpatialM6) + assert isinstance(b, SpatialVelocity) + assert isinstance(b, SpatialVector) + assert isinstance(b, SpatialM6) self.assertEqual(len(b), 1) self.assertTrue(all(b.A == r[:, 3])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 9) def test_acceleration(self): a = SpatialAcceleration([1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialAcceleration) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialM6) + assert isinstance(a, SpatialAcceleration) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) a = SpatialAcceleration(np.r_[1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialAcceleration) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialM6) + assert isinstance(a, SpatialAcceleration) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) self.assertTrue(s.startswith("SpatialAcceleration")) r = np.random.rand(6, 10) a = SpatialAcceleration(r) - self.assertIsInstance(a, SpatialAcceleration) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialM6) + assert isinstance(a, SpatialAcceleration) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialM6) self.assertEqual(len(a), 10) b = a[3] - self.assertIsInstance(b, SpatialAcceleration) - self.assertIsInstance(b, SpatialVector) - self.assertIsInstance(b, SpatialM6) + assert isinstance(b, SpatialAcceleration) + assert isinstance(b, SpatialVector) + assert isinstance(b, SpatialM6) self.assertEqual(len(b), 1) self.assertTrue(all(b.A == r[:, 3])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) def test_force(self): a = SpatialForce([1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialForce) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialF6) + assert isinstance(a, SpatialForce) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) a = SpatialForce(np.r_[1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialForce) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialF6) + assert isinstance(a, SpatialForce) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) self.assertTrue(s.startswith("SpatialForce")) r = np.random.rand(6, 10) a = SpatialForce(r) - self.assertIsInstance(a, SpatialForce) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialF6) + assert isinstance(a, SpatialForce) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialF6) self.assertEqual(len(a), 10) b = a[3] - self.assertIsInstance(b, SpatialForce) - self.assertIsInstance(b, SpatialVector) - self.assertIsInstance(b, SpatialF6) + assert isinstance(b, SpatialForce) + assert isinstance(b, SpatialVector) + assert isinstance(b, SpatialF6) self.assertEqual(len(b), 1) self.assertTrue(all(b.A == r[:, 3])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) def test_momentum(self): a = SpatialMomentum([1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialMomentum) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialF6) + assert isinstance(a, SpatialMomentum) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) a = SpatialMomentum(np.r_[1, 2, 3, 4, 5, 6]) - self.assertIsInstance(a, SpatialMomentum) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialF6) + assert isinstance(a, SpatialMomentum) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) self.assertTrue(s.startswith("SpatialMomentum")) r = np.random.rand(6, 10) a = SpatialMomentum(r) - self.assertIsInstance(a, SpatialMomentum) - self.assertIsInstance(a, SpatialVector) - self.assertIsInstance(a, SpatialF6) + assert isinstance(a, SpatialMomentum) + assert isinstance(a, SpatialVector) + assert isinstance(a, SpatialF6) self.assertEqual(len(a), 10) b = a[3] - self.assertIsInstance(b, SpatialMomentum) - self.assertIsInstance(b, SpatialVector) - self.assertIsInstance(b, SpatialF6) + assert isinstance(b, SpatialMomentum) + assert isinstance(b, SpatialVector) + assert isinstance(b, SpatialF6) self.assertEqual(len(b), 1) self.assertTrue(all(b.A == r[:, 3])) s = str(a) - self.assertIsInstance(s, str) + assert isinstance(s, str) def test_arith(self): # just test SpatialVelocity since all types derive from same superclass diff --git a/tests/test_twist.py b/tests/test_twist.py index 14623f96..d78a482e 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -33,7 +33,7 @@ def test_constructor(self): s = [1, 2, 3, 4, 5, 6] x = Twist3(s) - self.assertIsInstance(x, Twist3) + assert isinstance(x, Twist3) self.assertEqual(len(x), 1) array_compare(x.v, [1, 2, 3]) array_compare(x.w, [4, 5, 6]) @@ -65,7 +65,7 @@ def test_conversion_SE3(self): T = SE3.Rx(0) tw = Twist3(T) array_compare(tw.SE3(), T) - self.assertIsInstance(tw.SE3(), SE3) + assert isinstance(tw.SE3(), SE3) self.assertEqual(len(tw.SE3()), 1) T = SE3.Rx(0) * SE3(1, 2, 3) @@ -87,20 +87,20 @@ def test_list_constuctor(self): x = Twist3([1, 0, 0, 0, 0, 0]) a = Twist3([x,x,x,x]) - self.assertIsInstance(a, Twist3) + assert isinstance(a, Twist3) self.assertEqual(len(a), 4) a = Twist3([x.skewa(), x.skewa(), x.skewa(), x.skewa()]) - self.assertIsInstance(a, Twist3) + assert isinstance(a, Twist3) self.assertEqual(len(a), 4) a = Twist3([x.S, x.S, x.S, x.S]) - self.assertIsInstance(a, Twist3) + assert isinstance(a, Twist3) self.assertEqual(len(a), 4) s = np.r_[1, 2, 3, 4, 5, 6] a = Twist3([s, s, s, s]) - self.assertIsInstance(a, Twist3) + assert isinstance(a, Twist3) self.assertEqual(len(a), 4) def test_predicate(self): @@ -120,13 +120,13 @@ def test_predicate(self): def test_str(self): x = Twist3([1, 2, 3, 4, 5, 6]) s = str(x) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 14) self.assertEqual(s.count('\n'), 0) x.append(x) s = str(x) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 29) self.assertEqual(s.count('\n'), 1) @@ -200,7 +200,7 @@ def test_constructor(self): s = [1, 2, 3] x = Twist2(s) - self.assertIsInstance(x, Twist2) + assert isinstance(x, Twist2) self.assertEqual(len(x), 1) array_compare(x.v, [1, 2]) array_compare(x.w, [3]) @@ -252,7 +252,7 @@ def test_conversion_SE2(self): T = SE2(1, 2, 0.3) tw = Twist2(T) array_compare(tw.SE2(), T) - self.assertIsInstance(tw.SE2(), SE2) + assert isinstance(tw.SE2(), SE2) self.assertEqual(len(tw.SE2()), 1) def test_conversion_se2(self): @@ -267,20 +267,20 @@ def test_list_constuctor(self): x = Twist2([1, 0, 0]) a = Twist2([x,x,x,x]) - self.assertIsInstance(a, Twist2) + assert isinstance(a, Twist2) self.assertEqual(len(a), 4) a = Twist2([x.skewa(), x.skewa(), x.skewa(), x.skewa()]) - self.assertIsInstance(a, Twist2) + assert isinstance(a, Twist2) self.assertEqual(len(a), 4) a = Twist2([x.S, x.S, x.S, x.S]) - self.assertIsInstance(a, Twist2) + assert isinstance(a, Twist2) self.assertEqual(len(a), 4) s = np.r_[1, 2, 3] a = Twist2([s, s, s, s]) - self.assertIsInstance(a, Twist2) + assert isinstance(a, Twist2) self.assertEqual(len(a), 4) def test_predicate(self): @@ -300,13 +300,13 @@ def test_predicate(self): def test_str(self): x = Twist2([1, 2, 3]) s = str(x) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 8) self.assertEqual(s.count('\n'), 0) x.append(x) s = str(x) - self.assertIsInstance(s, str) + assert isinstance(s, str) self.assertEqual(len(s), 17) self.assertEqual(s.count('\n'), 1) From f672fe82ea5bc405a002a1f92ddc9cd3b7aa91b4 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:06:18 -0500 Subject: [PATCH 07/21] Replace all usage of assertTrue with a bare assert --- tests/base/test_numeric.py | 8 +++--- tests/base/test_quaternions.py | 2 +- tests/base/test_symbolic.py | 50 ++++++++++++++++----------------- tests/base/test_transforms2d.py | 4 +-- tests/base/test_transforms3d.py | 14 ++++----- tests/base/test_transformsNd.py | 38 ++++++++++++------------- tests/base/test_vectors.py | 36 ++++++++++++------------ tests/test_geom2d.py | 38 ++++++++++++------------- tests/test_geom3d.py | 34 +++++++++++----------- tests/test_pose2d.py | 8 +++--- tests/test_quaternion.py | 28 +++++++++--------- tests/test_spatialvector.py | 48 +++++++++++++++---------------- tests/test_twist.py | 12 ++++---- 13 files changed, 160 insertions(+), 160 deletions(-) diff --git a/tests/base/test_numeric.py b/tests/base/test_numeric.py index ff2fcc0f..71d3b9d2 100755 --- a/tests/base/test_numeric.py +++ b/tests/base/test_numeric.py @@ -64,7 +64,7 @@ def test_bresenham(self): z = np.array([x, y]) d = np.diff(z, axis=1) d = np.linalg.norm(d, axis=0) - self.assertTrue(all(d <= np.sqrt(2))) + assert all(d <= np.sqrt(2)) x, y = bresenham((20, 10), (-10, -10)) @@ -72,7 +72,7 @@ def test_bresenham(self): z = np.array([x, y]) d = np.diff(z, axis=1) d = np.linalg.norm(d, axis=0) - self.assertTrue(all(d <= np.sqrt(2))) + assert all(d <= np.sqrt(2)) x, y = bresenham((-10, -10), (10, 20)) @@ -80,7 +80,7 @@ def test_bresenham(self): z = np.array([x, y]) d = np.diff(z, axis=1) d = np.linalg.norm(d, axis=0) - self.assertTrue(all(d <= np.sqrt(2))) + assert all(d <= np.sqrt(2)) x, y = bresenham((10, 20), (-10, -10)) @@ -88,7 +88,7 @@ def test_bresenham(self): z = np.array([x, y]) d = np.diff(z, axis=1) d = np.linalg.norm(d, axis=0) - self.assertTrue(all(d <= np.sqrt(2))) + assert all(d <= np.sqrt(2)) def test_mpq(self): diff --git a/tests/base/test_quaternions.py b/tests/base/test_quaternions.py index c512c6d2..70eace50 100644 --- a/tests/base/test_quaternions.py +++ b/tests/base/test_quaternions.py @@ -136,7 +136,7 @@ def test_rotation(self): q2 = r2q(tr.rotx(large_rotation), shortest=True) self.assertLess(q1[0], 0) self.assertGreater(q2[0], 0) - self.assertTrue(qisequal(q1=q1, q2=q2, unitq=True)) + assert qisequal(q1=q1, q2=q2, unitq=True) def test_slerp(self): q1 = np.r_[0, 1, 0, 0] diff --git a/tests/base/test_symbolic.py b/tests/base/test_symbolic.py index 7a503b5b..7f688be1 100644 --- a/tests/base/test_symbolic.py +++ b/tests/base/test_symbolic.py @@ -15,26 +15,26 @@ class Test_symbolic(unittest.TestCase): @unittest.skipUnless(_symbolics, "sympy required") def test_symbol(self): theta = symbol("theta") - self.assertTrue(isinstance(theta, sp.Expr)) - self.assertTrue(theta.is_real) + assert isinstance(theta, sp.Expr) + assert theta.is_real theta = symbol("theta", real=False) - self.assertTrue(isinstance(theta, sp.Expr)) + assert isinstance(theta, sp.Expr) self.assertFalse(theta.is_real) theta, psi = symbol("theta, psi") - self.assertTrue(isinstance(theta, sp.Expr)) - self.assertTrue(isinstance(psi, sp.Expr)) + assert isinstance(theta, sp.Expr) + assert isinstance(psi, sp.Expr) theta, psi = symbol("theta psi") - self.assertTrue(isinstance(theta, sp.Expr)) - self.assertTrue(isinstance(psi, sp.Expr)) + assert isinstance(theta, sp.Expr) + assert isinstance(psi, sp.Expr) q = symbol("q:6") self.assertEqual(len(q), 6) for _ in q: - self.assertTrue(isinstance(_, sp.Expr)) - self.assertTrue(_.is_real) + assert isinstance(_, sp.Expr) + assert _.is_real @unittest.skipUnless(_symbolics, "sympy required") def test_issymbol(self): @@ -42,42 +42,42 @@ def test_issymbol(self): self.assertFalse(issymbol(3)) self.assertFalse(issymbol("not a symbol")) self.assertFalse(issymbol([1, 2])) - self.assertTrue(issymbol(theta)) + assert issymbol(theta) @unittest.skipUnless(_symbolics, "sympy required") def test_functions(self): theta = symbol("theta") - self.assertTrue(isinstance(sin(theta), sp.Expr)) - self.assertTrue(isinstance(sin(1.0), float)) + assert isinstance(sin(theta), sp.Expr) + assert isinstance(sin(1.0), float) - self.assertTrue(isinstance(cos(theta), sp.Expr)) - self.assertTrue(isinstance(cos(1.0), float)) + assert isinstance(cos(theta), sp.Expr) + assert isinstance(cos(1.0), float) - self.assertTrue(isinstance(sqrt(theta), sp.Expr)) - self.assertTrue(isinstance(sqrt(1.0), float)) + assert isinstance(sqrt(theta), sp.Expr) + assert isinstance(sqrt(1.0), float) x = (theta - 1) * (theta + 1) - theta ** 2 - self.assertTrue(math.isclose(simplify(x).evalf(), -1)) + assert math.isclose(simplify(x).evalf(), -1) @unittest.skipUnless(_symbolics, "sympy required") def test_constants(self): x = zero() - self.assertTrue(isinstance(x, sp.Expr)) - self.assertTrue(math.isclose(x.evalf(), 0)) + assert isinstance(x, sp.Expr) + assert math.isclose(x.evalf(), 0) x = one() - self.assertTrue(isinstance(x, sp.Expr)) - self.assertTrue(math.isclose(x.evalf(), 1)) + assert isinstance(x, sp.Expr) + assert math.isclose(x.evalf(), 1) x = negative_one() - self.assertTrue(isinstance(x, sp.Expr)) - self.assertTrue(math.isclose(x.evalf(), -1)) + assert isinstance(x, sp.Expr) + assert math.isclose(x.evalf(), -1) x = pi() - self.assertTrue(isinstance(x, sp.Expr)) - self.assertTrue(math.isclose(x.evalf(), math.pi)) + assert isinstance(x, sp.Expr) + assert math.isclose(x.evalf(), math.pi) # ---------------------------------------------------------------------------------------# diff --git a/tests/base/test_transforms2d.py b/tests/base/test_transforms2d.py index 84f6f91c..27b25685 100755 --- a/tests/base/test_transforms2d.py +++ b/tests/base/test_transforms2d.py @@ -102,14 +102,14 @@ def test_trnorm2(self): R = rot2(0.4) R = np.round(R, 3) # approx SO(2) R = trnorm2(R) - self.assertTrue(isrot2(R, check=True)) + assert isrot2(R, check=True) R = rot2(0.4) R = np.round(R, 3) # approx SO(2) T = rt2tr(R, [3, 4]) T = trnorm2(T) - self.assertTrue(ishom2(T, check=True)) + assert ishom2(T, check=True) nt.assert_almost_equal(T[:2, 2], [3, 4]) def test_transl2(self): diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index 74cf848f..abc1497e 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -442,14 +442,14 @@ def test_trnorm(self): R = rpy2r(0.2, 0.3, 0.4) R = np.round(R, 3) # approx SO(3) R = trnorm(R) - self.assertTrue(isrot(R, check=True)) + assert isrot(R, check=True) R = rpy2r(0.2, 0.3, 0.4) R = np.round(R, 3) # approx SO(3) T = rt2tr(R, [3, 4, 5]) T = trnorm(T) - self.assertTrue(ishom(T, check=True)) + assert ishom(T, check=True) nt.assert_almost_equal(T[:3, 3], [3, 4, 5]) def test_tr2eul(self): @@ -546,19 +546,19 @@ def test_print(self): s = trprint(T, file=None) assert isinstance(s, str) self.assertEqual(len(s), 42) - self.assertTrue("rpy" in s) - self.assertTrue("zyx" in s) + assert "rpy" in s + assert "zyx" in s s = trprint(T, file=None, orient="rpy/xyz") assert isinstance(s, str) self.assertEqual(len(s), 39) - self.assertTrue("rpy" in s) - self.assertTrue("xyz" in s) + assert "rpy" in s + assert "xyz" in s s = trprint(T, file=None, orient="eul") assert isinstance(s, str) self.assertEqual(len(s), 37) - self.assertTrue("eul" in s) + assert "eul" in s self.assertFalse("zyx" in s) def test_trinterp(self): diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index db561d6b..af6e9753 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -32,10 +32,10 @@ class TestND(unittest.TestCase): def test_iseye(self): - self.assertTrue(iseye(np.eye(1))) - self.assertTrue(iseye(np.eye(2))) - self.assertTrue(iseye(np.eye(3))) - self.assertTrue(iseye(np.eye(5))) + assert iseye(np.eye(1)) + assert iseye(np.eye(2)) + assert iseye(np.eye(3)) + assert iseye(np.eye(5)) self.assertFalse(iseye(2 * np.eye(3))) self.assertFalse(iseye(-np.eye(3))) @@ -80,7 +80,7 @@ def test_r2t_sym(self): self.assertEqual(r2t(R).dtype, "O") nt.assert_array_almost_equal(T[0:3, 3], np.r_[0, 0, 0]) # nt.assert_array_almost_equal(T[:3,:3], R) - self.assertTrue((T[:3, :3] == R).all()) + assert (T[:3, :3] == R).all() def test_t2r(self): # 3D @@ -189,24 +189,24 @@ def test_Ab2M(self): def test_checks(self): # 3D case, with rotation matrix R = np.eye(3) - self.assertTrue(isR(R)) + assert isR(R) self.assertFalse(isrot2(R)) - self.assertTrue(isrot(R)) + assert isrot(R) self.assertFalse(ishom(R)) - self.assertTrue(ishom2(R)) + assert ishom2(R) self.assertFalse(isrot2(R, True)) - self.assertTrue(isrot(R, True)) + assert isrot(R, True) self.assertFalse(ishom(R, True)) - self.assertTrue(ishom2(R, True)) + assert ishom2(R, True) # 3D case, invalid rotation matrix R = np.eye(3) R[0, 1] = 2 self.assertFalse(isR(R)) self.assertFalse(isrot2(R)) - self.assertTrue(isrot(R)) + assert isrot(R) self.assertFalse(ishom(R)) - self.assertTrue(ishom2(R)) + assert ishom2(R) self.assertFalse(isrot2(R, True)) self.assertFalse(isrot(R, True)) self.assertFalse(ishom(R, True)) @@ -217,11 +217,11 @@ def test_checks(self): self.assertFalse(isR(T)) self.assertFalse(isrot2(T)) self.assertFalse(isrot(T)) - self.assertTrue(ishom(T)) + assert ishom(T) self.assertFalse(ishom2(T)) self.assertFalse(isrot2(T, True)) self.assertFalse(isrot(T, True)) - self.assertTrue(ishom(T, True)) + assert ishom(T, True) self.assertFalse(ishom2(T, True)) # 3D case, invalid rotation matrix @@ -243,7 +243,7 @@ def test_checks(self): self.assertFalse(isR(T)) self.assertFalse(isrot2(T)) self.assertFalse(isrot(T)) - self.assertTrue(ishom(T)) + assert ishom(T) self.assertFalse(ishom2(T)) self.assertFalse(isrot2(T, True)) self.assertFalse(isrot(T, True)) @@ -331,14 +331,14 @@ def test_vex(self): def test_isskew(self): t = [3, 4, 5] sk = skew(t) - self.assertTrue(isskew(sk)) + assert isskew(sk) sk[0, 0] = 3 self.assertFalse(isskew(sk)) # 2D t = [3] sk = skew(t) - self.assertTrue(isskew(sk)) + assert isskew(sk) sk[0, 0] = 3 self.assertFalse(isskew(sk)) @@ -346,7 +346,7 @@ def test_isskewa(self): # 3D t = [3, 4, 5, 6, 7, 8] sk = skewa(t) - self.assertTrue(isskewa(sk)) + assert isskewa(sk) sk[0, 0] = 3 self.assertFalse(isskew(sk)) sk = skewa(t) @@ -356,7 +356,7 @@ def test_isskewa(self): # 2D t = [3, 4, 5] sk = skew(t) - self.assertTrue(isskew(sk)) + assert isskew(sk) sk[0, 0] = 3 self.assertFalse(isskew(sk)) sk = skewa(t) diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index be04c8ab..2707cf8a 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -67,18 +67,18 @@ def test_colvec(self): nt.assert_array_almost_equal(cv.flatten(), t) def test_isunitvec(self): - self.assertTrue(isunitvec([1, 0, 0])) - self.assertTrue(isunitvec((1, 0, 0))) - self.assertTrue(isunitvec(np.r_[1, 0, 0])) + assert isunitvec([1, 0, 0]) + assert isunitvec((1, 0, 0)) + assert isunitvec(np.r_[1, 0, 0]) self.assertFalse(isunitvec([9, 0, 0])) self.assertFalse(isunitvec((9, 0, 0))) self.assertFalse(isunitvec(np.r_[9, 0, 0])) - self.assertTrue(isunitvec(1)) - self.assertTrue(isunitvec([1])) - self.assertTrue(isunitvec(-1)) - self.assertTrue(isunitvec([-1])) + assert isunitvec(1) + assert isunitvec([1]) + assert isunitvec(-1) + assert isunitvec([-1]) self.assertFalse(isunitvec(2)) self.assertFalse(isunitvec([2])) @@ -108,33 +108,33 @@ def test_cross(self): for i in range(0, 3): j = (i + 1) % 3 k = (i + 2) % 3 - self.assertTrue(all(cross(A[:, i], A[:, j]) == A[:, k])) + assert all(cross(A[:, i], A[:, j]) == A[:, k]) def test_isunittwist(self): # 3D # unit rotational twist - self.assertTrue(isunittwist([1, 2, 3, 1, 0, 0])) - self.assertTrue(isunittwist((1, 2, 3, 1, 0, 0))) - self.assertTrue(isunittwist(np.r_[1, 2, 3, 1, 0, 0])) + assert isunittwist([1, 2, 3, 1, 0, 0]) + assert isunittwist((1, 2, 3, 1, 0, 0)) + assert isunittwist(np.r_[1, 2, 3, 1, 0, 0]) # not a unit rotational twist self.assertFalse(isunittwist([1, 2, 3, 1, 0, 1])) # unit translation twist - self.assertTrue(isunittwist([1, 0, 0, 0, 0, 0])) + assert isunittwist([1, 0, 0, 0, 0, 0]) # not a unit translation twist self.assertFalse(isunittwist([2, 0, 0, 0, 0, 0])) # 2D # unit rotational twist - self.assertTrue(isunittwist2([1, 2, 1])) + assert isunittwist2([1, 2, 1]) # not a unit rotational twist self.assertFalse(isunittwist2([1, 2, 3])) # unit translation twist - self.assertTrue(isunittwist2([1, 0, 0])) + assert isunittwist2([1, 0, 0]) # not a unit translation twist self.assertFalse(isunittwist2([2, 0, 0])) @@ -257,16 +257,16 @@ def test_unittwist2_norm(self): self.assertIsNone(a[1]) def test_iszerovec(self): - self.assertTrue(iszerovec([0])) - self.assertTrue(iszerovec([0, 0])) - self.assertTrue(iszerovec([0, 0, 0])) + assert iszerovec([0]) + assert iszerovec([0, 0]) + assert iszerovec([0, 0, 0]) self.assertFalse(iszerovec([1]), False) self.assertFalse(iszerovec([0, 1]), False) self.assertFalse(iszerovec([0, 1, 0]), False) def test_iszero(self): - self.assertTrue(iszero(0)) + assert iszero(0) self.assertFalse(iszero(1)) def test_angdiff(self): diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index 29dbe2a0..3c6b592c 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -42,18 +42,18 @@ def test_methods(self): def test_contains(self): p = Polygon2(np.array([[-1, 1, 1, -1], [-1, -1, 1, 1]])) - self.assertTrue(p.contains([0, 0], radius=1e-6)) - self.assertTrue(p.contains([1, 0], radius=1e-6)) - self.assertTrue(p.contains([-1, 0], radius=1e-6)) - self.assertTrue(p.contains([0, 1], radius=1e-6)) - self.assertTrue(p.contains([0, -1], radius=1e-6)) + assert p.contains([0, 0], radius=1e-6) + assert p.contains([1, 0], radius=1e-6) + assert p.contains([-1, 0], radius=1e-6) + assert p.contains([0, 1], radius=1e-6) + assert p.contains([0, -1], radius=1e-6) self.assertFalse(p.contains([0, 1.1], radius=1e-6)) self.assertFalse(p.contains([0, -1.1], radius=1e-6)) self.assertFalse(p.contains([1.1, 0], radius=1e-6)) self.assertFalse(p.contains([-1.1, 0], radius=1e-6)) - self.assertTrue(p.contains(np.r_[0, -1], radius=1e-6)) + assert p.contains(np.r_[0, -1], radius=1e-6) self.assertFalse(p.contains(np.r_[0, 1.1], radius=1e-6)) def test_transform(self): @@ -74,15 +74,15 @@ def test_intersect(self): self.assertFalse(p1.intersects(p2)) p2 = p1.transformed(SE2(1, 1)) - self.assertTrue(p1.intersects(p2)) + assert p1.intersects(p2) - self.assertTrue(p1.intersects(p1)) + assert p1.intersects(p1) def test_intersect_line(self): p = Polygon2(np.array([[-1, 1, 1, -1], [-1, -1, 1, 1]])) l = Line2.Join((-10, 0), (10, 0)) - self.assertTrue(p.intersects(l)) + assert p.intersects(l) l = Line2.Join((-10, 1.1), (10, 1.1)) self.assertFalse(p.intersects(l)) @@ -123,9 +123,9 @@ def test_constructor(self): def test_contains(self): l = Line2.Join((0, 0), (1, 2)) - self.assertTrue(l.contains((0, 0))) - self.assertTrue(l.contains((1, 2))) - self.assertTrue(l.contains((2, 4))) + assert l.contains((0, 0)) + assert l.contains((1, 2)) + assert l.contains((2, 4)) def test_intersect(self): l1 = Line2.Join((0, 0), (2, 0)) # y = 0 @@ -133,12 +133,12 @@ def test_intersect(self): self.assertFalse(l1.intersect(l2)) l2 = Line2.Join((2, 1), (2, -1)) # x = 2 - self.assertTrue(l1.intersect(l2)) + assert l1.intersect(l2) def test_intersect_segment(self): l1 = Line2.Join((0, 0), (2, 0)) # y = 0 self.assertFalse(l1.intersect_segment((2, 1), (2, 3))) - self.assertTrue(l1.intersect_segment((2, 1), (2, -1))) + assert l1.intersect_segment((2, 1), (2, -1)) class EllipseTest(unittest.TestCase): @@ -229,11 +229,11 @@ def test_misc(self): self.assertAlmostEqual(e.area, np.pi * 2) e = Ellipse(radii=(1, 2), theta=0) - self.assertTrue(e.contains((0, 0))) - self.assertTrue(e.contains((1, 0))) - self.assertTrue(e.contains((-1, 0))) - self.assertTrue(e.contains((0, 2))) - self.assertTrue(e.contains((0, -2))) + assert e.contains((0, 0)) + assert e.contains((1, 0)) + assert e.contains((-1, 0)) + assert e.contains((0, 2)) + assert e.contains((0, -2)) self.assertFalse(e.contains((1.1, 0))) self.assertFalse(e.contains((-1.1, 0))) diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index baf2fbfd..7550af70 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -37,7 +37,7 @@ def test_constructor1(self): # construct from point and direction L = Line3.PointDir([1, 2, 3], [4, 5, 6]) - self.assertTrue(L.contains([1, 2, 3])) + assert L.contains([1, 2, 3]) nt.assert_array_almost_equal(L.uw, base.unitvec([4, 5, 6])) def test_vec(self): @@ -82,7 +82,7 @@ def test_pp(self): self.assertEqual(L.ppd, math.sqrt(5)) # validate pp - self.assertTrue(L.contains(L.pp)) + assert L.contains(L.pp) def test_contains(self): P = [2, 3, 7] @@ -90,8 +90,8 @@ def test_contains(self): L = Line3.Join(P, Q) # validate contains - self.assertTrue(L.contains([2, 3, 7])) - self.assertTrue(L.contains([2, 1, 0])) + assert L.contains([2, 3, 7]) + assert L.contains([2, 1, 0]) self.assertFalse(L.contains([2, 1, 4])) def test_closest(self): @@ -150,11 +150,11 @@ def test_eq(self): L2 = Line3.Join(P + 2 * w, P + 5 * w) L3 = Line3.Join(P + np.r_[1, 0, 0], P + w) - self.assertTrue(L1 == L2) + assert L1 == L2 self.assertFalse(L1 == L3) self.assertFalse(L1 != L2) - self.assertTrue(L1 != L3) + assert L1 != L3 def test_skew(self): P = [2, 3, 7] @@ -196,13 +196,13 @@ def test_parallel(self): # L1, || L2, but doesnt intersect # L1, intersects L3 - self.assertTrue(L1.isparallel(L1)) - self.assertTrue(L1 | L1) + assert L1.isparallel(L1) + assert L1 | L1 - self.assertTrue(L1.isparallel(L2)) - self.assertTrue(L1 | L2) - self.assertTrue(L2.isparallel(L1)) - self.assertTrue(L2 | L1) + assert L1.isparallel(L2) + assert L1 | L2 + assert L2.isparallel(L1) + assert L2 | L1 self.assertFalse(L1.isparallel(L3)) self.assertFalse(L1 | L3) @@ -233,8 +233,8 @@ def test_commonperp(self): L = L1.commonperp(L2) # common perp intersects both lines - self.assertTrue(L ^ L1) - self.assertTrue(L ^ L2) + assert L ^ L1 + assert L ^ L2 def test_line(self): # mindist @@ -252,9 +252,9 @@ def test_contains(self): Q = [2, 1, 0] L = Line3.Join(P, Q) - self.assertTrue(L.contains(L.point(0))) - self.assertTrue(L.contains(L.point(1))) - self.assertTrue(L.contains(L.point(-1))) + assert L.contains(L.point(0)) + assert L.contains(L.point(1)) + assert L.contains(L.point(-1)) def test_point(self): P = [2, 3, 7] diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index 584bb041..f80f2c0c 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -113,7 +113,7 @@ def test_constructor_Exp(self): array_compare(x[2], rot2(1)) def test_isa(self): - self.assertTrue(SO2.isvalid(rot2(0))) + assert SO2.isvalid(rot2(0)) self.assertFalse(SO2.isvalid(1)) @@ -332,7 +332,7 @@ def test_constructor_Exp(self): array_compare(x[2], transl2(5, 6)) def test_isa(self): - self.assertTrue(SE2.isvalid(trot2(0))) + assert SE2.isvalid(trot2(0)) self.assertFalse(SE2.isvalid(1)) def test_resulttype(self): @@ -445,7 +445,7 @@ def test_conversions(self): ## Lie stuff x = TT.log() - self.assertTrue(isskewa(x)) + assert isskewa(x) def test_interp(self): TT = SE2(2, -4, 0.6) @@ -473,7 +473,7 @@ def test_miscellany(self): self.assertEqual(TT.A.shape, (3, 3)) - self.assertTrue(TT.isSE) + assert TT.isSE assert isinstance(TT, SE2) diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index 71271257..03688df6 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -192,7 +192,7 @@ def test_string(self): s = str(u) assert isinstance(s, str) - self.assertTrue(s.endswith(" >>")) + assert s.endswith(" >>") self.assertEqual(s.count("\n"), 0) q = UnitQuaternion.Rx([0.3, 0.4, 0.5]) @@ -522,7 +522,7 @@ def test_angle(self): uq1.angdist(other=uq2, metric=metric), uq2.angdist(other=uq1, metric=metric), ) - self.assertTrue(uq1.angdist(other=uq2, metric=metric) > 0) + assert uq1.angdist(other=uq2, metric=metric) > 0 def test_conversions(self): # , 3 angle @@ -615,7 +615,7 @@ def test_interp(self): qcompare(q.interp1(1), q) # self.assertEqual(length(q.interp(linspace(0,1, 10))), 10) - # self.assertTrue(all( q.interp([0, 1]) == [u, q])) + # assert all( q.interp([0, 1]) == [u, q]) # TODO vectorizing q0_5 = q.interp1(0.5) @@ -637,7 +637,7 @@ def test_interp(self): qq = rx.interp(q, 11) self.assertEqual(len(qq), 11) - # self.assertTrue(all( q.interp([0, 1], dest=rx, ) == [q, rx])) + # assert all( q.interp([0, 1], dest=rx, ) == [q, rx]) # test shortest option # q1 = UnitQuaternion.Rx(0.9*pi) @@ -671,10 +671,10 @@ def test_eq(self): q2 = UnitQuaternion([0, -1, 0, 0]) q3 = UnitQuaternion.Rz(pi / 2) - self.assertTrue(q1 == q1) - self.assertTrue(q2 == q2) - self.assertTrue(q3 == q3) - self.assertTrue(q1 == q2) # because of double wrapping + assert q1 == q1 + assert q2 == q2 + assert q3 == q3 + assert q1 == q2 # because of double wrapping self.assertFalse(q1 == q3) nt.assert_array_almost_equal( @@ -697,7 +697,7 @@ def test_logical(self): ry = UnitQuaternion.Ry(pi / 2) # equality tests - self.assertTrue(rx == rx) + assert rx == rx self.assertFalse(rx != rx) self.assertFalse(rx == ry) @@ -798,7 +798,7 @@ def test_string(self): s = str(u) assert isinstance(s, str) - self.assertTrue(s.endswith(" >")) + assert s.endswith(" >") self.assertEqual(s.count("\n"), 0) self.assertEqual(len(s), 37) @@ -824,8 +824,8 @@ def test_log(self): q1 = Quaternion([4, 3, 2, 1]) q2 = Quaternion([-1, 2, -3, 4]) - self.assertTrue(isscalar(q1.log().s)) - self.assertTrue(isvector(q1.log().v, 3)) + assert isscalar(q1.log().s) + assert isvector(q1.log().v, 3) nt.assert_array_almost_equal(q1.log().exp(), q1) nt.assert_array_almost_equal(q2.log().exp(), q2) @@ -930,10 +930,10 @@ def test_equality(self): q1 = Quaternion([1, 2, 3, 4]) q2 = Quaternion([-2, 1, -4, 3]) - self.assertTrue(q1 == q1) + assert q1 == q1 self.assertFalse(q1 == q2) - self.assertTrue(q1 != q2) + assert q1 != q2 self.assertFalse(q2 != q2) qt1 = Quaternion([q1, q1, q2, q2]) diff --git a/tests/test_spatialvector.py b/tests/test_spatialvector.py index 92505349..30936cac 100644 --- a/tests/test_spatialvector.py +++ b/tests/test_spatialvector.py @@ -18,24 +18,24 @@ def test_list_powers(self): y = x[0] assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) - self.assertTrue(all(y.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(y.A == np.r_[1, 2, 3, 4, 5, 6]) y = x[1] assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) - self.assertTrue(all(y.A == np.r_[7, 8, 9, 10, 11, 12])) + assert all(y.A == np.r_[7, 8, 9, 10, 11, 12]) x.insert(0, SpatialVelocity([20, 21, 22, 23, 24, 25])) y = x[0] assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) - self.assertTrue(all(y.A == np.r_[20, 21, 22, 23, 24, 25])) + assert all(y.A == np.r_[20, 21, 22, 23, 24, 25]) y = x[1] assert isinstance(y, SpatialVelocity) self.assertEqual(len(y), 1) - self.assertTrue(all(y.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(y.A == np.r_[1, 2, 3, 4, 5, 6]) def test_velocity(self): a = SpatialVelocity([1, 2, 3, 4, 5, 6]) @@ -43,19 +43,19 @@ def test_velocity(self): assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialVelocity(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialVelocity) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) - self.assertTrue(s.startswith("SpatialVelocity")) + assert s.startswith("SpatialVelocity") r = np.random.rand(6, 10) a = SpatialVelocity(r) @@ -69,7 +69,7 @@ def test_velocity(self): assert isinstance(b, SpatialVector) assert isinstance(b, SpatialM6) self.assertEqual(len(b), 1) - self.assertTrue(all(b.A == r[:, 3])) + assert all(b.A == r[:, 3]) s = str(a) assert isinstance(s, str) @@ -81,19 +81,19 @@ def test_acceleration(self): assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialAcceleration(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialAcceleration) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) - self.assertTrue(s.startswith("SpatialAcceleration")) + assert s.startswith("SpatialAcceleration") r = np.random.rand(6, 10) a = SpatialAcceleration(r) @@ -107,7 +107,7 @@ def test_acceleration(self): assert isinstance(b, SpatialVector) assert isinstance(b, SpatialM6) self.assertEqual(len(b), 1) - self.assertTrue(all(b.A == r[:, 3])) + assert all(b.A == r[:, 3]) s = str(a) assert isinstance(s, str) @@ -118,19 +118,19 @@ def test_force(self): assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialForce(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialForce) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) - self.assertTrue(s.startswith("SpatialForce")) + assert s.startswith("SpatialForce") r = np.random.rand(6, 10) a = SpatialForce(r) @@ -144,7 +144,7 @@ def test_force(self): assert isinstance(b, SpatialVector) assert isinstance(b, SpatialF6) self.assertEqual(len(b), 1) - self.assertTrue(all(b.A == r[:, 3])) + assert all(b.A == r[:, 3]) s = str(a) assert isinstance(s, str) @@ -155,19 +155,19 @@ def test_momentum(self): assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialMomentum(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialMomentum) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) self.assertEqual(len(a), 1) - self.assertTrue(all(a.A == np.r_[1, 2, 3, 4, 5, 6])) + assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) self.assertEqual(s.count("\n"), 0) - self.assertTrue(s.startswith("SpatialMomentum")) + assert s.startswith("SpatialMomentum") r = np.random.rand(6, 10) a = SpatialMomentum(r) @@ -181,7 +181,7 @@ def test_momentum(self): assert isinstance(b, SpatialVector) assert isinstance(b, SpatialF6) self.assertEqual(len(b), 1) - self.assertTrue(all(b.A == r[:, 3])) + assert all(b.A == r[:, 3]) s = str(a) assert isinstance(s, str) @@ -194,9 +194,9 @@ def test_arith(self): a1 = SpatialVelocity(r1) a2 = SpatialVelocity(r2) - self.assertTrue(all((a1 + a2).A == r1 + r2)) - self.assertTrue(all((a1 - a2).A == r1 - r2)) - self.assertTrue(all((-a1).A == -r1)) + assert all((a1 + a2).A == r1 + r2) + assert all((a1 - a2).A == r1 - r2) + assert all((-a1).A == -r1) def test_inertia(self): # constructor @@ -219,7 +219,7 @@ def test_inertia(self): nt.assert_almost_equal((i4a + i4b).A, SpatialInertia(m=m_a + m_b, r=r).A) # isvalid - note this method is very barebone, to be improved - self.assertTrue(SpatialInertia().isvalid(np.ones((6, 6)), check=False)) + assert SpatialInertia().isvalid(np.ones((6, 6)), check=False) def test_products(self): # v x v = a *, v x F6 = a diff --git a/tests/test_twist.py b/tests/test_twist.py index d78a482e..4088d6f2 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -109,10 +109,10 @@ def test_predicate(self): # check prismatic twist x = Twist3.UnitPrismatic([1, 2, 3]) - self.assertTrue(x.isprismatic) + assert x.isprismatic - self.assertTrue(Twist3.isvalid(x.skewa())) - self.assertTrue(Twist3.isvalid(x.S)) + assert Twist3.isvalid(x.skewa()) + assert Twist3.isvalid(x.S) self.assertFalse(Twist3.isvalid(2)) self.assertFalse(Twist3.isvalid(np.eye(4))) @@ -289,10 +289,10 @@ def test_predicate(self): # check prismatic twist x = Twist2.UnitPrismatic([1, 2]) - self.assertTrue(x.isprismatic) + assert x.isprismatic - self.assertTrue(Twist2.isvalid(x.skewa())) - self.assertTrue(Twist2.isvalid(x.S)) + assert Twist2.isvalid(x.skewa()) + assert Twist2.isvalid(x.S) self.assertFalse(Twist2.isvalid(2)) self.assertFalse(Twist2.isvalid(np.eye(3))) From d554cdbe57d0ae598da795208ffc29a79e4b3536 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:08:35 -0500 Subject: [PATCH 08/21] Replace all usage of assertFalse with a bare assert --- tests/base/test_symbolic.py | 8 +-- tests/base/test_transforms3d.py | 2 +- tests/base/test_transformsNd.py | 88 ++++++++++++++++----------------- tests/base/test_vectors.py | 30 +++++------ tests/test_geom2d.py | 26 +++++----- tests/test_geom3d.py | 14 +++--- tests/test_pose2d.py | 6 +-- tests/test_quaternion.py | 10 ++-- tests/test_twist.py | 12 ++--- 9 files changed, 98 insertions(+), 98 deletions(-) diff --git a/tests/base/test_symbolic.py b/tests/base/test_symbolic.py index 7f688be1..2ca7e1e9 100644 --- a/tests/base/test_symbolic.py +++ b/tests/base/test_symbolic.py @@ -20,7 +20,7 @@ def test_symbol(self): theta = symbol("theta", real=False) assert isinstance(theta, sp.Expr) - self.assertFalse(theta.is_real) + assert not theta.is_real theta, psi = symbol("theta, psi") assert isinstance(theta, sp.Expr) @@ -39,9 +39,9 @@ def test_symbol(self): @unittest.skipUnless(_symbolics, "sympy required") def test_issymbol(self): theta = symbol("theta") - self.assertFalse(issymbol(3)) - self.assertFalse(issymbol("not a symbol")) - self.assertFalse(issymbol([1, 2])) + assert not issymbol(3) + assert not issymbol("not a symbol") + assert not issymbol([1, 2]) assert issymbol(theta) @unittest.skipUnless(_symbolics, "sympy required") diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index abc1497e..c3b4eda5 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -559,7 +559,7 @@ def test_print(self): assert isinstance(s, str) self.assertEqual(len(s), 37) assert "eul" in s - self.assertFalse("zyx" in s) + assert not "zyx" in s def test_trinterp(self): R0 = rotx(-0.3) diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index af6e9753..683f5b8e 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -37,10 +37,10 @@ def test_iseye(self): assert iseye(np.eye(3)) assert iseye(np.eye(5)) - self.assertFalse(iseye(2 * np.eye(3))) - self.assertFalse(iseye(-np.eye(3))) - self.assertFalse(iseye(np.array([[1, 0, 0], [0, 1, 0]]))) - self.assertFalse(iseye(np.array([1, 0, 0]))) + assert not iseye(2 * np.eye(3)) + assert not iseye(-np.eye(3)) + assert not iseye(np.array([[1, 0, 0], [0, 1, 0]])) + assert not iseye(np.array([1, 0, 0])) def test_r2t(self): # 3D @@ -190,65 +190,65 @@ def test_checks(self): # 3D case, with rotation matrix R = np.eye(3) assert isR(R) - self.assertFalse(isrot2(R)) + assert not isrot2(R) assert isrot(R) - self.assertFalse(ishom(R)) + assert not ishom(R) assert ishom2(R) - self.assertFalse(isrot2(R, True)) + assert not isrot2(R, True) assert isrot(R, True) - self.assertFalse(ishom(R, True)) + assert not ishom(R, True) assert ishom2(R, True) # 3D case, invalid rotation matrix R = np.eye(3) R[0, 1] = 2 - self.assertFalse(isR(R)) - self.assertFalse(isrot2(R)) + assert not isR(R) + assert not isrot2(R) assert isrot(R) - self.assertFalse(ishom(R)) + assert not ishom(R) assert ishom2(R) - self.assertFalse(isrot2(R, True)) - self.assertFalse(isrot(R, True)) - self.assertFalse(ishom(R, True)) - self.assertFalse(ishom2(R, True)) + assert not isrot2(R, True) + assert not isrot(R, True) + assert not ishom(R, True) + assert not ishom2(R, True) # 3D case, with rotation matrix T = np.array([[1, 0, 0, 3], [0, 1, 0, 4], [0, 0, 1, 5], [0, 0, 0, 1]]) - self.assertFalse(isR(T)) - self.assertFalse(isrot2(T)) - self.assertFalse(isrot(T)) + assert not isR(T) + assert not isrot2(T) + assert not isrot(T) assert ishom(T) - self.assertFalse(ishom2(T)) - self.assertFalse(isrot2(T, True)) - self.assertFalse(isrot(T, True)) + assert not ishom2(T) + assert not isrot2(T, True) + assert not isrot(T, True) assert ishom(T, True) - self.assertFalse(ishom2(T, True)) + assert not ishom2(T, True) # 3D case, invalid rotation matrix T = np.array([[1, 0, 0, 3], [0, 1, 1, 4], [0, 0, 1, 5], [0, 0, 0, 1]]) - self.assertFalse(isR(T)) - self.assertFalse(isrot2(T)) - self.assertFalse(isrot(T)) + assert not isR(T) + assert not isrot2(T) + assert not isrot(T) self.assertTrue( ishom(T), ) - self.assertFalse(ishom2(T)) - self.assertFalse(isrot2(T, True)) - self.assertFalse(isrot(T, True)) - self.assertFalse(ishom(T, True)) - self.assertFalse(ishom2(T, True)) + assert not ishom2(T) + assert not isrot2(T, True) + assert not isrot(T, True) + assert not ishom(T, True) + assert not ishom2(T, True) # 3D case, invalid bottom row T = np.array([[1, 0, 0, 3], [0, 1, 1, 4], [0, 0, 1, 5], [9, 0, 0, 1]]) - self.assertFalse(isR(T)) - self.assertFalse(isrot2(T)) - self.assertFalse(isrot(T)) + assert not isR(T) + assert not isrot2(T) + assert not isrot(T) assert ishom(T) - self.assertFalse(ishom2(T)) - self.assertFalse(isrot2(T, True)) - self.assertFalse(isrot(T, True)) - self.assertFalse(ishom(T, True)) - self.assertFalse(ishom2(T, True)) + assert not ishom2(T) + assert not isrot2(T, True) + assert not isrot(T, True) + assert not ishom(T, True) + assert not ishom2(T, True) # skew matrices S = np.array([[0, 2], [-2, 0]]) @@ -333,14 +333,14 @@ def test_isskew(self): sk = skew(t) assert isskew(sk) sk[0, 0] = 3 - self.assertFalse(isskew(sk)) + assert not isskew(sk) # 2D t = [3] sk = skew(t) assert isskew(sk) sk[0, 0] = 3 - self.assertFalse(isskew(sk)) + assert not isskew(sk) def test_isskewa(self): # 3D @@ -348,20 +348,20 @@ def test_isskewa(self): sk = skewa(t) assert isskewa(sk) sk[0, 0] = 3 - self.assertFalse(isskew(sk)) + assert not isskew(sk) sk = skewa(t) sk[3, 3] = 3 - self.assertFalse(isskew(sk)) + assert not isskew(sk) # 2D t = [3, 4, 5] sk = skew(t) assert isskew(sk) sk[0, 0] = 3 - self.assertFalse(isskew(sk)) + assert not isskew(sk) sk = skewa(t) sk[2, 2] = 3 - self.assertFalse(isskew(sk)) + assert not isskew(sk) def test_skewa(self): # 3D diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index 2707cf8a..da0c3b34 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -71,19 +71,19 @@ def test_isunitvec(self): assert isunitvec((1, 0, 0)) assert isunitvec(np.r_[1, 0, 0]) - self.assertFalse(isunitvec([9, 0, 0])) - self.assertFalse(isunitvec((9, 0, 0))) - self.assertFalse(isunitvec(np.r_[9, 0, 0])) + assert not isunitvec([9, 0, 0]) + assert not isunitvec((9, 0, 0)) + assert not isunitvec(np.r_[9, 0, 0]) assert isunitvec(1) assert isunitvec([1]) assert isunitvec(-1) assert isunitvec([-1]) - self.assertFalse(isunitvec(2)) - self.assertFalse(isunitvec([2])) - self.assertFalse(isunitvec(-2)) - self.assertFalse(isunitvec([-2])) + assert not isunitvec(2) + assert not isunitvec([2]) + assert not isunitvec(-2) + assert not isunitvec([-2]) def test_norm(self): self.assertAlmostEqual(norm([0, 0, 0]), 0) @@ -118,26 +118,26 @@ def test_isunittwist(self): assert isunittwist(np.r_[1, 2, 3, 1, 0, 0]) # not a unit rotational twist - self.assertFalse(isunittwist([1, 2, 3, 1, 0, 1])) + assert not isunittwist([1, 2, 3, 1, 0, 1]) # unit translation twist assert isunittwist([1, 0, 0, 0, 0, 0]) # not a unit translation twist - self.assertFalse(isunittwist([2, 0, 0, 0, 0, 0])) + assert not isunittwist([2, 0, 0, 0, 0, 0]) # 2D # unit rotational twist assert isunittwist2([1, 2, 1]) # not a unit rotational twist - self.assertFalse(isunittwist2([1, 2, 3])) + assert not isunittwist2([1, 2, 3]) # unit translation twist assert isunittwist2([1, 0, 0]) # not a unit translation twist - self.assertFalse(isunittwist2([2, 0, 0])) + assert not isunittwist2([2, 0, 0]) with self.assertRaises(ValueError): isunittwist([3, 4]) @@ -261,13 +261,13 @@ def test_iszerovec(self): assert iszerovec([0, 0]) assert iszerovec([0, 0, 0]) - self.assertFalse(iszerovec([1]), False) - self.assertFalse(iszerovec([0, 1]), False) - self.assertFalse(iszerovec([0, 1, 0]), False) + assert not iszerovec([1]), False + assert not iszerovec([0, 1]), False + assert not iszerovec([0, 1, 0]), False def test_iszero(self): assert iszero(0) - self.assertFalse(iszero(1)) + assert not iszero(1) def test_angdiff(self): self.assertEqual(angdiff(0, 0), 0) diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index 3c6b592c..b079a108 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -48,13 +48,13 @@ def test_contains(self): assert p.contains([0, 1], radius=1e-6) assert p.contains([0, -1], radius=1e-6) - self.assertFalse(p.contains([0, 1.1], radius=1e-6)) - self.assertFalse(p.contains([0, -1.1], radius=1e-6)) - self.assertFalse(p.contains([1.1, 0], radius=1e-6)) - self.assertFalse(p.contains([-1.1, 0], radius=1e-6)) + assert not p.contains([0, 1.1], radius=1e-6) + assert not p.contains([0, -1.1], radius=1e-6) + assert not p.contains([1.1, 0], radius=1e-6) + assert not p.contains([-1.1, 0], radius=1e-6) assert p.contains(np.r_[0, -1], radius=1e-6) - self.assertFalse(p.contains(np.r_[0, 1.1], radius=1e-6)) + assert not p.contains(np.r_[0, 1.1], radius=1e-6) def test_transform(self): p = Polygon2(np.array([[-1, 1, 1, -1], [-1, -1, 1, 1]])) @@ -71,7 +71,7 @@ def test_intersect(self): p1 = Polygon2(np.array([[-1, 1, 1, -1], [-1, -1, 1, 1]])) p2 = p1.transformed(SE2(2, 3)) - self.assertFalse(p1.intersects(p2)) + assert not p1.intersects(p2) p2 = p1.transformed(SE2(1, 1)) assert p1.intersects(p2) @@ -85,7 +85,7 @@ def test_intersect_line(self): assert p.intersects(l) l = Line2.Join((-10, 1.1), (10, 1.1)) - self.assertFalse(p.intersects(l)) + assert not p.intersects(l) @pytest.mark.skipif( sys.platform.startswith("darwin") and sys.version_info < (3, 11), @@ -130,14 +130,14 @@ def test_contains(self): def test_intersect(self): l1 = Line2.Join((0, 0), (2, 0)) # y = 0 l2 = Line2.Join((0, 1), (2, 1)) # y = 1 - self.assertFalse(l1.intersect(l2)) + assert not l1.intersect(l2) l2 = Line2.Join((2, 1), (2, -1)) # x = 2 assert l1.intersect(l2) def test_intersect_segment(self): l1 = Line2.Join((0, 0), (2, 0)) # y = 0 - self.assertFalse(l1.intersect_segment((2, 1), (2, 3))) + assert not l1.intersect_segment((2, 1), (2, 3)) assert l1.intersect_segment((2, 1), (2, -1)) @@ -235,10 +235,10 @@ def test_misc(self): assert e.contains((0, 2)) assert e.contains((0, -2)) - self.assertFalse(e.contains((1.1, 0))) - self.assertFalse(e.contains((-1.1, 0))) - self.assertFalse(e.contains((0, 2.1))) - self.assertFalse(e.contains((0, -2.1))) + assert not e.contains((1.1, 0)) + assert not e.contains((-1.1, 0)) + assert not e.contains((0, 2.1)) + assert not e.contains((0, -2.1)) self.assertEqual(e.contains(np.array([[0, 0], [3, 3]]).T), [True, False]) diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 7550af70..00e0d79d 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -92,7 +92,7 @@ def test_contains(self): # validate contains assert L.contains([2, 3, 7]) assert L.contains([2, 1, 0]) - self.assertFalse(L.contains([2, 1, 4])) + assert not L.contains([2, 1, 4]) def test_closest(self): P = [2, 3, 7] @@ -151,9 +151,9 @@ def test_eq(self): L3 = Line3.Join(P + np.r_[1, 0, 0], P + w) assert L1 == L2 - self.assertFalse(L1 == L3) + assert not L1 == L3 - self.assertFalse(L1 != L2) + assert not L1 != L2 assert L1 != L3 def test_skew(self): @@ -203,8 +203,8 @@ def test_parallel(self): assert L1 | L2 assert L2.isparallel(L1) assert L2 | L1 - self.assertFalse(L1.isparallel(L3)) - self.assertFalse(L1 | L3) + assert not L1.isparallel(L3) + assert not L1 | L3 def test_intersect(self): L1 = Line3.PointDir([4, 5, 6], [1, 2, 3]) @@ -226,8 +226,8 @@ def test_commonperp(self): L1 = Line3.PointDir([4, 5, 6], [0, 0, 1]) L2 = Line3.PointDir([6, 5, 6], [0, 1, 0]) - self.assertFalse(L1 | L2) - self.assertFalse(L1 ^ L2) + assert not L1 | L2 + assert not L1 ^ L2 self.assertEqual(L1.distance(L2), 2) diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index f80f2c0c..bfb559b2 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -115,7 +115,7 @@ def test_constructor_Exp(self): def test_isa(self): assert SO2.isvalid(rot2(0)) - self.assertFalse(SO2.isvalid(1)) + assert not SO2.isvalid(1) def test_resulttype(self): r = SO2() @@ -205,7 +205,7 @@ def test_miscellany(self): self.assertEqual(r.N, 2) - self.assertFalse(r.isSE) + assert not r.isSE def test_printline(self): R = SO2(0.3) @@ -333,7 +333,7 @@ def test_constructor_Exp(self): def test_isa(self): assert SE2.isvalid(trot2(0)) - self.assertFalse(SE2.isvalid(1)) + assert not SE2.isvalid(1) def test_resulttype(self): t = SE2() diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index 03688df6..b174c316 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -675,7 +675,7 @@ def test_eq(self): assert q2 == q2 assert q3 == q3 assert q1 == q2 # because of double wrapping - self.assertFalse(q1 == q3) + assert not q1 == q3 nt.assert_array_almost_equal( UnitQuaternion([q1, q1, q1]) == UnitQuaternion([q1, q1, q1]), @@ -698,8 +698,8 @@ def test_logical(self): # equality tests assert rx == rx - self.assertFalse(rx != rx) - self.assertFalse(rx == ry) + assert not rx != rx + assert not rx == ry def test_dot(self): q = UnitQuaternion() @@ -931,10 +931,10 @@ def test_equality(self): q2 = Quaternion([-2, 1, -4, 3]) assert q1 == q1 - self.assertFalse(q1 == q2) + assert not q1 == q2 assert q1 != q2 - self.assertFalse(q2 != q2) + assert not q2 != q2 qt1 = Quaternion([q1, q1, q2, q2]) qt2 = Quaternion([q1, q2, q2, q1]) diff --git a/tests/test_twist.py b/tests/test_twist.py index 4088d6f2..f48cd106 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -105,7 +105,7 @@ def test_list_constuctor(self): def test_predicate(self): x = Twist3.UnitRevolute([1, 2, 3], [0, 0, 0]) - self.assertFalse(x.isprismatic) + assert not x.isprismatic # check prismatic twist x = Twist3.UnitPrismatic([1, 2, 3]) @@ -114,8 +114,8 @@ def test_predicate(self): assert Twist3.isvalid(x.skewa()) assert Twist3.isvalid(x.S) - self.assertFalse(Twist3.isvalid(2)) - self.assertFalse(Twist3.isvalid(np.eye(4))) + assert not Twist3.isvalid(2) + assert not Twist3.isvalid(np.eye(4)) def test_str(self): x = Twist3([1, 2, 3, 4, 5, 6]) @@ -285,7 +285,7 @@ def test_list_constuctor(self): def test_predicate(self): x = Twist2.UnitRevolute([1, 2]) - self.assertFalse(x.isprismatic) + assert not x.isprismatic # check prismatic twist x = Twist2.UnitPrismatic([1, 2]) @@ -294,8 +294,8 @@ def test_predicate(self): assert Twist2.isvalid(x.skewa()) assert Twist2.isvalid(x.S) - self.assertFalse(Twist2.isvalid(2)) - self.assertFalse(Twist2.isvalid(np.eye(3))) + assert not Twist2.isvalid(2) + assert not Twist2.isvalid(np.eye(3)) def test_str(self): x = Twist2([1, 2, 3]) From dda914d07cd41b74127328b7ec9159d21c3513a6 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:33:17 -0500 Subject: [PATCH 09/21] Replace assertEqual with bare assert --- tests/base/test_numeric.py | 30 ++++++------- tests/base/test_symbolic.py | 2 +- tests/base/test_transforms2d.py | 2 +- tests/base/test_transforms3d.py | 8 ++-- tests/base/test_transformsNd.py | 26 ++++++------ tests/base/test_vectors.py | 12 +++--- tests/base/test_velocity.py | 8 ++-- tests/test_dualquaternion.py | 2 +- tests/test_geom2d.py | 26 ++++++------ tests/test_geom3d.py | 28 ++++++------ tests/test_pose2d.py | 48 ++++++++++----------- tests/test_pose3d.py | 42 +++++++++--------- tests/test_quaternion.py | 75 ++++++++++++++++----------------- tests/test_spatialvector.py | 56 ++++++++++++------------ tests/test_twist.py | 44 +++++++++---------- 15 files changed, 203 insertions(+), 206 deletions(-) diff --git a/tests/base/test_numeric.py b/tests/base/test_numeric.py index 71d3b9d2..5fa0eed7 100755 --- a/tests/base/test_numeric.py +++ b/tests/base/test_numeric.py @@ -27,38 +27,38 @@ def test_array2str(self): s = array2str(x) assert isinstance(s, str) - self.assertEqual(s, "[ 1.23 ]") + assert s == "[ 1.23 ]" s = array2str(x, fmt="{:.5f}") - self.assertEqual(s, "[ 1.23457 ]") + assert s == "[ 1.23457 ]" s = array2str([1, 2, 3]) - self.assertEqual(s, "[ 1, 2, 3 ]") + assert s == "[ 1, 2, 3 ]" s = array2str([1, 2, 3], valuesep=":") - self.assertEqual(s, "[ 1:2:3 ]") + assert s == "[ 1:2:3 ]" s = array2str([1, 2, 3], brackets=("<< ", " >>")) - self.assertEqual(s, "<< 1, 2, 3 >>") + assert s == "<< 1, 2, 3 >>" s = array2str([1, 2e-8, 3]) - self.assertEqual(s, "[ 1, 2e-08, 3 ]") + assert s == "[ 1, 2e-08, 3 ]" s = array2str([1, -2e-14, 3]) - self.assertEqual(s, "[ 1, 0, 3 ]") + assert s == "[ 1, 0, 3 ]" x = np.array([[1, 2, 3], [4, 5, 6]]) s = array2str(x) - self.assertEqual(s, "[ 1, 2, 3 | 4, 5, 6 ]") + assert s == "[ 1, 2, 3 | 4, 5, 6 ]" def test_bresenham(self): x, y = bresenham((-10, -10), (20, 10)) assert isinstance(x, np.ndarray) - self.assertEqual(x.ndim, 1) + assert x.ndim == 1 assert isinstance(y, np.ndarray) - self.assertEqual(y.ndim, 1) - self.assertEqual(len(x), len(y)) + assert y.ndim == 1 + assert len(x) == len(y) # test points are no more than sqrt(2) apart z = np.array([x, y]) @@ -94,16 +94,16 @@ def test_mpq(self): data = np.array([[-1, 1, 1, -1], [-1, -1, 1, 1]]) - self.assertEqual(mpq_point(data, 0, 0), 4) - self.assertEqual(mpq_point(data, 1, 0), 0) - self.assertEqual(mpq_point(data, 0, 1), 0) + assert mpq_point(data, 0, 0) == 4 + assert mpq_point(data, 1, 0) == 0 + assert mpq_point(data, 0, 1) == 0 def test_gauss1d(self): x = np.arange(-10, 10, 0.02) y = gauss1d(2, 1, x) - self.assertEqual(len(x), len(y)) + assert len(x) == len(y) m = np.argmax(y) self.assertAlmostEqual(x[m], 2) diff --git a/tests/base/test_symbolic.py b/tests/base/test_symbolic.py index 2ca7e1e9..0095ea65 100644 --- a/tests/base/test_symbolic.py +++ b/tests/base/test_symbolic.py @@ -31,7 +31,7 @@ def test_symbol(self): assert isinstance(psi, sp.Expr) q = symbol("q:6") - self.assertEqual(len(q), 6) + assert len(q) == 6 for _ in q: assert isinstance(_, sp.Expr) assert _.is_real diff --git a/tests/base/test_transforms2d.py b/tests/base/test_transforms2d.py index 27b25685..1bdf066c 100755 --- a/tests/base/test_transforms2d.py +++ b/tests/base/test_transforms2d.py @@ -183,7 +183,7 @@ def test_print2(self): s = trprint2(T, file=None) assert isinstance(s, str) - self.assertEqual(len(s), 15) + assert len(s) == 15 def test_checks(self): # 2D case, with rotation matrix diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index c3b4eda5..c2809988 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -540,24 +540,24 @@ def test_print(self): R = rotx(0.3) @ roty(0.4) s = trprint(R, file=None) assert isinstance(s, str) - self.assertEqual(len(s), 30) + assert len(s) == 30 T = transl(1, 2, 3) @ trotx(0.3) @ troty(0.4) s = trprint(T, file=None) assert isinstance(s, str) - self.assertEqual(len(s), 42) + assert len(s) == 42 assert "rpy" in s assert "zyx" in s s = trprint(T, file=None, orient="rpy/xyz") assert isinstance(s, str) - self.assertEqual(len(s), 39) + assert len(s) == 39 assert "rpy" in s assert "xyz" in s s = trprint(T, file=None, orient="eul") assert isinstance(s, str) - self.assertEqual(len(s), 37) + assert len(s) == 37 assert "eul" in s assert not "zyx" in s diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index 683f5b8e..b71399ad 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -70,14 +70,14 @@ def test_r2t_sym(self): theta = symbol("theta") R = rot2(theta) T = r2t(R) - self.assertEqual(r2t(R).dtype, "O") + assert r2t(R).dtype == "O" nt.assert_array_almost_equal(T[0:2, 2], np.r_[0, 0]) nt.assert_array_almost_equal(T[:2, :2], R) theta = symbol("theta") R = rotx(theta) T = r2t(R) - self.assertEqual(r2t(R).dtype, "O") + assert r2t(R).dtype == "O" nt.assert_array_almost_equal(T[0:3, 3], np.r_[0, 0, 0]) # nt.assert_array_almost_equal(T[:3,:3], R) assert (T[:3, :3] == R).all() @@ -135,11 +135,11 @@ def test_rt2tr(self): def test_rt2tr_sym(self): theta = symbol("theta") R = rotx(theta) - self.assertEqual(r2t(R).dtype, "O") + assert r2t(R).dtype == "O" theta = symbol("theta") R = rot2(theta) - self.assertEqual(r2t(R).dtype, "O") + assert r2t(R).dtype == "O" def test_tr2rt(self): # 3D @@ -293,18 +293,18 @@ def test_homtrans(self): def test_skew(self): # 3D sk = skew([1, 2, 3]) - self.assertEqual(sk.shape, (3, 3)) + assert sk.shape == (3, 3) nt.assert_almost_equal(sk + sk.T, np.zeros((3, 3))) - self.assertEqual(sk[2, 1], 1) - self.assertEqual(sk[0, 2], 2) - self.assertEqual(sk[1, 0], 3) + assert sk[2, 1] == 1 + assert sk[0, 2] == 2 + assert sk[1, 0] == 3 nt.assert_almost_equal(sk.diagonal(), np.r_[0, 0, 0]) # 2D sk = skew([1]) - self.assertEqual(sk.shape, (2, 2)) + assert sk.shape == (2, 2) nt.assert_almost_equal(sk + sk.T, np.zeros((2, 2))) - self.assertEqual(sk[1, 0], 1) + assert sk[1, 0] == 1 nt.assert_almost_equal(sk.diagonal(), np.r_[0, 0]) with self.assertRaises(ValueError): @@ -366,7 +366,7 @@ def test_isskewa(self): def test_skewa(self): # 3D sk = skewa([1, 2, 3, 4, 5, 6]) - self.assertEqual(sk.shape, (4, 4)) + assert sk.shape == (4, 4) nt.assert_almost_equal(sk.diagonal(), np.r_[0, 0, 0, 0]) nt.assert_almost_equal(sk[-1, :], np.r_[0, 0, 0, 0]) nt.assert_almost_equal(sk[:3, 3], [1, 2, 3]) @@ -374,7 +374,7 @@ def test_skewa(self): # 2D sk = skewa([1, 2, 3]) - self.assertEqual(sk.shape, (3, 3)) + assert sk.shape == (3, 3) nt.assert_almost_equal(sk.diagonal(), np.r_[0, 0, 0]) nt.assert_almost_equal(sk[-1, :], np.r_[0, 0, 0]) nt.assert_almost_equal(sk[:2, 2], [1, 2]) @@ -402,7 +402,7 @@ def test_det(self): def test_det_sym(self): x, y = symbol("x y") a = np.array([[x, y], [y, x]]) - self.assertEqual(det(a), x**2 - y**2) + assert det(a) == x**2 - y**2 # ---------------------------------------------------------------------------------------# diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index da0c3b34..abd1de2c 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -63,7 +63,7 @@ def test_unit(self): def test_colvec(self): t = np.r_[1, 2, 3] cv = colvec(t) - self.assertEqual(cv.shape, (3, 1)) + assert cv.shape == (3, 1) nt.assert_array_almost_equal(cv.flatten(), t) def test_isunitvec(self): @@ -99,8 +99,8 @@ def test_normsq(self): def test_norm_sym(self): x, y = symbol("x y") v = [x, y] - self.assertEqual(norm(v), sqrt(x**2 + y**2)) - self.assertEqual(norm(np.r_[v]), sqrt(x**2 + y**2)) + assert norm(v) == sqrt(x**2 + y**2) + assert norm(np.r_[v]) == sqrt(x**2 + y**2) def test_cross(self): A = np.eye(3) @@ -270,10 +270,10 @@ def test_iszero(self): assert not iszero(1) def test_angdiff(self): - self.assertEqual(angdiff(0, 0), 0) + assert angdiff(0, 0) == 0 assert isinstance(angdiff(0, 0), float) - self.assertEqual(angdiff(pi, 0), -pi) - self.assertEqual(angdiff(-pi, pi), 0) + assert angdiff(pi, 0) == -pi + assert angdiff(-pi, pi) == 0 x = angdiff([0, -pi, pi], 0) nt.assert_array_almost_equal(x, [0, -pi, -pi]) diff --git a/tests/base/test_velocity.py b/tests/base/test_velocity.py index 8dd96b93..0f9beae2 100644 --- a/tests/base/test_velocity.py +++ b/tests/base/test_velocity.py @@ -101,28 +101,28 @@ def test_exp2jac(self): # gamma = [0.1, 0.2, 0.3] # R = rpy2r(gamma, order="zyx") # A = rotvelxform(R, representation="rpy/zyx") - # self.assertEqual(A.shape, (6, 6)) + # assert A.shape == (6, 6) # A3 = np.linalg.inv(A[3:6, 3:6]) # nt.assert_array_almost_equal(A3, rpy2jac(gamma, order="zyx")) # gamma = [0.1, 0.2, 0.3] # R = rpy2r(gamma, order="xyz") # A = rot2jac(R, representation="rpy/xyz") - # self.assertEqual(A.shape, (6, 6)) + # assert A.shape == (6, 6) # A3 = np.linalg.inv(A[3:6, 3:6]) # nt.assert_array_almost_equal(A3, rpy2jac(gamma, order="xyz")) # gamma = [0.1, 0.2, 0.3] # R = eul2r(gamma) # A = rot2jac(R, representation="eul") - # self.assertEqual(A.shape, (6, 6)) + # assert A.shape == (6, 6) # A3 = np.linalg.inv(A[3:6, 3:6]) # nt.assert_array_almost_equal(A3, eul2jac(gamma)) # gamma = [0.1, 0.2, 0.3] # R = trexp(gamma) # A = rot2jac(R, representation="exp") - # self.assertEqual(A.shape, (6, 6)) + # assert A.shape == (6, 6) # A3 = np.linalg.inv(A[3:6, 3:6]) # nt.assert_array_almost_equal(A3, exp2jac(gamma)) diff --git a/tests/test_dualquaternion.py b/tests/test_dualquaternion.py index 450ba9a6..e83810c4 100644 --- a/tests/test_dualquaternion.py +++ b/tests/test_dualquaternion.py @@ -70,7 +70,7 @@ def test_matrix(self): M = dq1.matrix() assert isinstance(M, np.ndarray) - self.assertEqual(M.shape, (8,8)) + assert M.shape == (8,8) def test_multiply(self): dq1 = DualQuaternion(Quaternion([1.,2,3,4]), Quaternion([5.,6,7,8])) diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index b079a108..17361a49 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -21,8 +21,8 @@ class Polygon2Test(unittest.TestCase): def test_constructor1(self): p = Polygon2([(1, 2), (3, 2), (2, 4)]) assert isinstance(p, Polygon2) - self.assertEqual(len(p), 3) - self.assertEqual(str(p), "Polygon2 with 4 vertices") + assert len(p) == 3 + assert str(p) == "Polygon2 with 4 vertices" nt.assert_array_equal(p.vertices(), np.array([[1, 3, 2], [2, 2, 4]])) nt.assert_array_equal( p.vertices(unique=False), np.array([[1, 3, 2, 1], [2, 2, 4, 2]]) @@ -31,13 +31,13 @@ def test_constructor1(self): def test_methods(self): p = Polygon2(np.array([[-1, 1, 1, -1], [-1, -1, 1, 1]])) - self.assertEqual(p.area(), 4) - self.assertEqual(p.moment(0, 0), 4) - self.assertEqual(p.moment(1, 0), 0) - self.assertEqual(p.moment(0, 1), 0) + assert p.area() == 4 + assert p.moment(0, 0) == 4 + assert p.moment(1, 0) == 0 + assert p.moment(0, 1) == 0 nt.assert_array_equal(p.centroid(), np.r_[0, 0]) - self.assertEqual(p.radius(), np.sqrt(2)) + assert p.radius() == np.sqrt(2) nt.assert_array_equal(p.bbox(), np.r_[-1, -1, 1, 1]) def test_contains(self): @@ -61,10 +61,10 @@ def test_transform(self): p = p.transformed(SE2(2, 3)) - self.assertEqual(p.area(), 4) - self.assertEqual(p.moment(0, 0), 4) - self.assertEqual(p.moment(1, 0), 8) - self.assertEqual(p.moment(0, 1), 12) + assert p.area() == 4 + assert p.moment(0 == 0, 4) + assert p.moment(1 == 0, 8) + assert p.moment(0 == 1, 12) nt.assert_array_equal(p.centroid(), np.r_[2, 3]) def test_intersect(self): @@ -112,7 +112,7 @@ def test_edges(self): class Line2Test(unittest.TestCase): def test_constructor(self): l = Line2([1, 2, 3]) - self.assertEqual(str(l), "Line2: [1. 2. 3.]") + assert str(l) == "Line2: [1. 2. 3.]" l = Line2.Join((0, 0), (1, 2)) nt.assert_equal(l.line, [-2, 1, 0]) @@ -240,7 +240,7 @@ def test_misc(self): assert not e.contains((0, 2.1)) assert not e.contains((0, -2.1)) - self.assertEqual(e.contains(np.array([[0, 0], [3, 3]]).T), [True, False]) + assert e.contains(np.array([[0, 0], [3, 3]]).T) == [True, False] if __name__ == "__main__": diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 00e0d79d..b46ceaa0 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -56,30 +56,30 @@ def test_constructor2(self): # TODO, all combos of list and ndarray # test all possible input shapes # L2, = Line3(P, Q) - # self.assertEqual(double(L2), double(L)) + # assert double(L2) == double(L) # L2, = Line3(P, Q') - # self.assertEqual(double(L2), double(L)) + # assert double(L2) == double(L) # L2, = Line3(P', Q') - # self.assertEqual(double(L2), double(L)) + # assert double(L2) == double(L) # L2, = Line3(P, Q) - # self.assertEqual(double(L2), double(L)) + # assert double(L2) == double(L) # # planes constructor # P = [10, 11, 12]'; w = [1, 2, 3] # L = Line3.PointDir(P, w) - # self.assertEqual(double(L), [cross(w,P) w]'); %FAIL + # assertEqual(double(L), [cross(w,P) w]'); %FAIL # L2, = Line3.PointDir(P', w) - # self.assertEqual(double(L2), double(L)) + # assert double(L2) == double(L) # L2, = Line3.PointDir(P, w') - # self.assertEqual(double(L2), double(L)) + # assert double(L2) == double(L) # L2, = Line3.PointDir(P', w') - # self.assertEqual(double(L2), double(L)) + # assert double(L2) == double(L) def test_pp(self): # validate pp and ppd L = Line3.Join([-1, 1, 2], [1, 1, 2]) nt.assert_array_almost_equal(L.pp, np.r_[0, 1, 2]) - self.assertEqual(L.ppd, math.sqrt(5)) + assert L.ppd == math.sqrt(5) # validate pp assert L.contains(L.pp) @@ -119,7 +119,7 @@ def test_closest(self): p, d = L.closest_to_point([0, 0, 0]) nt.assert_array_almost_equal(p, L.pp) - self.assertEqual(d, L.ppd) + assert d == L.ppd p, d = L.closest_to_point([5, 1, 0]) nt.assert_array_almost_equal(p, [5, 1, 2]) @@ -163,7 +163,7 @@ def test_skew(self): m = L.skew() - self.assertEqual(m.shape, (4, 4)) + assert m.shape == (4, 4) nt.assert_array_almost_equal(m + m.T, np.zeros((4, 4))) def test_rmul(self): @@ -229,7 +229,7 @@ def test_commonperp(self): assert not L1 | L2 assert not L1 ^ L2 - self.assertEqual(L1.distance(L2), 2) + assert L1.distance(L2) == 2 L = L1.commonperp(L2) # common perp intersects both lines @@ -304,8 +304,8 @@ def test_methods(self): px1 = Line3.Join([0, 1, 0], [1, 1, 0]) # offset x-axis - self.assertEqual(px.ppd, 0) - self.assertEqual(px1.ppd, 1) + assert px.ppd == 0 + assert px1.ppd == 1 nt.assert_array_almost_equal(px1.pp, [0, 1, 0]) px.intersects(px) diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index bfb559b2..5c61a0b5 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -41,7 +41,7 @@ def test_constructor(self): # null case x = SO2() assert isinstance(x, SO2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, np.eye(2, 2)) ## from angle @@ -66,11 +66,11 @@ def test_constructor(self): R = SO2.Empty() for theta in [-pi / 2, 0, pi / 2, pi]: R.append(SO2(theta)) - self.assertEqual(len(R), 4) + assert len(R) == 4 array_compare(R[0], rot2(-pi / 2)) array_compare(R[3], rot2(pi)) - # TODO self.assertEqual(SO2(R).R, R) + # TODO assert SO2(R).R == R ## copy constructor r = SO2(0.3) @@ -84,7 +84,7 @@ def test_concat(self): xx = SO2([x, x, x, x]) assert isinstance(xx, SO2) - self.assertEqual(len(xx), 4) + assert len(xx) == 4 def test_primitive_convert(self): # char @@ -94,20 +94,20 @@ def test_primitive_convert(self): def test_shape(self): a = SO2() - self.assertEqual(a._A.shape, a.shape) + assert a._A.shape == a.shape def test_constructor_Exp(self): array_compare(SO2.Exp(skew(0.3)).R, rot2(0.3)) array_compare(SO2.Exp(0.3).R, rot2(0.3)) x = SO2.Exp([0, 0.3, 1]) - self.assertEqual(len(x), 3) + assert len(x) == 3 array_compare(x[0], rot2(0)) array_compare(x[1], rot2(0.3)) array_compare(x[2], rot2(1)) x = SO2.Exp([skew(x) for x in [0, 0.3, 1]]) - self.assertEqual(len(x), 3) + assert len(x) == 3 array_compare(x[0], rot2(0)) array_compare(x[1], rot2(0.3)) array_compare(x[2], rot2(1)) @@ -203,7 +203,7 @@ def test_miscellany(self): ) self.assertAlmostEqual(np.linalg.det(r.A), 1) - self.assertEqual(r.N, 2) + assert r.N == 2 assert not r.isSE @@ -217,7 +217,7 @@ def test_printline(self): R = SO2([0.3, 0.4, 0.5]) s = R.printline(file=None) # assert isinstance(s, str) - # self.assertEqual(s.count('\n'), 2) + # assert s.count('\n') == 2 @pytest.mark.skipif( sys.platform.startswith("darwin") and sys.version_info < (3, 11), @@ -251,40 +251,40 @@ def test_constructor(self): # from x,y x = SE2(2, 3) assert isinstance(x, SE2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, np.array([[1, 0, 2], [0, 1, 3], [0, 0, 1]])) x = SE2([2, 3]) assert isinstance(x, SE2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, np.array([[1, 0, 2], [0, 1, 3], [0, 0, 1]])) # from x,y,theta x = SE2(2, 3, pi / 2) assert isinstance(x, SE2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) x = SE2([2, 3, pi / 2]) assert isinstance(x, SE2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) x = SE2(2, 3, 90, unit="deg") assert isinstance(x, SE2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) x = SE2([2, 3, 90], unit="deg") assert isinstance(x, SE2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, np.array([[0, -1, 2], [1, 0, 3], [0, 0, 1]])) ## T T = transl2(1, 2) @ trot2(0.3) x = SE2(T) assert isinstance(x, SE2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.A, T) ## copy constructor @@ -300,33 +300,33 @@ def test_constructor(self): x = SE2([T1, T2, T1, T2]) assert isinstance(x, SE2) - self.assertEqual(len(x), 4) + assert len(x) == 4 array_compare(x[0], T1) array_compare(x[1], T2) def test_shape(self): a = SE2() - self.assertEqual(a._A.shape, a.shape) + assert a._A.shape == a.shape def test_concat(self): x = SE2() xx = SE2([x, x, x, x]) assert isinstance(xx, SE2) - self.assertEqual(len(xx), 4) + assert len(xx) == 4 def test_constructor_Exp(self): array_compare(SE2.Exp(skewa([1, 2, 0])), transl2(1, 2)) array_compare(SE2.Exp(np.r_[1, 2, 0]), transl2(1, 2)) x = SE2.Exp([(1, 2, 0), (3, 4, 0), (5, 6, 0)]) - self.assertEqual(len(x), 3) + assert len(x) == 3 array_compare(x[0], transl2(1, 2)) array_compare(x[1], transl2(3, 4)) array_compare(x[2], transl2(5, 6)) x = SE2.Exp([skewa(x) for x in [(1, 2, 0), (3, 4, 0), (5, 6, 0)]]) - self.assertEqual(len(x), 3) + assert len(x) == 3 array_compare(x[0], transl2(1, 2)) array_compare(x[1], transl2(3, 4)) array_compare(x[2], transl2(5, 6)) @@ -373,8 +373,8 @@ def test_Rt(self): array_compare(TT1.A, T1) array_compare(TT1.R, R1) array_compare(TT1.t, t1) - self.assertEqual(TT1.x, t1[0]) - self.assertEqual(TT1.y, t1[1]) + assert TT1.x == t1[0] + assert TT1.y == t1[1] TT = SE2([TT1, TT1, TT1]) array_compare(TT.t, [t1, t1, t1]) @@ -471,7 +471,7 @@ def test_interp(self): def test_miscellany(self): TT = SE2(1, 2, 0.3) - self.assertEqual(TT.A.shape, (3, 3)) + assert TT.A.shape == (3, 3) assert TT.isSE diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 8485a5bb..03b1803d 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -83,7 +83,7 @@ def test_constructor(self): # random constrained R = SO3.Rand(theta_range=(0.1, 0.7)) assert isinstance(R, SO3) - self.assertEqual(R.A.shape, (3, 3)) + assert R.A.shape == (3, 3) self.assertLessEqual(R.angvec()[0], 0.7) self.assertGreaterEqual(R.angvec()[0], 0.1) @@ -259,7 +259,7 @@ def test_conversion(self): def test_shape(self): a = SO3() - self.assertEqual(a._A.shape, a.shape) + assert a._A.shape == a.shape def test_about(self): R = SO3() @@ -270,11 +270,11 @@ def test_str(self): s = str(R) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 3) + assert s.count("\n") == 3 s = repr(R) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 2) + assert s.count("\n") == 2 def test_printline(self): R = SO3.Rx(0.3) @@ -286,7 +286,7 @@ def test_printline(self): R = SO3.Rx([0.3, 0.4, 0.5]) s = R.printline(file=None) # assert isinstance(s, str) - # self.assertEqual(s.count('\n'), 2) + # assert s.count('\n') == 2 @pytest.mark.skipif( sys.platform.startswith("darwin") and sys.version_info < (3, 11), @@ -333,16 +333,16 @@ def test_listpowers(self): def test_tests(self): R = SO3() - self.assertEqual(R.isrot(), True) - self.assertEqual(R.isrot2(), False) - self.assertEqual(R.ishom(), False) - self.assertEqual(R.ishom2(), False) + assert R.isrot() == True + assert R.isrot2() == False + assert R.ishom() == False + assert R.ishom2() == False def test_properties(self): R = SO3() - self.assertEqual(R.isSO, True) - self.assertEqual(R.isSE, False) + assert R.isSO == True + assert R.isSE == False array_compare(R.n, np.r_[1, 0, 0]) array_compare(R.n, np.r_[1, 0, 0]) @@ -838,7 +838,7 @@ def test_constructor(self): t = T.t T = SE3.Rt(R, t) assert isinstance(T, SE3) - self.assertEqual(T.A.shape, (4, 4)) + assert T.A.shape == (4, 4) nt.assert_equal(T.R, R) nt.assert_equal(T.t, t) @@ -861,7 +861,7 @@ def test_constructor(self): # random constrained T = SE3.Rand(theta_range=(0.1, 0.7)) assert isinstance(T, SE3) - self.assertEqual(T.A.shape, (4, 4)) + assert T.A.shape == (4, 4) self.assertLessEqual(T.angvec()[0], 0.7) self.assertGreaterEqual(T.angvec()[0], 0.1) @@ -881,7 +881,7 @@ def test_constructor(self): T = SE3(SE2(1, 2, 0.4)) nt.assert_equal(len(T), 1) assert isinstance(T, SE3) - self.assertEqual(T.A.shape, (4, 4)) + assert T.A.shape == (4, 4) nt.assert_equal(T.t, [1, 2, 0]) # Bad number of arguments @@ -892,7 +892,7 @@ def test_constructor(self): def test_shape(self): a = SE3() - self.assertEqual(a._A.shape, a.shape) + assert a._A.shape == a.shape def test_listpowers(self): R = SE3() @@ -925,16 +925,16 @@ def test_listpowers(self): def test_tests(self): R = SE3() - self.assertEqual(R.isrot(), False) - self.assertEqual(R.isrot2(), False) - self.assertEqual(R.ishom(), True) - self.assertEqual(R.ishom2(), False) + assert R.isrot() == False + assert R.isrot2() == False + assert R.ishom() == True + assert R.ishom2() == False def test_properties(self): R = SE3() - self.assertEqual(R.isSO, False) - self.assertEqual(R.isSE, True) + assert R.isSO == False + assert R.isSE == True array_compare(R.n, np.r_[1, 0, 0]) array_compare(R.n, np.r_[1, 0, 0]) diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index b174c316..3644d493 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -120,7 +120,7 @@ def test_constructor(self): # vector of SO3 q = UnitQuaternion([SO3.Rx(pi / 2), SO3.Ry(pi / 2), SO3.Rz(pi / 2)]) - self.assertEqual(len(q), 3) + assert len(q) == 3 qcompare(q, np.array([[1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]]) / math.sqrt(2)) # from SE3 @@ -141,13 +141,13 @@ def test_constructor(self): # vector of SE3 q = UnitQuaternion([SE3.Rx(pi / 2), SE3.Ry(pi / 2), SE3.Rz(pi / 2)]) - self.assertEqual(len(q), 3) + assert len(q) == 3 qcompare(q, np.array([[1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]]) / math.sqrt(2)) # from S M = np.identity(4) q = UnitQuaternion(M) - self.assertEqual(len(q), 4) + assert len(q) == 4 qcompare(q[0], np.r_[1, 0, 0, 0]) qcompare(q[1], np.r_[0, 1, 0, 0]) @@ -185,7 +185,7 @@ def test_concat(self): uu = UnitQuaternion([u, u, u, u]) assert isinstance(uu, UnitQuaternion) - self.assertEqual(len(uu), 4) + assert len(uu) == 4 def test_string(self): u = UnitQuaternion() @@ -193,12 +193,12 @@ def test_string(self): s = str(u) assert isinstance(s, str) assert s.endswith(" >>") - self.assertEqual(s.count("\n"), 0) + assert s.count("\n") == 0 q = UnitQuaternion.Rx([0.3, 0.4, 0.5]) s = str(q) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 2) + assert s.count("\n") == 2 def test_properties(self): u = UnitQuaternion() @@ -516,12 +516,9 @@ def test_angle(self): uq1 = UnitQuaternion.Rx(0.1) uq2 = UnitQuaternion.Ry(0.1) for metric in range(5): - self.assertEqual(uq1.angdist(other=uq1, metric=metric), 0.0) - self.assertEqual(uq2.angdist(other=uq2, metric=metric), 0.0) - self.assertEqual( - uq1.angdist(other=uq2, metric=metric), - uq2.angdist(other=uq1, metric=metric), - ) + assert uq1.angdist(other=uq1, metric=metric) == 0.0 + assert uq2.angdist(other=uq2, metric=metric) == 0.0 + assert uq1.angdist(other=uq2, metric=metric) == uq2.angdist(other=uq1, metric=metric) assert uq1.angdist(other=uq2, metric=metric) > 0 def test_conversions(self): @@ -590,11 +587,11 @@ def test_miscellany(self): qcompare(q**2, q * q) # angle - # self.assertEqual(angle(u, u), 0) - # self.assertEqual(angle(u, rx), pi/4) - # self.assertEqual(angle(u, [rx, u]), pi/4*np.r_[1, 0]) - # self.assertEqual(angle([rx, u], u), pi/4*np.r_[1, 0]) - # self.assertEqual(angle([rx, u], [u, rx]), pi/4*np.r_[1, 1]) + # assert angle(u, u) == 0 + # assert angle(u, rx) == pi/4 + # assert angle(u, [rx, u]) == pi/4*np.r_[1, 0] + # assert angle([rx, u], u) == pi/4*np.r_[1, 0] + # assert angle([rx, u], [u, rx]) == pi/4*np.r_[1, 1] # TODO angle # increment @@ -614,7 +611,7 @@ def test_interp(self): qcompare(q.interp1(0), u) qcompare(q.interp1(1), q) - # self.assertEqual(length(q.interp(linspace(0,1, 10))), 10) + # assert length(q.interp(linspace(0,1, 10))) == 10 # assert all( q.interp([0, 1]) == [u, q]) # TODO vectorizing @@ -622,7 +619,7 @@ def test_interp(self): qcompare(q0_5 * q0_5, q) qq = rx.interp1(11) - self.assertEqual(len(qq), 11) + assert len(qq) == 11 # between two quaternions qcompare(q.interp(rx, 0), q) @@ -630,12 +627,12 @@ def test_interp(self): # test vectorised results qq = q.interp(rx, [0, 1]) - self.assertEqual(len(qq), 2) + assert len(qq) == 2 qcompare(qq[0], q) qcompare(qq[1], rx) qq = rx.interp(q, 11) - self.assertEqual(len(qq), 11) + assert len(qq) == 11 # assert all( q.interp([0, 1], dest=rx, ) == [q, rx]) @@ -746,7 +743,7 @@ def test_vec3(self): class TestQuaternion(unittest.TestCase): def test_constructor(self): q = Quaternion() - self.assertEqual(len(q), 1) + assert len(q) == 1 assert isinstance(q, Quaternion) nt.assert_array_almost_equal(Quaternion().vec, [0, 0, 0, 0]) @@ -799,17 +796,17 @@ def test_string(self): s = str(u) assert isinstance(s, str) assert s.endswith(" >") - self.assertEqual(s.count("\n"), 0) - self.assertEqual(len(s), 37) + assert s.count("\n") == 0 + assert len(s) == 37 q = Quaternion([u, u, u]) s = str(q) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 2) + assert s.count("\n") == 2 def test_properties(self): q = Quaternion([1, 2, 3, 4]) - self.assertEqual(q.s, 1) + assert q.s == 1 nt.assert_array_almost_equal(q.v, np.r_[2, 3, 4]) nt.assert_array_almost_equal(q.vec, np.r_[1, 2, 3, 4]) @@ -835,7 +832,7 @@ def test_concat(self): uu = Quaternion([u, u, u, u]) assert isinstance(uu, Quaternion) - self.assertEqual(len(uu), 4) + assert len(uu) == 4 def primitive_test_convert(self): # s,v @@ -939,21 +936,21 @@ def test_equality(self): qt1 = Quaternion([q1, q1, q2, q2]) qt2 = Quaternion([q1, q2, q2, q1]) - self.assertEqual(qt1 == q1, [True, True, False, False]) - self.assertEqual(q1 == qt1, [True, True, False, False]) - self.assertEqual(qt1 == qt1, [True, True, True, True]) + assert (qt1 == q1) == [True, True, False, False] + assert (q1 == qt1) == [True, True, False, False] + assert (qt1 == qt1) == [True, True, True, True] - self.assertEqual(qt2 == q1, [True, False, False, True]) - self.assertEqual(q1 == qt2, [True, False, False, True]) - self.assertEqual(qt1 == qt2, [True, False, True, False]) + assert (qt2 == q1) == [True, False, False, True] + assert (q1 == qt2) == [True, False, False, True] + assert (qt1 == qt2) == [True, False, True, False] - self.assertEqual(qt1 != q1, [False, False, True, True]) - self.assertEqual(q1 != qt1, [False, False, True, True]) - self.assertEqual(qt1 != qt1, [False, False, False, False]) + assert (qt1 != q1) == [False, False, True, True] + assert (q1 != qt1) == [False, False, True, True] + assert (qt1 != qt1) == [False, False, False, False] - self.assertEqual(qt2 != q1, [False, True, True, False]) - self.assertEqual(q1 != qt2, [False, True, True, False]) - self.assertEqual(qt1 != qt2, [False, True, False, True]) + assert (qt2 != q1) == [False, True, True, False] + assert (q1 != qt2) == [False, True, True, False] + assert (qt1 != qt2) == [False, True, False, True] # errors diff --git a/tests/test_spatialvector.py b/tests/test_spatialvector.py index 30936cac..8db1d41f 100644 --- a/tests/test_spatialvector.py +++ b/tests/test_spatialvector.py @@ -8,33 +8,33 @@ class TestSpatialVector(unittest.TestCase): def test_list_powers(self): x = SpatialVelocity.Empty() - self.assertEqual(len(x), 0) + assert len(x) == 0 x.append(SpatialVelocity([1, 2, 3, 4, 5, 6])) - self.assertEqual(len(x), 1) + assert len(x) == 1 x.append(SpatialVelocity([7, 8, 9, 10, 11, 12])) - self.assertEqual(len(x), 2) + assert len(x) == 2 y = x[0] assert isinstance(y, SpatialVelocity) - self.assertEqual(len(y), 1) + assert len(y) == 1 assert all(y.A == np.r_[1, 2, 3, 4, 5, 6]) y = x[1] assert isinstance(y, SpatialVelocity) - self.assertEqual(len(y), 1) + assert len(y) == 1 assert all(y.A == np.r_[7, 8, 9, 10, 11, 12]) x.insert(0, SpatialVelocity([20, 21, 22, 23, 24, 25])) y = x[0] assert isinstance(y, SpatialVelocity) - self.assertEqual(len(y), 1) + assert len(y) == 1 assert all(y.A == np.r_[20, 21, 22, 23, 24, 25]) y = x[1] assert isinstance(y, SpatialVelocity) - self.assertEqual(len(y), 1) + assert len(y) == 1 assert all(y.A == np.r_[1, 2, 3, 4, 5, 6]) def test_velocity(self): @@ -42,19 +42,19 @@ def test_velocity(self): assert isinstance(a, SpatialVelocity) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialVelocity(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialVelocity) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 0) + assert s.count("\n") == 0 assert s.startswith("SpatialVelocity") r = np.random.rand(6, 10) @@ -62,37 +62,37 @@ def test_velocity(self): assert isinstance(a, SpatialVelocity) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) - self.assertEqual(len(a), 10) + assert len(a) == 10 b = a[3] assert isinstance(b, SpatialVelocity) assert isinstance(b, SpatialVector) assert isinstance(b, SpatialM6) - self.assertEqual(len(b), 1) + assert len(b) == 1 assert all(b.A == r[:, 3]) s = str(a) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 9) + assert s.count("\n") == 9 def test_acceleration(self): a = SpatialAcceleration([1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialAcceleration) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialAcceleration(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialAcceleration) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 0) + assert s.count("\n") == 0 assert s.startswith("SpatialAcceleration") r = np.random.rand(6, 10) @@ -100,13 +100,13 @@ def test_acceleration(self): assert isinstance(a, SpatialAcceleration) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialM6) - self.assertEqual(len(a), 10) + assert len(a) == 10 b = a[3] assert isinstance(b, SpatialAcceleration) assert isinstance(b, SpatialVector) assert isinstance(b, SpatialM6) - self.assertEqual(len(b), 1) + assert len(b) == 1 assert all(b.A == r[:, 3]) s = str(a) @@ -117,19 +117,19 @@ def test_force(self): assert isinstance(a, SpatialForce) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialForce(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialForce) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 0) + assert s.count("\n") == 0 assert s.startswith("SpatialForce") r = np.random.rand(6, 10) @@ -137,13 +137,13 @@ def test_force(self): assert isinstance(a, SpatialForce) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) - self.assertEqual(len(a), 10) + assert len(a) == 10 b = a[3] assert isinstance(b, SpatialForce) assert isinstance(b, SpatialVector) assert isinstance(b, SpatialF6) - self.assertEqual(len(b), 1) + assert len(b) == 1 assert all(b.A == r[:, 3]) s = str(a) @@ -154,19 +154,19 @@ def test_momentum(self): assert isinstance(a, SpatialMomentum) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) a = SpatialMomentum(np.r_[1, 2, 3, 4, 5, 6]) assert isinstance(a, SpatialMomentum) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) - self.assertEqual(len(a), 1) + assert len(a) == 1 assert all(a.A == np.r_[1, 2, 3, 4, 5, 6]) s = str(a) assert isinstance(s, str) - self.assertEqual(s.count("\n"), 0) + assert s.count("\n") == 0 assert s.startswith("SpatialMomentum") r = np.random.rand(6, 10) @@ -174,13 +174,13 @@ def test_momentum(self): assert isinstance(a, SpatialMomentum) assert isinstance(a, SpatialVector) assert isinstance(a, SpatialF6) - self.assertEqual(len(a), 10) + assert len(a) == 10 b = a[3] assert isinstance(b, SpatialMomentum) assert isinstance(b, SpatialVector) assert isinstance(b, SpatialF6) - self.assertEqual(len(b), 1) + assert len(b) == 1 assert all(b.A == r[:, 3]) s = str(a) diff --git a/tests/test_twist.py b/tests/test_twist.py index f48cd106..ad8e2c40 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -34,7 +34,7 @@ def test_constructor(self): s = [1, 2, 3, 4, 5, 6] x = Twist3(s) assert isinstance(x, Twist3) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.v, [1, 2, 3]) array_compare(x.w, [4, 5, 6]) array_compare(x.S, s) @@ -57,7 +57,7 @@ def test_list(self): a = Twist3(x) a.append(y) - self.assertEqual(len(a), 2) + assert len(a) == 2 array_compare(a[0], x) array_compare(a[1], y) @@ -66,7 +66,7 @@ def test_conversion_SE3(self): tw = Twist3(T) array_compare(tw.SE3(), T) assert isinstance(tw.SE3(), SE3) - self.assertEqual(len(tw.SE3()), 1) + assert len(tw.SE3()) == 1 T = SE3.Rx(0) * SE3(1, 2, 3) array_compare(Twist3(T).SE3(), T) @@ -88,20 +88,20 @@ def test_list_constuctor(self): a = Twist3([x,x,x,x]) assert isinstance(a, Twist3) - self.assertEqual(len(a), 4) + assert len(a) == 4 a = Twist3([x.skewa(), x.skewa(), x.skewa(), x.skewa()]) assert isinstance(a, Twist3) - self.assertEqual(len(a), 4) + assert len(a) == 4 a = Twist3([x.S, x.S, x.S, x.S]) assert isinstance(a, Twist3) - self.assertEqual(len(a), 4) + assert len(a) == 4 s = np.r_[1, 2, 3, 4, 5, 6] a = Twist3([s, s, s, s]) assert isinstance(a, Twist3) - self.assertEqual(len(a), 4) + assert len(a) == 4 def test_predicate(self): x = Twist3.UnitRevolute([1, 2, 3], [0, 0, 0]) @@ -121,14 +121,14 @@ def test_str(self): x = Twist3([1, 2, 3, 4, 5, 6]) s = str(x) assert isinstance(s, str) - self.assertEqual(len(s), 14) - self.assertEqual(s.count('\n'), 0) + assert len(s) == 14 + assert s.count('\n') == 0 x.append(x) s = str(x) assert isinstance(s, str) - self.assertEqual(len(s), 29) - self.assertEqual(s.count('\n'), 1) + assert len(s) == 29 + assert s.count('\n') == 1 def test_variant_constructors(self): @@ -201,7 +201,7 @@ def test_constructor(self): s = [1, 2, 3] x = Twist2(s) assert isinstance(x, Twist2) - self.assertEqual(len(x), 1) + assert len(x) == 1 array_compare(x.v, [1, 2]) array_compare(x.w, [3]) array_compare(x.S, s) @@ -234,7 +234,7 @@ def test_list(self): a = Twist2(x) a.append(y) - self.assertEqual(len(a), 2) + assert len(a) == 2 array_compare(a[0], x) array_compare(a[1], y) @@ -253,7 +253,7 @@ def test_conversion_SE2(self): tw = Twist2(T) array_compare(tw.SE2(), T) assert isinstance(tw.SE2(), SE2) - self.assertEqual(len(tw.SE2()), 1) + assert len(tw.SE2()) == 1 def test_conversion_se2(self): s = [1, 2, 3] @@ -268,20 +268,20 @@ def test_list_constuctor(self): a = Twist2([x,x,x,x]) assert isinstance(a, Twist2) - self.assertEqual(len(a), 4) + assert len(a) == 4 a = Twist2([x.skewa(), x.skewa(), x.skewa(), x.skewa()]) assert isinstance(a, Twist2) - self.assertEqual(len(a), 4) + assert len(a) == 4 a = Twist2([x.S, x.S, x.S, x.S]) assert isinstance(a, Twist2) - self.assertEqual(len(a), 4) + assert len(a) == 4 s = np.r_[1, 2, 3] a = Twist2([s, s, s, s]) assert isinstance(a, Twist2) - self.assertEqual(len(a), 4) + assert len(a) == 4 def test_predicate(self): x = Twist2.UnitRevolute([1, 2]) @@ -301,14 +301,14 @@ def test_str(self): x = Twist2([1, 2, 3]) s = str(x) assert isinstance(s, str) - self.assertEqual(len(s), 8) - self.assertEqual(s.count('\n'), 0) + assert len(s) == 8 + assert s.count('\n') == 0 x.append(x) s = str(x) assert isinstance(s, str) - self.assertEqual(len(s), 17) - self.assertEqual(s.count('\n'), 1) + assert len(s) == 17 + assert s.count('\n') == 1 def test_SE2_twists(self): From 0f6db55bae5a5d8734ac1d7c19d63d28cabcd725 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:34:47 -0500 Subject: [PATCH 10/21] Replace assertIsNotInstance with bare assert --- tests/test_pose3d.py | 108 +++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 03b1803d..4994d866 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -359,23 +359,23 @@ def test_arith(self): # sum a = R + R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2]])) a = R + 1 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, np.array([[2, 1, 1], [1, 2, 1], [1, 1, 2]])) # a = 1 + R - # self.assertNotIsInstance(a, SO3) + # assert not isinstance(a, SO3) # array_compare(a, np.array([ [2,1,1], [1,2,1], [1,1,2]])) a = R + np.eye(3) - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2]])) # a = np.eye(3) + R - # self.assertNotIsInstance(a, SO3) + # assert not isinstance(a, SO3) # array_compare(a, np.array([ [2,0,0], [0,2,0], [0,0,2]])) # this invokes the __add__ method for numpy @@ -383,23 +383,23 @@ def test_arith(self): R = SO3() a = R - R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, np.zeros((3, 3))) a = R - 1 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, np.array([[0, -1, -1], [-1, 0, -1], [-1, -1, 0]])) # a = 1 - R - # self.assertNotIsInstance(a, SO3) + # assert not isinstance(a, SO3) # array_compare(a, -np.array([ [0,-1,-1], [-1,0,-1], [-1,-1,0]])) a = R - np.eye(3) - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, np.zeros((3, 3))) # a = np.eye(3) - R - # self.assertNotIsInstance(a, SO3) + # assert not isinstance(a, SO3) # array_compare(a, np.zeros((3,3))) # multiply @@ -410,11 +410,11 @@ def test_arith(self): array_compare(a, R) a = R * 2 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, 2 * np.eye(3)) a = 2 * R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, 2 * np.eye(3)) R = SO3() @@ -424,7 +424,7 @@ def test_arith(self): R = SO3() R *= 2 - self.assertNotIsInstance(R, SO3) + assert not isinstance(R, SO3) array_compare(R, 2 * np.eye(3)) array_compare(SO3.Rx(pi / 2) * SO3.Ry(pi / 2) * SO3.Rx(-pi / 2), SO3.Rz(pi / 2)) @@ -462,7 +462,7 @@ def cv(v): array_compare(a, np.eye(3)) a = R / 2 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) array_compare(a, roty(0.3) / 2) # power @@ -513,14 +513,14 @@ def test_arith_vect(self): array_compare(a[2], rz * rz) a = R * 2 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * 2) array_compare(a[1], ry * 2) array_compare(a[2], rz * 2) a = 2 * R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * 2) array_compare(a[1], ry * 2) @@ -552,7 +552,7 @@ def test_arith_vect(self): a = R a *= 2 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * 2) array_compare(a[1], ry * 2) @@ -597,7 +597,7 @@ def test_arith_vect(self): array_compare(a[2], np.eye(3)) a = R / 2 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / 2) array_compare(a[1], ry / 2) @@ -629,7 +629,7 @@ def test_arith_vect(self): a = R a /= 2 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / 2) array_compare(a[1], ry / 2) @@ -638,28 +638,28 @@ def test_arith_vect(self): # add R = SO3([rx, ry, rz]) a = R + rx - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + rx) array_compare(a[1], ry + rx) array_compare(a[2], rz + rx) a = rx + R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + rx) array_compare(a[1], rx + ry) array_compare(a[2], rx + rz) a = R + R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + rx) array_compare(a[1], ry + ry) array_compare(a[2], rz + rz) a = R + 1 - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + 1) array_compare(a[1], ry + 1) @@ -668,21 +668,21 @@ def test_arith_vect(self): # subtract R = SO3([rx, ry, rz]) a = R - rx - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx - rx) array_compare(a[1], ry - rx) array_compare(a[2], rz - rx) a = rx - R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx - rx) array_compare(a[1], rx - ry) array_compare(a[2], rx - rz) a = R - R - self.assertNotIsInstance(a, SO3) + assert not isinstance(a, SO3) nt.assert_equal(len(a), 3) array_compare(a[0], rx - rx) array_compare(a[1], ry - ry) @@ -959,29 +959,29 @@ def test_arith(self): # sum a = T + T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare( a, np.array([[2, 0, 0, 2], [0, 2, 0, 4], [0, 0, 2, 6], [0, 0, 0, 2]]) ) a = T + 1 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare( a, np.array([[2, 1, 1, 2], [1, 2, 1, 3], [1, 1, 2, 4], [1, 1, 1, 2]]) ) # a = 1 + T - # self.assertNotIsInstance(a, SE3) + # assert not isinstance(a, SE3) # array_compare(a, np.array([ [2,1,1], [1,2,1], [1,1,2]])) a = T + np.eye(4) - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare( a, np.array([[2, 0, 0, 1], [0, 2, 0, 2], [0, 0, 2, 3], [0, 0, 0, 2]]) ) # a = np.eye(3) + T - # self.assertNotIsInstance(a, SE3) + # assert not isinstance(a, SE3) # array_compare(a, np.array([ [2,0,0], [0,2,0], [0,0,2]])) # this invokes the __add__ method for numpy @@ -989,33 +989,33 @@ def test_arith(self): T = SE3(1, 2, 3) a = T - T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare(a, np.zeros((4, 4))) a = T - 1 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare( a, np.array([[0, -1, -1, 0], [-1, 0, -1, 1], [-1, -1, 0, 2], [-1, -1, -1, 0]]), ) # a = 1 - T - # self.assertNotIsInstance(a, SE3) + # assert not isinstance(a, SE3) # array_compare(a, -np.array([ [0,-1,-1], [-1,0,-1], [-1,-1,0]])) a = T - np.eye(4) - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare( a, np.array([[0, 0, 0, 1], [0, 0, 0, 2], [0, 0, 0, 3], [0, 0, 0, 0]]) ) # a = np.eye(3) - T - # self.assertNotIsInstance(a, SE3) + # assert not isinstance(a, SE3) # array_compare(a, np.zeros((3,3))) a = T a -= T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare(a, np.zeros((4, 4))) # multiply @@ -1026,11 +1026,11 @@ def test_arith(self): array_compare(a, transl(2, 4, 6)) a = T * 2 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare(a, 2 * transl(1, 2, 3)) a = 2 * T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare(a, 2 * transl(1, 2, 3)) T = SE3(1, 2, 3) @@ -1042,7 +1042,7 @@ def test_arith(self): T = SE3() T *= 2 - self.assertNotIsInstance(T, SE3) + assert not isinstance(T, SE3) array_compare(T, 2 * np.eye(4)) array_compare(SE3.Rx(pi / 2) * SE3.Ry(pi / 2) * SE3.Rx(-pi / 2), SE3.Rz(pi / 2)) @@ -1077,7 +1077,7 @@ def cv(v): array_compare(a, np.eye(4)) a = T / 2 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) array_compare(a, troty(0.3) / 2) def test_arith_vect(self): @@ -1110,14 +1110,14 @@ def test_arith_vect(self): array_compare(a[2], rz * rz) a = T * 2 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * 2) array_compare(a[1], ry * 2) array_compare(a[2], rz * 2) a = 2 * T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * 2) array_compare(a[1], ry * 2) @@ -1149,7 +1149,7 @@ def test_arith_vect(self): a = T a *= 2 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx * 2) array_compare(a[1], ry * 2) @@ -1194,7 +1194,7 @@ def test_arith_vect(self): array_compare(a[2], np.eye(4)) a = T / 2 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / 2) array_compare(a[1], ry / 2) @@ -1226,7 +1226,7 @@ def test_arith_vect(self): a = T a /= 2 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx / 2) array_compare(a[1], ry / 2) @@ -1235,28 +1235,28 @@ def test_arith_vect(self): # add T = SE3([rx, ry, rz]) a = T + rx - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + rx) array_compare(a[1], ry + rx) array_compare(a[2], rz + rx) a = rx + T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + rx) array_compare(a[1], rx + ry) array_compare(a[2], rx + rz) a = T + T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + rx) array_compare(a[1], ry + ry) array_compare(a[2], rz + rz) a = T + 1 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx + 1) array_compare(a[1], ry + 1) @@ -1265,28 +1265,28 @@ def test_arith_vect(self): # subtract T = SE3([rx, ry, rz]) a = T - rx - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx - rx) array_compare(a[1], ry - rx) array_compare(a[2], rz - rx) a = rx - T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx - rx) array_compare(a[1], rx - ry) array_compare(a[2], rx - rz) a = T - T - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx - rx) array_compare(a[1], ry - ry) array_compare(a[2], rz - rz) a = T - 1 - self.assertNotIsInstance(a, SE3) + assert not isinstance(a, SE3) nt.assert_equal(len(a), 3) array_compare(a[0], rx - 1) array_compare(a[1], ry - 1) From 1abeeab1983864671727131cb1b5d99fb09af304 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:38:11 -0500 Subject: [PATCH 11/21] Replace assertIsNone with bare assert --- tests/base/test_vectors.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index abd1de2c..4001f0db 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -176,7 +176,7 @@ def test_unittwist(self): unittwist([0, 0, -2, 0, 0, 0]), np.r_[0, 0, -1, 0, 0, 0] ) - self.assertIsNone(unittwist([0, 0, 0, 0, 0, 0])) + assert unittwist([0, 0, 0, 0, 0, 0]) is None def test_unittwist_norm(self): a = unittwist_norm([0, 0, 0, 1, 0, 0]) @@ -216,8 +216,8 @@ def test_unittwist_norm(self): nt.assert_array_almost_equal(a[1], 2) a = unittwist_norm([0, 0, 0, 0, 0, 0]) - self.assertIsNone(a[0]) - self.assertIsNone(a[1]) + assert a[0] is None + assert a[1] is None def test_unittwist2(self): nt.assert_array_almost_equal( @@ -233,7 +233,7 @@ def test_unittwist2(self): unittwist2([2, 0, -2]), np.r_[1, 0, -1] ) - self.assertIsNone(unittwist2([0, 0, 0])) + assert unittwist2([0, 0, 0]) is None def test_unittwist2_norm(self): a = unittwist2_norm([1, 0, 0]) @@ -253,8 +253,8 @@ def test_unittwist2_norm(self): nt.assert_array_almost_equal(a[1], 2) a = unittwist2_norm([0, 0, 0]) - self.assertIsNone(a[0]) - self.assertIsNone(a[1]) + assert a[0] is None + assert a[1] is None def test_iszerovec(self): assert iszerovec([0]) From 942eab58451cfb68f6aacdd36aeacdd809ff1fbb Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:40:00 -0500 Subject: [PATCH 12/21] Replace assertLessEqual with bare assert --- tests/test_pose3d.py | 4 ++-- tests/test_quaternion.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 4994d866..d8c8d07c 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -84,7 +84,7 @@ def test_constructor(self): R = SO3.Rand(theta_range=(0.1, 0.7)) assert isinstance(R, SO3) assert R.A.shape == (3, 3) - self.assertLessEqual(R.angvec()[0], 0.7) + assert R.angvec()[0] <= 0.7 self.assertGreaterEqual(R.angvec()[0], 0.1) # copy constructor @@ -862,7 +862,7 @@ def test_constructor(self): T = SE3.Rand(theta_range=(0.1, 0.7)) assert isinstance(T, SE3) assert T.A.shape == (4, 4) - self.assertLessEqual(T.angvec()[0], 0.7) + assert T.angvec()[0] <= 0.7 self.assertGreaterEqual(T.angvec()[0], 0.1) # copy constructor diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index 3644d493..db522185 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -52,13 +52,13 @@ def test_constructor_variants(self): np.random.seed(73) q = UnitQuaternion.Rand(theta_range=(0.1, 0.7)) assert isinstance(q, UnitQuaternion) - self.assertLessEqual(q.angvec()[0], 0.7) + assert q.angvec()[0] <= 0.7 self.assertGreaterEqual(q.angvec()[0], 0.1) q = UnitQuaternion.Rand(theta_range=(0.1, 0.7)) assert isinstance(q, UnitQuaternion) - self.assertLessEqual(q.angvec()[0], 0.7) + assert q.angvec()[0] <= 0.7 self.assertGreaterEqual(q.angvec()[0], 0.1) From ed7f5cc2becb7337e1aeaaf1c50c99142772ccb2 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:41:32 -0500 Subject: [PATCH 13/21] Replace assertGreaterEqual with bare assert --- tests/test_pose3d.py | 4 ++-- tests/test_quaternion.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index d8c8d07c..3424eee8 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -85,7 +85,7 @@ def test_constructor(self): assert isinstance(R, SO3) assert R.A.shape == (3, 3) assert R.angvec()[0] <= 0.7 - self.assertGreaterEqual(R.angvec()[0], 0.1) + assert R.angvec()[0] >= 0.1 # copy constructor R = SO3.Rx(pi / 2) @@ -863,7 +863,7 @@ def test_constructor(self): assert isinstance(T, SE3) assert T.A.shape == (4, 4) assert T.angvec()[0] <= 0.7 - self.assertGreaterEqual(T.angvec()[0], 0.1) + assert T.angvec()[0] >= 0.1 # copy constructor R = SE3.Rx(pi / 2) diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index db522185..3d03d4c0 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -53,13 +53,13 @@ def test_constructor_variants(self): q = UnitQuaternion.Rand(theta_range=(0.1, 0.7)) assert isinstance(q, UnitQuaternion) assert q.angvec()[0] <= 0.7 - self.assertGreaterEqual(q.angvec()[0], 0.1) + assert q.angvec()[0] >= 0.1 q = UnitQuaternion.Rand(theta_range=(0.1, 0.7)) assert isinstance(q, UnitQuaternion) assert q.angvec()[0] <= 0.7 - self.assertGreaterEqual(q.angvec()[0], 0.1) + assert q.angvec()[0] >= 0.1 def test_constructor(self): From ab8a2f1abb8bfffec59f0a6cca3f6e4a04f8f9dc Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:56:20 -0500 Subject: [PATCH 14/21] =?UTF-8?q?Replace=20self.assertAlmostEqual(a,=20b)?= =?UTF-8?q?=20=E2=86=92=20assert=20a=20=3D=3D=20pytest.approx(b)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/base/test_numeric.py | 7 +-- tests/base/test_transformsNd.py | 3 +- tests/base/test_vectors.py | 79 +++++++++++++++++---------------- tests/test_geom2d.py | 12 ++--- tests/test_geom3d.py | 10 ++--- tests/test_pose2d.py | 2 +- tests/test_pose3d.py | 20 +++------ tests/test_quaternion.py | 7 +-- 8 files changed, 68 insertions(+), 72 deletions(-) diff --git a/tests/base/test_numeric.py b/tests/base/test_numeric.py index 5fa0eed7..379751d1 100755 --- a/tests/base/test_numeric.py +++ b/tests/base/test_numeric.py @@ -9,6 +9,7 @@ import numpy as np import numpy.testing as nt +import pytest import unittest import math @@ -106,7 +107,7 @@ def test_gauss1d(self): assert len(x) == len(y) m = np.argmax(y) - self.assertAlmostEqual(x[m], 2) + assert x[m] == pytest.approx(2) def test_gauss2d(self): @@ -115,8 +116,8 @@ def test_gauss2d(self): Z = gauss2d([2, 3], np.eye(2), X, Y) m = np.unravel_index(np.argmax(Z, axis=None), Z.shape) - self.assertAlmostEqual(r[m[0]], 3) - self.assertAlmostEqual(r[m[1]], 2) + assert r[m[0]] == pytest.approx(3) + assert r[m[1]] == pytest.approx(2) # ---------------------------------------------------------------------------------------# diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index b71399ad..fc2d8326 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -9,6 +9,7 @@ import numpy as np import numpy.testing as nt +import pytest import unittest from math import pi import math @@ -396,7 +397,7 @@ def test_vexa(self): def test_det(self): a = np.array([[1, 2], [3, 4]]) - self.assertAlmostEqual(np.linalg.det(a), det(a)) + assert np.linalg.det(a) == pytest.approx(det(a)) @unittest.skipUnless(_symbolics, "sympy required") def test_det_sym(self): diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index 4001f0db..8214fc04 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -9,6 +9,7 @@ import numpy as np import numpy.testing as nt +import pytest import unittest from math import pi import math @@ -86,14 +87,14 @@ def test_isunitvec(self): assert not isunitvec([-2]) def test_norm(self): - self.assertAlmostEqual(norm([0, 0, 0]), 0) - self.assertAlmostEqual(norm([1, 2, 3]), math.sqrt(14)) - self.assertAlmostEqual(norm(np.r_[1, 2, 3]), math.sqrt(14)) + assert norm([0, 0, 0]) == pytest.approx(0) + assert norm([1, 2, 3]) == pytest.approx(math.sqrt(14)) + assert norm(np.r_[1, 2, 3]) == pytest.approx(math.sqrt(14)) def test_normsq(self): - self.assertAlmostEqual(normsq([0, 0, 0]), 0) - self.assertAlmostEqual(normsq([1, 2, 3]), 14) - self.assertAlmostEqual(normsq(np.r_[1, 2, 3]), 14) + assert normsq([0, 0, 0]) == pytest.approx(0) + assert normsq([1, 2, 3]) == pytest.approx(14) + assert normsq(np.r_[1, 2, 3]) == pytest.approx(14) @unittest.skipUnless(_symbolics, "sympy required") def test_norm_sym(self): @@ -290,38 +291,38 @@ def test_angdiff(self): assert isinstance(x, np.ndarray) def test_wrap(self): - self.assertAlmostEqual(wrap_0_2pi(0), 0) - self.assertAlmostEqual(wrap_0_2pi(2 * pi), 0) - self.assertAlmostEqual(wrap_0_2pi(3 * pi), pi) - self.assertAlmostEqual(wrap_0_2pi(-pi), pi) + assert wrap_0_2pi(0) == pytest.approx(0) + assert wrap_0_2pi(2 * pi) == pytest.approx(0) + assert wrap_0_2pi(3 * pi) == pytest.approx(pi) + assert wrap_0_2pi(-pi) == pytest.approx(pi) nt.assert_array_almost_equal( wrap_0_2pi([0, 2 * pi, 3 * pi, -pi]), [0, 0, pi, pi] ) - self.assertAlmostEqual(wrap_mpi_pi(0), 0) - self.assertAlmostEqual(wrap_mpi_pi(-pi), -pi) - self.assertAlmostEqual(wrap_mpi_pi(pi), -pi) - self.assertAlmostEqual(wrap_mpi_pi(2 * pi), 0) - self.assertAlmostEqual(wrap_mpi_pi(1.5 * pi), -0.5 * pi) - self.assertAlmostEqual(wrap_mpi_pi(-1.5 * pi), 0.5 * pi) + assert wrap_mpi_pi(0) == pytest.approx(0) + assert wrap_mpi_pi(-pi) == pytest.approx(-pi) + assert wrap_mpi_pi(pi) == pytest.approx(-pi) + assert wrap_mpi_pi(2 * pi) == pytest.approx(0) + assert wrap_mpi_pi(1.5 * pi) == pytest.approx(-0.5 * pi) + assert wrap_mpi_pi(-1.5 * pi) == pytest.approx(0.5 * pi) nt.assert_array_almost_equal( wrap_mpi_pi([0, -pi, pi, 2 * pi, 1.5 * pi, -1.5 * pi]), [0, -pi, -pi, 0, -0.5 * pi, 0.5 * pi], ) - self.assertAlmostEqual(wrap_0_pi(0), 0) - self.assertAlmostEqual(wrap_0_pi(pi), pi) - self.assertAlmostEqual(wrap_0_pi(1.2 * pi), 0.8 * pi) - self.assertAlmostEqual(wrap_0_pi(-0.2 * pi), 0.2 * pi) + assert wrap_0_pi(0) == pytest.approx(0) + assert wrap_0_pi(pi) == pytest.approx(pi) + assert wrap_0_pi(1.2 * pi) == pytest.approx(0.8 * pi) + assert wrap_0_pi(-0.2 * pi) == pytest.approx(0.2 * pi) nt.assert_array_almost_equal( wrap_0_pi([0, pi, 1.2 * pi, -0.2 * pi]), [0, pi, 0.8 * pi, 0.2 * pi] ) - self.assertAlmostEqual(wrap_mpi2_pi2(0), 0) - self.assertAlmostEqual(wrap_mpi2_pi2(-0.5 * pi), -0.5 * pi) - self.assertAlmostEqual(wrap_mpi2_pi2(0.5 * pi), 0.5 * pi) - self.assertAlmostEqual(wrap_mpi2_pi2(0.6 * pi), 0.4 * pi) - self.assertAlmostEqual(wrap_mpi2_pi2(-0.6 * pi), -0.4 * pi) + assert wrap_mpi2_pi2(0) == pytest.approx(0) + assert wrap_mpi2_pi2(-0.5 * pi) == pytest.approx(-0.5 * pi) + assert wrap_mpi2_pi2(0.5 * pi) == pytest.approx(0.5 * pi) + assert wrap_mpi2_pi2(0.6 * pi) == pytest.approx(0.4 * pi) + assert wrap_mpi2_pi2(-0.6 * pi) == pytest.approx(-0.4 * pi) nt.assert_array_almost_equal( wrap_mpi2_pi2([0, -0.5 * pi, 0.5 * pi, 0.6 * pi, -0.6 * pi]), [0, -0.5 * pi, 0.5 * pi, 0.4 * pi, -0.4 * pi], @@ -329,27 +330,27 @@ def test_wrap(self): for angle_factor in (0, 0.3, 0.5, 0.8, 1.0, 1.3, 1.5, 1.7, 2): theta = angle_factor * pi - self.assertAlmostEqual(angle_wrap(theta), wrap_mpi_pi(theta)) - self.assertAlmostEqual(angle_wrap(-theta), wrap_mpi_pi(-theta)) - self.assertAlmostEqual(angle_wrap(theta=theta, mode="-pi:pi"), wrap_mpi_pi(theta)) - self.assertAlmostEqual(angle_wrap(theta=-theta, mode="-pi:pi"), wrap_mpi_pi(-theta)) - self.assertAlmostEqual(angle_wrap(theta=theta, mode="0:2pi"), wrap_0_2pi(theta)) - self.assertAlmostEqual(angle_wrap(theta=-theta, mode="0:2pi"), wrap_0_2pi(-theta)) - self.assertAlmostEqual(angle_wrap(theta=theta, mode="0:pi"), wrap_0_pi(theta)) - self.assertAlmostEqual(angle_wrap(theta=-theta, mode="0:pi"), wrap_0_pi(-theta)) - self.assertAlmostEqual(angle_wrap(theta=theta, mode="-pi/2:pi/2"), wrap_mpi2_pi2(theta)) - self.assertAlmostEqual(angle_wrap(theta=-theta, mode="-pi/2:pi/2"), wrap_mpi2_pi2(-theta)) + assert angle_wrap(theta) == pytest.approx(wrap_mpi_pi(theta)) + assert angle_wrap(-theta) == pytest.approx(wrap_mpi_pi(-theta)) + assert angle_wrap(theta=theta, mode="-pi:pi") == pytest.approx(wrap_mpi_pi(theta)) + assert angle_wrap(theta=-theta, mode="-pi:pi") == pytest.approx(wrap_mpi_pi(-theta)) + assert angle_wrap(theta=theta, mode="0:2pi") == pytest.approx(wrap_0_2pi(theta)) + assert angle_wrap(theta=-theta, mode="0:2pi") == pytest.approx(wrap_0_2pi(-theta)) + assert angle_wrap(theta=theta, mode="0:pi") == pytest.approx(wrap_0_pi(theta)) + assert angle_wrap(theta=-theta, mode="0:pi") == pytest.approx(wrap_0_pi(-theta)) + assert angle_wrap(theta=theta, mode="-pi/2:pi/2") == pytest.approx(wrap_mpi2_pi2(theta)) + assert angle_wrap(theta=-theta, mode="-pi/2:pi/2") == pytest.approx(wrap_mpi2_pi2(-theta)) with self.assertRaises(ValueError): angle_wrap(theta=theta, mode="foo") def test_angle_stats(self): theta = np.linspace(3 * pi / 2, 5 * pi / 2, 50) - self.assertAlmostEqual(angle_mean(theta), 0) - self.assertAlmostEqual(angle_std(theta), 0.9717284050981313) + assert angle_mean(theta) == pytest.approx(0) + assert angle_std(theta) == pytest.approx(0.9717284050981313) theta = np.linspace(pi / 2, 3 * pi / 2, 50) - self.assertAlmostEqual(angle_mean(theta), pi) - self.assertAlmostEqual(angle_std(theta), 0.9717284050981313) + assert angle_mean(theta) == pytest.approx(pi) + assert angle_std(theta) == pytest.approx(0.9717284050981313) def test_removesmall(self): v = np.r_[1, 2, 3] diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index 17361a49..403122e7 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -147,31 +147,31 @@ def test_constructor(self): e = Ellipse(E=E) nt.assert_almost_equal(e.E, E) nt.assert_almost_equal(e.centre, [0, 0]) - self.assertAlmostEqual(e.theta, 1.1780972450961724) + assert e.theta == pytest.approx(1.1780972450961724) e = Ellipse(radii=(1, 2), theta=0) nt.assert_almost_equal(e.E, np.diag([1, 0.25])) nt.assert_almost_equal(e.centre, [0, 0]) nt.assert_almost_equal(e.radii, [1, 2]) - self.assertAlmostEqual(e.theta, 0) + assert e.theta == pytest.approx(0) e = Ellipse(radii=(1, 2), theta=np.pi / 2) nt.assert_almost_equal(e.E, np.diag([0.25, 1])) nt.assert_almost_equal(e.centre, [0, 0]) nt.assert_almost_equal(e.radii, [2, 1]) - self.assertAlmostEqual(e.theta, np.pi / 2) + assert e.theta == pytest.approx(np.pi / 2) E = np.array([[1, 1], [1, 3]]) e = Ellipse(E=E, centre=[3, 4]) nt.assert_almost_equal(e.E, E) nt.assert_almost_equal(e.centre, [3, 4]) - self.assertAlmostEqual(e.theta, 1.1780972450961724) + assert e.theta == pytest.approx(1.1780972450961724) e = Ellipse(radii=(1, 2), theta=0, centre=[3, 4]) nt.assert_almost_equal(e.E, np.diag([1, 0.25])) nt.assert_almost_equal(e.centre, [3, 4]) nt.assert_almost_equal(e.radii, [1, 2]) - self.assertAlmostEqual(e.theta, 0) + assert e.theta == pytest.approx(0) def test_Polynomial(self): e = Ellipse.Polynomial([2, 3, 1, 0, 0, -1]) @@ -226,7 +226,7 @@ def test_misc(self): e = Ellipse(radii=(1, 2), theta=np.pi / 2) assert isinstance(str(e), str) - self.assertAlmostEqual(e.area, np.pi * 2) + assert e.area == pytest.approx(np.pi * 2) e = Ellipse(radii=(1, 2), theta=0) assert e.contains((0, 0)) diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index b46ceaa0..cacb0bec 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -101,21 +101,21 @@ def test_closest(self): p, d = L.closest_to_point(P) nt.assert_array_almost_equal(p, P) - self.assertAlmostEqual(d, 0) + assert d == pytest.approx(0) # validate closest with given points and origin p, d = L.closest_to_point(Q) nt.assert_array_almost_equal(p, Q) - self.assertAlmostEqual(d, 0) + assert d == pytest.approx(0) L = Line3.Join([-1, 1, 2], [1, 1, 2]) p, d = L.closest_to_point([0, 1, 2]) nt.assert_array_almost_equal(p, np.r_[0, 1, 2]) - self.assertAlmostEqual(d, 0) + assert d == pytest.approx(0) p, d = L.closest_to_point([5, 1, 2]) nt.assert_array_almost_equal(p, np.r_[5, 1, 2]) - self.assertAlmostEqual(d, 0) + assert d == pytest.approx(0) p, d = L.closest_to_point([0, 0, 0]) nt.assert_array_almost_equal(p, L.pp) @@ -123,7 +123,7 @@ def test_closest(self): p, d = L.closest_to_point([5, 1, 0]) nt.assert_array_almost_equal(p, [5, 1, 2]) - self.assertAlmostEqual(d, 2) + assert d == pytest.approx(2) @pytest.mark.skipif( sys.platform.startswith("darwin") and sys.version_info < (3, 11), diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index 5c61a0b5..0155656a 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -201,7 +201,7 @@ def test_miscellany(self): r = SO2( 0.3, ) - self.assertAlmostEqual(np.linalg.det(r.A), 1) + assert np.linalg.det(r.A) == pytest.approx(1) assert r.N == 2 diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 3424eee8..23f3de9e 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -1297,26 +1297,18 @@ def test_angle(self): r1 = SO3.Rx(0.1) r2 = SO3.Rx(0.2) for metric in range(6): - self.assertAlmostEqual(r1.angdist(other=r1, metric=metric), 0.0) + assert r1.angdist(other=r1, metric=metric) == pytest.approx(0.0) self.assertGreater(r1.angdist(other=r2, metric=metric), 0.0) - self.assertAlmostEqual( - r1.angdist(other=r2, metric=metric), r2.angdist(other=r1, metric=metric) - ) + assert r1.angdist(other=r2, metric=metric) == pytest.approx(r2.angdist(other=r1, metric=metric)) # angle between SE3's p1a, p1b = SE3.Rx(0.1), SE3.Rx(0.1, t=(1, 2, 3)) p2a, p2b = SE3.Rx(0.2), SE3.Rx(0.2, t=(3, 2, 1)) for metric in range(6): - self.assertAlmostEqual(p1a.angdist(other=p1a, metric=metric), 0.0) + assert p1a.angdist(other=p1a, metric=metric) == pytest.approx(0.0) self.assertGreater(p1a.angdist(other=p2a, metric=metric), 0.0) - self.assertAlmostEqual(p1a.angdist(other=p1b, metric=metric), 0.0) - self.assertAlmostEqual( - p1a.angdist(other=p2a, metric=metric), - p2a.angdist(other=p1a, metric=metric), - ) - self.assertAlmostEqual( - p1a.angdist(other=p2a, metric=metric), - p1a.angdist(other=p2b, metric=metric), - ) + assert p1a.angdist(other=p1b, metric=metric) == pytest.approx(0.0) + assert p1a.angdist(other=p2a, metric=metric) == pytest.approx(p2a.angdist(other=p1a, metric=metric)) + assert p1a.angdist(other=p2a, metric=metric) == pytest.approx(p1a.angdist(other=p2b, metric=metric)) # angdist is not implemented for mismatched types with self.assertRaises(ValueError): _ = r1.angdist(p1a) diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index 3d03d4c0..05856744 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -1,6 +1,7 @@ import math from math import pi import numpy.testing as nt +import pytest import unittest from spatialmath import * @@ -543,18 +544,18 @@ def test_conversions(self): th = 0.2 v = unitvec([1, 2, 3]) [a, b] = UnitQuaternion.AngVec(th, v).angvec() - self.assertAlmostEqual(a, th) + assert a == pytest.approx(th) nt.assert_array_almost_equal(b, v) [a, b] = UnitQuaternion.AngVec(-th, v).angvec() - self.assertAlmostEqual(a, th) + assert a == pytest.approx(th) nt.assert_array_almost_equal(b, -v) # null rotation case th = 0 v = unitvec([1, 2, 3]) [a, b] = UnitQuaternion.AngVec(th, v).angvec() - self.assertAlmostEqual(a, th) + assert a == pytest.approx(th) # SO3 convert to SO3 class # SE3 convert to SE3 class From 1271de8d1299012206a529f877ddf687045535dc Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 14:59:40 -0500 Subject: [PATCH 15/21] Replace assertGreater and assertLess with bare assert --- tests/base/test_quaternions.py | 4 ++-- tests/test_pose3d.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/base/test_quaternions.py b/tests/base/test_quaternions.py index 70eace50..08869675 100644 --- a/tests/base/test_quaternions.py +++ b/tests/base/test_quaternions.py @@ -134,8 +134,8 @@ def test_rotation(self): large_rotation = math.pi + 0.01 q1 = r2q(tr.rotx(large_rotation), shortest=False) q2 = r2q(tr.rotx(large_rotation), shortest=True) - self.assertLess(q1[0], 0) - self.assertGreater(q2[0], 0) + assert q1[0] < 0 + assert q2[0] > 0 assert qisequal(q1=q1, q2=q2, unitq=True) def test_slerp(self): diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 23f3de9e..32cb5c76 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -1298,14 +1298,14 @@ def test_angle(self): r2 = SO3.Rx(0.2) for metric in range(6): assert r1.angdist(other=r1, metric=metric) == pytest.approx(0.0) - self.assertGreater(r1.angdist(other=r2, metric=metric), 0.0) + assert r1.angdist(other=r2, metric=metric) > 0.0 assert r1.angdist(other=r2, metric=metric) == pytest.approx(r2.angdist(other=r1, metric=metric)) # angle between SE3's p1a, p1b = SE3.Rx(0.1), SE3.Rx(0.1, t=(1, 2, 3)) p2a, p2b = SE3.Rx(0.2), SE3.Rx(0.2, t=(3, 2, 1)) for metric in range(6): assert p1a.angdist(other=p1a, metric=metric) == pytest.approx(0.0) - self.assertGreater(p1a.angdist(other=p2a, metric=metric), 0.0) + assert p1a.angdist(other=p2a, metric=metric) > 0.0 assert p1a.angdist(other=p1b, metric=metric) == pytest.approx(0.0) assert p1a.angdist(other=p2a, metric=metric) == pytest.approx(p2a.angdist(other=p1a, metric=metric)) assert p1a.angdist(other=p2a, metric=metric) == pytest.approx(p1a.angdist(other=p2b, metric=metric)) From 4411e696a844d6a19aaf6f6be777d89dfeb81a4a Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 15:04:22 -0500 Subject: [PATCH 16/21] replace (unittest) self.assertRaises with pytest.raises --- tests/base/test_quaternions.py | 3 ++- tests/base/test_transforms3d.py | 3 ++- tests/base/test_transformsNd.py | 38 ++++++++++++++++----------------- tests/base/test_vectors.py | 12 +++++------ tests/test_geom3d.py | 2 +- tests/test_pose3d.py | 12 +++++------ tests/test_quaternion.py | 6 +++--- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/tests/base/test_quaternions.py b/tests/base/test_quaternions.py index 08869675..6f3ddcf7 100644 --- a/tests/base/test_quaternions.py +++ b/tests/base/test_quaternions.py @@ -30,6 +30,7 @@ # 3. Peter Corke, 2020 import numpy.testing as nt +import pytest import unittest from spatialmath.base.vectors import * @@ -222,7 +223,7 @@ def test_r2q(self): nt.assert_array_almost_equal(q1a, r2q(r1.R, order="sxyz")) nt.assert_array_almost_equal(q1b, r2q(r1.R, order="xyzs")) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): nt.assert_array_almost_equal(q1a, r2q(r1.R, order="aaa")) def test_qangle(self): diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index c2809988..d530d86c 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -10,6 +10,7 @@ import numpy as np import numpy.testing as nt +import pytest import unittest from math import pi import math @@ -528,7 +529,7 @@ def test_tr2angvec(self): # check a rotation matrix that should fail badR = roty(true_ang) + eps - with self.assertRaises(ValueError): + with pytest.raises(ValueError): tr2angvec(badR, check=True) # run without check diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index fc2d8326..cdc7e30d 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -56,14 +56,14 @@ def test_r2t(self): nt.assert_array_almost_equal(T[0:2, 2], np.r_[0, 0]) nt.assert_array_almost_equal(T[:2, :2], R) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): r2t(3) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): r2t(np.eye(3, 4)) _ = r2t(np.ones((3, 3)), check=False) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): r2t(np.ones((3, 3)), check=True) @unittest.skipUnless(_symbolics, "sympy required") @@ -98,10 +98,10 @@ def test_t2r(self): nt.assert_array_almost_equal(T[:2, :2], R) nt.assert_array_almost_equal(transl2(T), np.array(t)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): t2r(3) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): r2t(np.eye(3, 4)) def test_rt2tr(self): @@ -119,17 +119,17 @@ def test_rt2tr(self): nt.assert_array_almost_equal(t2r(T), R) nt.assert_array_almost_equal(transl2(T), np.array(t)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): rt2tr(3, 4) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): rt2tr(np.eye(3, 4), [1, 2, 3, 4]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): rt2tr(np.eye(4, 4), [1, 2, 3, 4]) _ = rt2tr(np.ones((3, 3)), [1, 2, 3], check=False) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): rt2tr(np.ones((3, 3)), [1, 2, 3], check=True) @unittest.skipUnless(_symbolics, "sympy required") @@ -155,10 +155,10 @@ def test_tr2rt(self): nt.assert_array_almost_equal(T[:2, :2], R) nt.assert_array_almost_equal(T[:2, 2], t) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): R, t = tr2rt(3) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): R, t = tr2rt(np.eye(3, 4)) def test_Ab2M(self): @@ -178,13 +178,13 @@ def test_Ab2M(self): nt.assert_array_almost_equal(T[:2, 2], np.array(t)) nt.assert_array_almost_equal(T[2, :], np.array([0, 0, 0])) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): Ab2M(3, 4) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): Ab2M(np.eye(3, 4), [1, 2, 3, 4]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): Ab2M(np.eye(4, 4), [1, 2, 3, 4]) def test_checks(self): @@ -286,7 +286,7 @@ def test_homtrans(self): v2 = homtrans(T, v) nt.assert_almost_equal(v2, np.c_[[-11, 12], [5, -1]]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): T = trotx(pi / 2, t=[1, 2, 3]) v = [10, 12] v2 = homtrans(T, v) @@ -308,7 +308,7 @@ def test_skew(self): assert sk[1, 0] == 1 nt.assert_almost_equal(sk.diagonal(), np.r_[0, 0]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): sk = skew([1, 2]) def test_vex(self): @@ -323,10 +323,10 @@ def test_vex(self): nt.assert_almost_equal(vex(sk), t) _ = vex(np.ones((3, 3)), check=False) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = vex(np.ones((3, 3)), check=True) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = vex(np.eye(4, 4)) def test_isskew(self): @@ -381,7 +381,7 @@ def test_skewa(self): nt.assert_almost_equal(sk[:2, 2], [1, 2]) nt.assert_almost_equal(vex(sk[:2, :2]), [3]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): sk = skew([1, 2]) def test_vexa(self): diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index 8214fc04..59d8c91f 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -54,11 +54,11 @@ def test_unit(self): nt.assert_array_almost_equal(unitvec([0, 9, 0]), np.r_[0, 1, 0]) nt.assert_array_almost_equal(unitvec([0, 0, 9]), np.r_[0, 0, 1]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): unitvec([0, 0, 0]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): unitvec([0]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): unitvec(0) def test_colvec(self): @@ -140,10 +140,10 @@ def test_isunittwist(self): # not a unit translation twist assert not isunittwist2([2, 0, 0]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): isunittwist([3, 4]) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): isunittwist2([3, 4]) def test_unittwist(self): @@ -340,7 +340,7 @@ def test_wrap(self): assert angle_wrap(theta=-theta, mode="0:pi") == pytest.approx(wrap_0_pi(-theta)) assert angle_wrap(theta=theta, mode="-pi/2:pi/2") == pytest.approx(wrap_mpi2_pi2(theta)) assert angle_wrap(theta=-theta, mode="-pi/2:pi/2") == pytest.approx(wrap_mpi2_pi2(-theta)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): angle_wrap(theta=theta, mode="foo") def test_angle_stats(self): diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index cacb0bec..91514aae 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -21,7 +21,7 @@ class Line3Test(unittest.TestCase): def test_constructor1(self): # construct from 6-vector - with self.assertRaises(ValueError): + with pytest.raises(ValueError): L = Line3([1, 2, 3, 4, 5, 6], check=True) L = Line3([1, 2, 3, 4, 5, 6], check=False) diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 32cb5c76..70dcc787 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -885,9 +885,9 @@ def test_constructor(self): nt.assert_equal(T.t, [1, 2, 0]) # Bad number of arguments - with self.assertRaises(ValueError): + with pytest.raises(ValueError): T = SE3(1.0, 0.0) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): T = SE3(1.0, 0.0, 0.0, 0.0) def test_shape(self): @@ -1310,17 +1310,17 @@ def test_angle(self): assert p1a.angdist(other=p2a, metric=metric) == pytest.approx(p2a.angdist(other=p1a, metric=metric)) assert p1a.angdist(other=p2a, metric=metric) == pytest.approx(p1a.angdist(other=p2b, metric=metric)) # angdist is not implemented for mismatched types - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = r1.angdist(p1a) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = r1._op2(right=p1a, op=r1.angdist) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = p1a._op2(right=r1, op=p1a.angdist) # in general, the _op2 interface enforces an isinstance check. - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = r1._op2(right=(1, 0, 0), op=r1.angdist) def test_functions(self): diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index 05856744..c99441fc 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -171,14 +171,14 @@ def test_constructor(self): # fail when invalid arrays are provided # invalid rotation matrix R = 1.1 * np.eye(3) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): UnitQuaternion(R, check=True) # wrong shape to be anything R = np.zeros((5, 5)) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): UnitQuaternion(R, check=True) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): UnitQuaternion(R, check=False) def test_concat(self): From c37a828edfaed98402090db7d54603fd5ec0a03c Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 15:06:33 -0500 Subject: [PATCH 17/21] Replace a few leftover unittest-style assertions (via methods) with bare assert --- tests/base/test_transformsNd.py | 4 +--- tests/test_geom3d.py | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index cdc7e30d..d9d61242 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -230,9 +230,7 @@ def test_checks(self): assert not isR(T) assert not isrot2(T) assert not isrot(T) - self.assertTrue( - ishom(T), - ) + assert ishom(T) assert not ishom2(T) assert not isrot2(T, True) assert not isrot(T, True) diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 91514aae..4d8be238 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -214,13 +214,9 @@ def test_intersect(self): # L1, || L2, but doesnt intersect # L3, intersects L4 - self.assertFalse( - L1 ^ L2, - ) + assert not L1 ^ L2 - self.assertTrue( - L3 ^ L4, - ) + assert L3 ^ L4 def test_commonperp(self): L1 = Line3.PointDir([4, 5, 6], [0, 0, 1]) From 214499e4dbcaf76da1c0bfb6676635c44558d10e Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 15:12:44 -0500 Subject: [PATCH 18/21] Replace unittest.skipUnless with pytest.mark.skipif --- tests/base/test_symbolic.py | 9 +++++---- tests/base/test_transformsNd.py | 6 +++--- tests/base/test_vectors.py | 2 +- tests/base/test_velocity.py | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/base/test_symbolic.py b/tests/base/test_symbolic.py index 0095ea65..f96da7fd 100644 --- a/tests/base/test_symbolic.py +++ b/tests/base/test_symbolic.py @@ -1,3 +1,4 @@ +import pytest import unittest import math @@ -12,7 +13,7 @@ class Test_symbolic(unittest.TestCase): - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_symbol(self): theta = symbol("theta") assert isinstance(theta, sp.Expr) @@ -36,7 +37,7 @@ def test_symbol(self): assert isinstance(_, sp.Expr) assert _.is_real - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_issymbol(self): theta = symbol("theta") assert not issymbol(3) @@ -44,7 +45,7 @@ def test_issymbol(self): assert not issymbol([1, 2]) assert issymbol(theta) - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_functions(self): theta = symbol("theta") @@ -60,7 +61,7 @@ def test_functions(self): x = (theta - 1) * (theta + 1) - theta ** 2 assert math.isclose(simplify(x).evalf(), -1) - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_constants(self): x = zero() diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index d9d61242..f8cefcbe 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -66,7 +66,7 @@ def test_r2t(self): with pytest.raises(ValueError): r2t(np.ones((3, 3)), check=True) - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_r2t_sym(self): theta = symbol("theta") R = rot2(theta) @@ -132,7 +132,7 @@ def test_rt2tr(self): with pytest.raises(ValueError): rt2tr(np.ones((3, 3)), [1, 2, 3], check=True) - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_rt2tr_sym(self): theta = symbol("theta") R = rotx(theta) @@ -397,7 +397,7 @@ def test_det(self): a = np.array([[1, 2], [3, 4]]) assert np.linalg.det(a) == pytest.approx(det(a)) - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_det_sym(self): x, y = symbol("x y") a = np.array([[x, y], [y, x]]) diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index 59d8c91f..edccc126 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -96,7 +96,7 @@ def test_normsq(self): assert normsq([1, 2, 3]) == pytest.approx(14) assert normsq(np.r_[1, 2, 3]) == pytest.approx(14) - @unittest.skipUnless(_symbolics, "sympy required") + @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_norm_sym(self): x, y = symbol("x y") v = [x, y] diff --git a/tests/base/test_velocity.py b/tests/base/test_velocity.py index 0f9beae2..f179cfc4 100644 --- a/tests/base/test_velocity.py +++ b/tests/base/test_velocity.py @@ -218,7 +218,7 @@ def test_angvelxform_dot_rpy_zyx(self): res = rotvelxform_inv_dot(gamma, gamma_d, representation=rep, full=False) nt.assert_array_almost_equal(Adot, res, decimal=4) - # @unittest.skip("bug in angvelxform_dot for exponential coordinates") + # @pytest.mark.skip("bug in angvelxform_dot for exponential coordinates") def test_angvelxform_dot_exp(self): rep = "exp" gamma = [0.1, 0.2, 0.3] From a5b7982355e197f6a5f26383d80a0e44c42957b8 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 15:16:41 -0500 Subject: [PATCH 19/21] Remove __main__ logic from tests, and just rely on pytest --- tests/base/test_graphics.py | 5 ----- tests/base/test_numeric.py | 6 ------ tests/base/test_quaternions.py | 4 ---- tests/base/test_symbolic.py | 6 ------ tests/base/test_transforms.py | 6 ------ tests/base/test_transforms2d.py | 5 ----- tests/base/test_transforms3d.py | 4 ---- tests/base/test_transforms3d_plot.py | 5 ----- tests/base/test_transformsNd.py | 5 ----- tests/base/test_vectors.py | 5 ----- tests/base/test_velocity.py | 5 ----- tests/test_dualquaternion.py | 6 ------ tests/test_geom2d.py | 4 ---- tests/test_geom3d.py | 4 ---- tests/test_pose2d.py | 5 ----- tests/test_pose3d.py | 5 ----- tests/test_quaternion.py | 5 ----- tests/test_spatialvector.py | 5 ----- tests/test_twist.py | 6 ------ 19 files changed, 96 deletions(-) diff --git a/tests/base/test_graphics.py b/tests/base/test_graphics.py index c8b999ad..bd9e17e3 100644 --- a/tests/base/test_graphics.py +++ b/tests/base/test_graphics.py @@ -144,8 +144,3 @@ def test_cone(self): resolution=5, color="red", ) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main(buffer=True) diff --git a/tests/base/test_numeric.py b/tests/base/test_numeric.py index 379751d1..38c627d5 100755 --- a/tests/base/test_numeric.py +++ b/tests/base/test_numeric.py @@ -118,9 +118,3 @@ def test_gauss2d(self): m = np.unravel_index(np.argmax(Z, axis=None), Z.shape) assert r[m[0]] == pytest.approx(3) assert r[m[1]] == pytest.approx(2) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - - unittest.main() diff --git a/tests/base/test_quaternions.py b/tests/base/test_quaternions.py index 6f3ddcf7..13e93525 100644 --- a/tests/base/test_quaternions.py +++ b/tests/base/test_quaternions.py @@ -235,7 +235,3 @@ def test_qangle(self): q1 = [1., 0, 0, 0] q2 = [1 / np.sqrt(2), 1 / np.sqrt(2), 0, 0] # 90deg rotation about x-axis nt.assert_almost_equal(qangle(q1, q2), np.pi / 2) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/base/test_symbolic.py b/tests/base/test_symbolic.py index f96da7fd..4f8e4c36 100644 --- a/tests/base/test_symbolic.py +++ b/tests/base/test_symbolic.py @@ -79,9 +79,3 @@ def test_constants(self): x = pi() assert isinstance(x, sp.Expr) assert math.isclose(x.evalf(), math.pi) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": # pragma: no cover - - unittest.main() diff --git a/tests/base/test_transforms.py b/tests/base/test_transforms.py index d74a048e..eb19f365 100755 --- a/tests/base/test_transforms.py +++ b/tests/base/test_transforms.py @@ -321,9 +321,3 @@ def test_trexp2(self): def test_trnorm(self): T0 = transl(-1, -2, -3) @ trotx(-0.3) nt.assert_array_almost_equal(trnorm(T0), T0) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - - unittest.main() diff --git a/tests/base/test_transforms2d.py b/tests/base/test_transforms2d.py index 1bdf066c..9920a493 100755 --- a/tests/base/test_transforms2d.py +++ b/tests/base/test_transforms2d.py @@ -299,8 +299,3 @@ def test_plot(self): transl2(4, 3) @ trot2(math.pi / 3), block=False, color="green", frame="c" ) plt.close("all") - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index d530d86c..9cd9cfc9 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -806,7 +806,3 @@ def test_x2tr(self): nt.assert_array_almost_equal( x2tr(x, representation="exp"), transl(t) @ r2t(trexp(gamma)) ) - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/base/test_transforms3d_plot.py b/tests/base/test_transforms3d_plot.py index 9e92e4ab..07d30784 100755 --- a/tests/base/test_transforms3d_plot.py +++ b/tests/base/test_transforms3d_plot.py @@ -86,8 +86,3 @@ def test_animate(self): plt.close("all") # test animate with line not arrow, text, test with SO(3) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index f8cefcbe..0a19ef4e 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -402,8 +402,3 @@ def test_det_sym(self): x, y = symbol("x y") a = np.array([[x, y], [y, x]]) assert det(a) == x**2 - y**2 - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index edccc126..f8743fb5 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -367,8 +367,3 @@ def test_removesmall(self): v = np.r_[1, 2, 3, 1e-10, -1e-10] nt.assert_array_almost_equal(removesmall(v, tol=1e8), [1, 2, 3, 0, 0]) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/base/test_velocity.py b/tests/base/test_velocity.py index f179cfc4..78ca0517 100644 --- a/tests/base/test_velocity.py +++ b/tests/base/test_velocity.py @@ -272,8 +272,3 @@ def test_x_tr(self): # f = lambda gamma: angvelxform(gamma, options) # nt.assert_array_almost_equal(angvelxform_dot(gamma, options), numjac(f)) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_dualquaternion.py b/tests/test_dualquaternion.py index e83810c4..c1cda855 100644 --- a/tests/test_dualquaternion.py +++ b/tests/test_dualquaternion.py @@ -108,9 +108,3 @@ def test_multiply(self): d = d1 * d2 nt.assert_array_almost_equal(d.SE3().A, T.A) - - -# ---------------------------------------------------------------------------------------# -if __name__ == '__main__': # pragma: no cover - - unittest.main() diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index 403122e7..8290f40c 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -241,7 +241,3 @@ def test_misc(self): assert not e.contains((0, -2.1)) assert e.contains(np.array([[0, 0], [3, 3]]).T) == [True, False] - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 4d8be238..3e9a48fa 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -316,7 +316,3 @@ def test_methods(self): # # px.intersect_plane(plane) # py.intersect_plane(plane) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index 0155656a..73858a67 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -495,8 +495,3 @@ def test_graphics(self): T1.animate(repeat=False, dims=[-2, 2], nframes=10) T1.animate(T0=T2, repeat=False, dims=[-2, 2], nframes=10) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main(buffer=True) diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 70dcc787..3088e68a 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -1332,8 +1332,3 @@ def test_functions_vect(self): # inv # .T pass - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index c99441fc..d73d1ca3 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -1015,8 +1015,3 @@ def test_miscellany(self): nt.assert_equal(u.inner(u), 1) nt.assert_equal(q.inner(q), q.norm() ** 2) nt.assert_equal(q.inner(u), np.dot(q.vec, u.vec)) - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_spatialvector.py b/tests/test_spatialvector.py index 8db1d41f..75b5aa9e 100644 --- a/tests/test_spatialvector.py +++ b/tests/test_spatialvector.py @@ -227,8 +227,3 @@ def test_products(self): # v x I, I x v # twist x v, twist x a, twist x F pass - - -# ---------------------------------------------------------------------------------------# -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_twist.py b/tests/test_twist.py index ad8e2c40..35f9acbb 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -362,9 +362,3 @@ def test_prod(self): x = Twist2([x1, x2]) array_compare( x.prod().SE2(), T1 * T2) - -# ---------------------------------------------------------------------------------------# -if __name__ == '__main__': - - - unittest.main() From 648ed91b0ff410d45541fc9a5fd7a95c8ba47532 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Tue, 26 Nov 2024 15:28:51 -0500 Subject: [PATCH 20/21] Remove all references to unittest --- tests/base/test_graphics.py | 3 +-- tests/base/test_numeric.py | 3 +-- tests/base/test_quaternions.py | 3 +-- tests/base/test_symbolic.py | 3 +-- tests/base/test_transforms.py | 3 +-- tests/base/test_transforms2d.py | 3 +-- tests/base/test_transforms3d.py | 3 +-- tests/base/test_transforms3d_plot.py | 3 +-- tests/base/test_transformsNd.py | 3 +-- tests/base/test_vectors.py | 3 +-- tests/base/test_velocity.py | 3 +-- tests/test_dualquaternion.py | 5 ++--- tests/test_geom2d.py | 7 +++---- tests/test_geom3d.py | 3 +-- tests/test_pose2d.py | 5 ++--- tests/test_pose3d.py | 5 ++--- tests/test_quaternion.py | 5 ++--- tests/test_spatialvector.py | 3 +-- tests/test_spline.py | 3 +-- tests/test_twist.py | 5 ++--- 20 files changed, 27 insertions(+), 47 deletions(-) diff --git a/tests/base/test_graphics.py b/tests/base/test_graphics.py index bd9e17e3..125ec79c 100644 --- a/tests/base/test_graphics.py +++ b/tests/base/test_graphics.py @@ -1,4 +1,3 @@ -import unittest import numpy as np import matplotlib matplotlib.use("AGG") @@ -10,7 +9,7 @@ # test graphics primitives # TODO check they actually create artists -class TestGraphics(unittest.TestCase): +class TestGraphics: def teardown_method(self, method): plt.close("all") diff --git a/tests/base/test_numeric.py b/tests/base/test_numeric.py index 38c627d5..1ed794fa 100755 --- a/tests/base/test_numeric.py +++ b/tests/base/test_numeric.py @@ -10,14 +10,13 @@ import numpy as np import numpy.testing as nt import pytest -import unittest import math from spatialmath.base.numeric import * -class TestNumeric(unittest.TestCase): +class TestNumeric: def test_numjac(self): pass diff --git a/tests/base/test_quaternions.py b/tests/base/test_quaternions.py index 13e93525..2ae73ccd 100644 --- a/tests/base/test_quaternions.py +++ b/tests/base/test_quaternions.py @@ -31,7 +31,6 @@ import numpy.testing as nt import pytest -import unittest from spatialmath.base.vectors import * import spatialmath.base as tr @@ -39,7 +38,7 @@ import spatialmath as sm -class TestQuaternion(unittest.TestCase): +class TestQuaternion: def test_ops(self): nt.assert_array_almost_equal(qeye(), np.r_[1, 0, 0, 0]) diff --git a/tests/base/test_symbolic.py b/tests/base/test_symbolic.py index 4f8e4c36..4106381f 100644 --- a/tests/base/test_symbolic.py +++ b/tests/base/test_symbolic.py @@ -1,5 +1,4 @@ import pytest -import unittest import math try: @@ -12,7 +11,7 @@ from spatialmath.base.symbolic import * -class Test_symbolic(unittest.TestCase): +class Test_symbolic: @pytest.mark.skipif(not _symbolics, reason="sympy required") def test_symbol(self): theta = symbol("theta") diff --git a/tests/base/test_transforms.py b/tests/base/test_transforms.py index eb19f365..62fed783 100755 --- a/tests/base/test_transforms.py +++ b/tests/base/test_transforms.py @@ -10,7 +10,6 @@ import numpy as np import numpy.testing as nt -import unittest from math import pi import math from scipy.linalg import logm, expm @@ -23,7 +22,7 @@ import matplotlib.pyplot as plt -class TestLie(unittest.TestCase): +class TestLie: def test_vex(self): S = np.array([[0, -3], [3, 0]]) diff --git a/tests/base/test_transforms2d.py b/tests/base/test_transforms2d.py index 9920a493..24c284a2 100755 --- a/tests/base/test_transforms2d.py +++ b/tests/base/test_transforms2d.py @@ -9,7 +9,6 @@ import numpy as np import numpy.testing as nt -import unittest from math import pi import math from scipy.linalg import logm, expm @@ -34,7 +33,7 @@ import matplotlib.pyplot as plt -class Test2D(unittest.TestCase): +class Test2D: def test_rot2(self): R = np.array([[1, 0], [0, 1]]) nt.assert_array_almost_equal(rot2(0), R) diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index 9cd9cfc9..213502f7 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -11,7 +11,6 @@ import numpy as np import numpy.testing as nt import pytest -import unittest from math import pi import math from scipy.linalg import logm, expm @@ -20,7 +19,7 @@ from spatialmath.base.transformsNd import isR, t2r, r2t, rt2tr, skew -class Test3D(unittest.TestCase): +class Test3D: def test_checks(self): # 2D case, with rotation matrix R = np.eye(2) diff --git a/tests/base/test_transforms3d_plot.py b/tests/base/test_transforms3d_plot.py index 07d30784..517b616d 100755 --- a/tests/base/test_transforms3d_plot.py +++ b/tests/base/test_transforms3d_plot.py @@ -10,7 +10,6 @@ import numpy as np import numpy.testing as nt -import unittest from math import pi import math from scipy.linalg import logm, expm @@ -25,7 +24,7 @@ import matplotlib.pyplot as plt -class Test3D(unittest.TestCase): +class Test3D: @pytest.mark.skipif( sys.platform.startswith("darwin") and sys.version_info < (3, 11), reason="tkinter bug with mac", diff --git a/tests/base/test_transformsNd.py b/tests/base/test_transformsNd.py index 0a19ef4e..829a827f 100755 --- a/tests/base/test_transformsNd.py +++ b/tests/base/test_transformsNd.py @@ -10,7 +10,6 @@ import numpy as np import numpy.testing as nt import pytest -import unittest from math import pi import math from scipy.linalg import logm, expm @@ -31,7 +30,7 @@ import matplotlib.pyplot as plt -class TestND(unittest.TestCase): +class TestND: def test_iseye(self): assert iseye(np.eye(1)) assert iseye(np.eye(2)) diff --git a/tests/base/test_vectors.py b/tests/base/test_vectors.py index f8743fb5..b18b5a2a 100755 --- a/tests/base/test_vectors.py +++ b/tests/base/test_vectors.py @@ -10,7 +10,6 @@ import numpy as np import numpy.testing as nt import pytest -import unittest from math import pi import math from scipy.linalg import logm, expm @@ -32,7 +31,7 @@ from math import pi -class TestVector(unittest.TestCase): +class TestVector: @classmethod def tearDownClass(cls): plt.close("all") diff --git a/tests/base/test_velocity.py b/tests/base/test_velocity.py index 78ca0517..65519a16 100644 --- a/tests/base/test_velocity.py +++ b/tests/base/test_velocity.py @@ -10,7 +10,6 @@ import numpy as np import numpy.testing as nt -import unittest from math import pi import math from scipy.linalg import logm, expm @@ -24,7 +23,7 @@ import matplotlib.pyplot as plt -class TestVelocity(unittest.TestCase): +class TestVelocity: def test_numjac(self): # test on algebraic example def f(X): diff --git a/tests/test_dualquaternion.py b/tests/test_dualquaternion.py index c1cda855..2bea5ec6 100644 --- a/tests/test_dualquaternion.py +++ b/tests/test_dualquaternion.py @@ -3,7 +3,6 @@ import numpy as np import numpy.testing as nt -import unittest from spatialmath import DualQuaternion, UnitDualQuaternion, Quaternion, SE3 from spatialmath import base @@ -20,7 +19,7 @@ def qcompare(x, y): y = y.A nt.assert_array_almost_equal(x, y) -class TestDualQuaternion(unittest.TestCase): +class TestDualQuaternion: def test_init(self): @@ -84,7 +83,7 @@ def test_unit(self): pass -class TestUnitDualQuaternion(unittest.TestCase): +class TestUnitDualQuaternion: def test_init(self): diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index 8290f40c..3e95414a 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -9,14 +9,13 @@ from spatialmath.geom2d import * from spatialmath.pose2d import SE2 -import unittest import pytest import sys import numpy.testing as nt import spatialmath.base as smb -class Polygon2Test(unittest.TestCase): +class Polygon2Test: # Primitives def test_constructor1(self): p = Polygon2([(1, 2), (3, 2), (2, 4)]) @@ -109,7 +108,7 @@ def test_edges(self): # p.move(SE2(0, 0, 0.7)) -class Line2Test(unittest.TestCase): +class Line2Test: def test_constructor(self): l = Line2([1, 2, 3]) assert str(l) == "Line2: [1. 2. 3.]" @@ -141,7 +140,7 @@ def test_intersect_segment(self): assert l1.intersect_segment((2, 1), (2, -1)) -class EllipseTest(unittest.TestCase): +class EllipseTest: def test_constructor(self): E = np.array([[1, 1], [1, 3]]) e = Ellipse(E=E) diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 3e9a48fa..2be1e1c0 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -9,14 +9,13 @@ from spatialmath.geom3d import * from spatialmath.pose3d import SE3 -import unittest import numpy.testing as nt import spatialmath.base as base import pytest import sys -class Line3Test(unittest.TestCase): +class Line3Test: # Primitives def test_constructor1(self): # construct from 6-vector diff --git a/tests/test_pose2d.py b/tests/test_pose2d.py index 73858a67..900269e1 100755 --- a/tests/test_pose2d.py +++ b/tests/test_pose2d.py @@ -2,7 +2,6 @@ import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt -import unittest import sys import pytest @@ -32,7 +31,7 @@ def array_compare(x, y): nt.assert_array_almost_equal(x, y) -class TestSO2(unittest.TestCase): +class TestSO2: @classmethod def tearDownClass(cls): plt.close("all") @@ -237,7 +236,7 @@ def test_plot(self): # ============================== SE2 =====================================# -class TestSE2(unittest.TestCase): +class TestSE2: @classmethod def tearDownClass(cls): plt.close("all") diff --git a/tests/test_pose3d.py b/tests/test_pose3d.py index 3088e68a..29c2e589 100755 --- a/tests/test_pose3d.py +++ b/tests/test_pose3d.py @@ -2,7 +2,6 @@ import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt -import unittest import sys import pytest @@ -29,7 +28,7 @@ def array_compare(x, y): nt.assert_array_almost_equal(x, y) -class TestSO3(unittest.TestCase): +class TestSO3: @classmethod def tearDownClass(cls): plt.close("all") @@ -723,7 +722,7 @@ def test_functions_lie(self): # ============================== SE3 =====================================# -class TestSE3(unittest.TestCase): +class TestSE3: @classmethod def tearDownClass(cls): plt.close("all") diff --git a/tests/test_quaternion.py b/tests/test_quaternion.py index d73d1ca3..99a9e570 100644 --- a/tests/test_quaternion.py +++ b/tests/test_quaternion.py @@ -2,7 +2,6 @@ from math import pi import numpy.testing as nt import pytest -import unittest from spatialmath import * from spatialmath.base import * @@ -27,7 +26,7 @@ def qcompare(x, y): # straight port of the MATLAB unit tests -class TestUnitQuaternion(unittest.TestCase): +class TestUnitQuaternion: def test_constructor_variants(self): nt.assert_array_almost_equal(UnitQuaternion().vec, np.r_[1, 0, 0, 0]) @@ -741,7 +740,7 @@ def test_vec3(self): # ry.animate( UnitQuaternion.Rx(pi/2), 'rgb' ) -class TestQuaternion(unittest.TestCase): +class TestQuaternion: def test_constructor(self): q = Quaternion() assert len(q) == 1 diff --git a/tests/test_spatialvector.py b/tests/test_spatialvector.py index 75b5aa9e..be381c72 100644 --- a/tests/test_spatialvector.py +++ b/tests/test_spatialvector.py @@ -1,11 +1,10 @@ -import unittest import numpy.testing as nt import numpy as np from spatialmath.spatialvector import * -class TestSpatialVector(unittest.TestCase): +class TestSpatialVector: def test_list_powers(self): x = SpatialVelocity.Empty() assert len(x) == 0 diff --git a/tests/test_spline.py b/tests/test_spline.py index 1d4277cb..5d49f087 100644 --- a/tests/test_spline.py +++ b/tests/test_spline.py @@ -3,12 +3,11 @@ import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt -import unittest from spatialmath import BSplineSE3, SE3, InterpSplineSE3, SplineFit, SO3 -class TestBSplineSE3(unittest.TestCase): +class TestBSplineSE3: control_poses = [ SE3.Trans([e, 2 * np.cos(e / 2 * np.pi), 2 * np.sin(e / 2 * np.pi)]) * SE3.Ry(e / 8 * np.pi) diff --git a/tests/test_twist.py b/tests/test_twist.py index 35f9acbb..0ac0ad53 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -2,7 +2,6 @@ import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt -import unittest """ we will assume that the primitives rotx,trotx, etc. all work @@ -27,7 +26,7 @@ def array_compare(x, y): nt.assert_array_almost_equal(x, y) -class Twist3dTest(unittest.TestCase): +class Twist3dTest: def test_constructor(self): @@ -194,7 +193,7 @@ def test_prod(self): array_compare( x.prod().SE3(), T1 * T2) -class Twist2dTest(unittest.TestCase): +class Twist2dTest: def test_constructor(self): From eff2eb89c39e90edab83ba6d4013752ab0627786 Mon Sep 17 00:00:00 2001 From: John Barnett Date: Mon, 2 Dec 2024 15:04:29 -0500 Subject: [PATCH 21/21] Rename test classes with _suffix_ Test to use _prefix_ instead, for pytest discovery rules --- tests/test_geom2d.py | 6 +++--- tests/test_geom3d.py | 2 +- tests/test_twist.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_geom2d.py b/tests/test_geom2d.py index 3e95414a..638a98bf 100755 --- a/tests/test_geom2d.py +++ b/tests/test_geom2d.py @@ -15,7 +15,7 @@ import spatialmath.base as smb -class Polygon2Test: +class TestPolygon2: # Primitives def test_constructor1(self): p = Polygon2([(1, 2), (3, 2), (2, 4)]) @@ -108,7 +108,7 @@ def test_edges(self): # p.move(SE2(0, 0, 0.7)) -class Line2Test: +class TestLine2: def test_constructor(self): l = Line2([1, 2, 3]) assert str(l) == "Line2: [1. 2. 3.]" @@ -140,7 +140,7 @@ def test_intersect_segment(self): assert l1.intersect_segment((2, 1), (2, -1)) -class EllipseTest: +class TestEllipse: def test_constructor(self): E = np.array([[1, 1], [1, 3]]) e = Ellipse(E=E) diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 2be1e1c0..61ed2688 100755 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -15,7 +15,7 @@ import sys -class Line3Test: +class TestLine3: # Primitives def test_constructor1(self): # construct from 6-vector diff --git a/tests/test_twist.py b/tests/test_twist.py index 0ac0ad53..48dac575 100755 --- a/tests/test_twist.py +++ b/tests/test_twist.py @@ -26,7 +26,7 @@ def array_compare(x, y): nt.assert_array_almost_equal(x, y) -class Twist3dTest: +class TestTwist3d: def test_constructor(self): @@ -193,7 +193,7 @@ def test_prod(self): array_compare( x.prod().SE3(), T1 * T2) -class Twist2dTest: +class TestTwist2d: def test_constructor(self):