Пример #1
0
 def setUpContainer(self):
     containers = [
         Container('container1'),
         Container('container2'),
         Data('data1', [0, 1, 2, 3, 4]),
         Data('data2', [0.0, 1.0, 2.0, 3.0, 4.0]),
     ]
     multi_container = SimpleMultiContainer('multi', containers)
     return multi_container
Пример #2
0
 def test_set_dataio_data_already_set(self):
     """
     Test that Data.set_dataio works as intended
     """
     dataio = DataIO(data=np.arange(30).reshape(5, 2, 3))
     data = np.arange(30).reshape(5, 2, 3)
     container = Data('wrapped_data', data)
     with self.assertRaisesWith(ValueError, "cannot overwrite 'data' on DataIO"):
         container.set_dataio(dataio)
Пример #3
0
 def test_set_dataio(self):
     """
     Test that Data.set_dataio works as intended
     """
     dataio = DataIO()
     data = np.arange(30).reshape(5, 2, 3)
     container = Data('wrapped_data', data)
     container.set_dataio(dataio)
     self.assertIs(dataio.data, data)
     self.assertIs(dataio, container.data)
 def test_init_multi(self):
     """Test that initializing the MCI with no arguments initializes the attribute dict empty."""
     obj1 = Container('obj1')
     data1 = Data('data1', [1, 2, 3])
     foo = Foo(containers=obj1, data=data1)
     self.assertDictEqual(foo.containers, {'obj1': obj1})
     self.assertDictEqual(foo.data, {'data1': data1})
Пример #5
0
 def test_shape_list(self):
     """
     Test that shape works for np.array
     """
     data_obj = Data('my_data', [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]])
     self.assertTupleEqual(data_obj.shape, (2, 5))
Пример #6
0
 def test_shape_nparray(self):
     """
     Test that shape works for np.array
     """
     data_obj = Data('my_data', np.arange(10).reshape(2, 5))
     self.assertTupleEqual(data_obj.shape, (2, 5))
Пример #7
0
 def test_bool_false(self):
     """Test that __bool__ method works correctly on empty data
     """
     data_obj = Data('my_data', [])
     self.assertFalse(data_obj)
Пример #8
0
 def test_bool_true(self):
     """Test that __bool__ method works correctly on data with len
     """
     data_obj = Data('my_data', [1, 2, 3, 4, 5])
     self.assertTrue(data_obj)
Пример #9
0
 def test_constructor_scalar(self):
     """Test that constructor works correctly on scalar data
     """
     data_obj = Data('my_data', 'foobar')
     self.assertEqual(data_obj.data, 'foobar')