def setUp(self): BaseTestIO.setUp(self) filename = get_test_file_full_path( ioclass=NestIO, filename='0gid-1time-2Vm-3gex-4gin-1260-0.dat', directory=self.local_test_dir, clean=False) self.testIO = ColumnIO(filename=filename)
class TestColumnIO(BaseTestIO, unittest.TestCase): ioclass = NestIO files_to_download = ['0gid-1time-2Vm-3gex-4gin-1260-0.dat'] def setUp(self): BaseTestIO.setUp(self) filename = get_test_file_full_path( ioclass=NestIO, filename='0gid-1time-2Vm-3gex-4gin-1260-0.dat', directory=self.local_test_dir, clean=False) self.testIO = ColumnIO(filename=filename) def test_no_arguments(self): """ Test if data can be read using the default keyword arguments. """ columns = self.testIO.get_columns() expected = self.testIO.data np.testing.assert_array_equal(columns, expected) def test_single_column_id(self): """ Test if the column_ids keywords works properly. """ column = self.testIO.get_columns(column_ids=1) expected = self.testIO.data[:, [1]] np.testing.assert_array_equal(column, expected) def test_multiple_column_ids(self): """ Test if multiple columns can be read at the same time. """ columns = self.testIO.get_columns(column_ids=range(2)) expected = self.testIO.data[:, [0, 1]] np.testing.assert_array_equal(columns, expected) def test_no_condition(self): """ Test if a missing condition function leads to a warning """ with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") self.testIO.get_columns(condition_column=0) # Verify number and content of warning assert len(w) == 1 assert "no condition" in str(w[-1].message) def test_no_condition_column(self): """ Test if a missing condition column leads to an error """ with self.assertRaises(ValueError) as context: self.testIO.get_columns(condition=lambda x: True) self.assertTrue('no condition_column ID provided' in str(context.exception)) def test_correct_condition_selection(self): """ Test if combination of condition function and condition_column works properly. """ condition_column = 0 def condition_function(x): return x > 10 result = self.testIO.get_columns(condition=condition_function, condition_column=0) selected_ids = np.where(condition_function(self.testIO.data[:, condition_column]))[0] expected = self.testIO.data[selected_ids, :] np.testing.assert_array_equal(result, expected) assert all(condition_function(result[:, condition_column])) def test_sorting(self): """ Test if presorting of columns work properly. """ result = self.testIO.get_columns(sorting_columns=0) assert len(result) > 0 assert all(np.diff(result[:, 0]) >= 0)
class TestColumnIO(BaseTestIO, unittest.TestCase): ioclass = NestIO def setUp(self): BaseTestIO.setUp(self) filename = get_test_file_full_path( ioclass=NestIO, filename='0gid-1time-2Vm-3gex-4gin-1260-0.dat', directory=self.local_test_dir, clean=False) self.testIO = ColumnIO(filename=filename) def test_no_arguments(self): """ Test if data can be read using the default keyword arguments. """ columns = self.testIO.get_columns() expected = self.testIO.data np.testing.assert_array_equal(columns, expected) def test_single_column_id(self): """ Test if the column_ids keywords works properly. """ column = self.testIO.get_columns(column_ids=1) expected = self.testIO.data[:, [1]] np.testing.assert_array_equal(column, expected) def test_multiple_column_ids(self): """ Test if multiple columns can be read at the same time. """ columns = self.testIO.get_columns(column_ids=range(2)) expected = self.testIO.data[:, [0, 1]] np.testing.assert_array_equal(columns, expected) def test_no_condition(self): """ Test if a missing condition function leads to a warning """ with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") self.testIO.get_columns(condition_column=0) # Verify number and content of warning assert len(w) == 1 assert "no condition" in str(w[-1].message) def test_no_condition_column(self): """ Test if a missing condition column leads to an error """ with self.assertRaises(ValueError) as context: self.testIO.get_columns(condition=lambda x: True) self.assertTrue('no condition_column ID provided' in str(context.exception)) def test_correct_condition_selection(self): """ Test if combination of condition function and condition_column works properly. """ condition_column = 0 condition_function = lambda x: x > 10 result = self.testIO.get_columns(condition=condition_function, condition_column=0) selected_ids = np.where(condition_function(self.testIO.data[:, condition_column]))[0] expected = self.testIO.data[selected_ids, :] np.testing.assert_array_equal(result, expected) assert all(condition_function(result[:, condition_column])) def test_sorting(self): """ Test if presorting of columns work properly. """ result = self.testIO.get_columns(sorting_columns=0) assert len(result) > 0 assert all(np.diff(result[:, 0]) >= 0)
def setUp(self): BaseTestIO.setUp(self) filename = self.get_local_path( 'nest/0gid-1time-2Vm-3gex-4gin-1260-0.dat') self.testIO = ColumnIO(filename=filename)