Exemple #1
0
 def test_append_restricted_type(self):
     v = TimeSeriesReferenceVectorData(name='a', description='a')
     with self.assertRaisesWith(
             TypeError,
             "TimeSeriesReferenceVectorData.append: incorrect type for "
             "'arg' (got 'float', expected 'TimeSeriesReference')"):
         v.append(2.0)
Exemple #2
0
 def test_get_length1_invalid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with one element and invalid data"""
     temp = TimeSeriesReferenceVectorData()
     value = TimeSeriesReference(
         -1, -1,
         TimeSeries(name='test',
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     temp.append(value)
     # test index slicing
     re = temp[0]
     self.assertTrue(
         isinstance(
             re, TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE))
     self.assertTupleEqual(
         re, TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_NONE_TYPE)
     # test array slicing and list slicing
     selection = [slice(None), [
         0,
     ]]
     for s in selection:
         re = temp[s]
         self.assertTrue(isinstance(re, list))
         self.assertTrue(len(re), 1)
         self.assertTrue(
             isinstance(
                 re[0],
                 TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE))
         self.assertTupleEqual(
             re[0],
             TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_NONE_TYPE)
Exemple #3
0
 def test_add_row_restricted_type(self):
     v = TimeSeriesReferenceVectorData(name='a', description='a')
     with self.assertRaisesWith(
             TypeError,
             "TimeSeriesReferenceVectorData.add_row: incorrect type for "
             "'val' (got 'int', expected 'TimeSeriesReference')"):
         v.add_row(1)
Exemple #4
0
 def test_init(self):
     temp = TimeSeriesReferenceVectorData()
     self.assertEqual(temp.name, 'timeseries')
     self.assertEqual(
         temp.description,
         "Column storing references to a TimeSeries (rows). For each TimeSeries this "
         "VectorData column stores the start_index and count to indicate the range in time "
         "to be selected as well as an object reference to the TimeSeries.")
     self.assertListEqual(temp.data, [])
     temp = TimeSeriesReferenceVectorData(name='test', description='test')
     self.assertEqual(temp.name, 'test')
     self.assertEqual(temp.description, 'test')
Exemple #5
0
 def test_get_length1_valid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with one element and valid data"""
     temp = TimeSeriesReferenceVectorData()
     value = TimeSeriesReference(
         0, 5,
         TimeSeries(name='test',
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     temp.append(value)
     self.assertTupleEqual(temp[0], value)
     self.assertListEqual(temp[:], [
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(*value),
     ])
Exemple #6
0
 def test_get_length5_valid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with 5 elements"""
     temp = TimeSeriesReferenceVectorData()
     num_values = 5
     values = [
         TimeSeriesReference(
             0, 5,
             TimeSeries(name='test' + str(i),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)) for i in range(num_values)
     ]
     for v in values:
         temp.append(v)
     # Test single element selection
     for i in range(num_values):
         # test index slicing
         re = temp[i]
         self.assertTupleEqual(re, values[i])
         # test slicing
         re = temp[i:i + 1]
         self.assertTupleEqual(
             re[0],
             TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
                 *values[i]))
     # Test multi element selection
     re = temp[0:2]
     self.assertTupleEqual(
         re[0],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
             *values[0]))
     self.assertTupleEqual(
         re[1],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
             *values[1]))
Exemple #7
0
 def test_get_length5_with_invalid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with 5 elements"""
     temp = TimeSeriesReferenceVectorData()
     num_values = 5
     values = [
         TimeSeriesReference(
             0, 5,
             TimeSeries(name='test' + str(i + 1),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)) for i in range(num_values - 2)
     ]
     values = ([
         TimeSeriesReference(
             -1, -1,
             TimeSeries(name='test' + str(0),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)),
     ] + values + [
         TimeSeriesReference(
             -1, -1,
             TimeSeries(name='test' + str(5),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)),
     ])
     for v in values:
         temp.append(v)
     # Test single element selection
     for i in range(num_values):
         # test index slicing
         re = temp[i]
         if i in [0, 4]:
             self.assertTrue(
                 isinstance(
                     re, TimeSeriesReferenceVectorData.
                     TIME_SERIES_REFERENCE_TUPLE))
             self.assertTupleEqual(
                 re, TimeSeriesReferenceVectorData.
                 TIME_SERIES_REFERENCE_NONE_TYPE)
         else:
             self.assertTupleEqual(re, values[i])
         # test slicing
         re = temp[i:i + 1]
         if i in [0, 4]:
             self.assertTrue(
                 isinstance(
                     re[0], TimeSeriesReferenceVectorData.
                     TIME_SERIES_REFERENCE_TUPLE))
             self.assertTupleEqual(
                 re[0], TimeSeriesReferenceVectorData.
                 TIME_SERIES_REFERENCE_NONE_TYPE)
         else:
             self.assertTupleEqual(
                 re[0],
                 TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
                     *values[i]))
     # Test multi element selection
     re = temp[0:2]
     self.assertTupleEqual(
         re[0],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_NONE_TYPE)
     self.assertTupleEqual(
         re[1],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
             *values[1]))
Exemple #8
0
 def test_get_empty(self):
     """Get data from an empty TimeSeriesReferenceVectorData"""
     temp = TimeSeriesReferenceVectorData()
     self.assertListEqual(temp[:], [])
     with self.assertRaises(IndexError):
         temp[0]