diff --git a/tests/sid/test_dimension.py b/tests/sid/test_dimension.py index 4f737caf..a188610f 100644 --- a/tests/sid/test_dimension.py +++ b/tests/sid/test_dimension.py @@ -9,6 +9,7 @@ import sys import unittest +import warnings import numpy as np from numpy.testing import assert_array_equal @@ -73,21 +74,27 @@ def test_repr(self): expected = '{}: {} ({}) of size {}'.format(name, quantity, units, values.shape) self.assertEqual(actual, expected) - def test_equality(self): - name = 'Bias' + def test_inequality_req_inputs(self): + name = 'X' + quantity = "Length" + units = 'nm' - dim_1 = Dimension([0, 1, 2, 3, 4], name) - dim_2 = Dimension(np.arange(5, dtype=np.float32), name) - self.assertEqual(dim_1, dim_2) - self.assertTrue(np.allclose(dim_1.values, dim_2.values)) + self.assertTrue(Dimension(5, name) == Dimension(5, name)) + self.assertFalse(Dimension(5, 'Y') == Dimension(5, name)) + self.assertFalse(Dimension(4, name) == Dimension(5, name)) - def test_inequality_req_inputs(self): - name = 'Bias' + self.assertTrue( + Dimension(5, units=units) == Dimension(5, units=units)) + self.assertFalse( + Dimension(5, units='pm') == Dimension(5, units=units)) - self.assertTrue(Dimension([0, 1, 2, 3], name) == Dimension([0, 1, 2, 3], name)) - self.assertFalse(Dimension([0, 1, 2, 3], 'fdfd') == Dimension([0, 1, 2, 3], name)) + self.assertTrue( + Dimension(5, quantity=quantity) == Dimension(5, quantity=quantity)) + self.assertFalse( + Dimension(5, quantity='Bias') == Dimension(5, quantity=quantity)) - self.assertFalse(Dimension([0, 1, 2], name)== Dimension([0, 1, 2, 3], name)) + self.assertFalse( + Dimension(np.arange(5)) == Dimension(np.arange(5) + 1)) def test_dimensionality(self): vals = np.ones((2, 2)) @@ -96,10 +103,14 @@ def test_dimensionality(self): _ = Dimension(vals, "x",) self.assertTrue(expected in str(context.exception)) + def test_info(self): + expected = "X - Bias (mV): [0. 1. 2. 3. 4.]" + dim = Dimension(np.arange(5), "X", "Bias", "mV") + self.assertTrue(dim.info, expected) + def test_nonposint_values(self): - vals = [-1, .5] - expected = ["values should at least be specified as a positive integer", - "len() of unsized object"] + vals = [-1, []] + expected = 2*["values should at least be specified as a positive integer"] for v, e in zip(vals, expected): with self.assertRaises(TypeError) as context: _ = Dimension(v, "x") @@ -128,5 +139,11 @@ def test_dimension_type(self): self.assertEqual(dim.dimension_type.value, dv) self.assertEqual(dim.dimension_type.name, dn) -if __name__ == '__main__': - unittest.main() + def test_unknown_dimension_type(self): + dim_type = "bad_name" + expected_wrn = ["Supported dimension types for plotting are only: [", + "Setting DimensionType to UNKNOWN"] + with warnings.catch_warnings(record=True) as w: + _ = Dimension(5, "x", dimension_type=dim_type) + self.assertTrue(expected_wrn[0] in str(w[0].message)) + self.assertTrue(expected_wrn[1] in str(w[1].message))