Skip to content

Commit

Permalink
Merge pull request #79 from ziatdinovmax/master
Browse files Browse the repository at this point in the history
Add more tests for Dimension class
  • Loading branch information
ssomnath authored Oct 9, 2020
2 parents 52ee406 + 299147b commit c6e4776
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions tests/sid/test_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import sys
import unittest
import warnings

import numpy as np
from numpy.testing import assert_array_equal
Expand Down Expand Up @@ -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))
Expand All @@ -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")
Expand Down Expand Up @@ -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))

0 comments on commit c6e4776

Please sign in to comment.