Пример #1
0
 def test_invalid_refspec_dict(self):
     with self.assertRaises(AssertionError):
         DtypeSpec.assertValidDtype({
             'no target':
             'test',  # <-- missing or here bad target key for RefSpec
             'reftype': 'object'
         })
Пример #2
0
 def test_simplify_cpd_type(self):
     compound_type = [
         DtypeSpec('test', 'test field', 'float'),
         DtypeSpec('test2', 'test field2', 'int')
     ]
     expected_result = ['float', 'int']
     result = DtypeHelper.simplify_cpd_type(compound_type)
     self.assertListEqual(result, expected_result)
Пример #3
0
 def test_constructor_table(self):
     dtype1 = DtypeSpec('column1', 'the first column', 'int')
     dtype2 = DtypeSpec('column2', 'the second column', 'float')
     spec = DatasetSpec('my first table', [dtype1, dtype2],
                        name='table1',
                        attributes=self.attributes)
     self.assertEqual(spec['dtype'], [dtype1, dtype2])
     self.assertEqual(spec['name'], 'table1')
     self.assertEqual(spec['doc'], 'my first table')
     self.assertNotIn('linkable', spec)
     self.assertNotIn('data_type_def', spec)
     self.assertListEqual(spec['attributes'], self.attributes)
     self.assertIs(spec, self.attributes[0].parent)
     self.assertIs(spec, self.attributes[1].parent)
     json.dumps(spec)
Пример #4
0
 def test_datatype_table_extension_diff_format(self):
     dtype1 = DtypeSpec('column1', 'the first column', 'int')
     dtype2 = DtypeSpec('column2', 'the second column', 'float64')
     base = DatasetSpec('my first table',
                        [dtype1, dtype2],
                        attributes=self.attributes,
                        data_type_def='SimpleTable')
     self.assertEqual(base['dtype'], [dtype1, dtype2])
     self.assertEqual(base['doc'], 'my first table')
     dtype3 = DtypeSpec('column2', 'the second column, with greater precision', 'int32')
     with self.assertRaisesRegex(ValueError, 'Cannot extend float64 to int32'):
         ext = DatasetSpec('my first table extension',  # noqa: F841
                       [dtype3],
                       data_type_inc=base,
                       data_type_def='ExtendedTable')
Пример #5
0
 def test_datatype_table_extension(self):
     dtype1 = DtypeSpec('column1', 'the first column', 'int')
     dtype2 = DtypeSpec('column2', 'the second column', 'float')
     base = DatasetSpec('my first table', [dtype1, dtype2],
                        attributes=self.attributes,
                        namespace='core',
                        data_type_def='SimpleTable')
     self.assertEqual(base['dtype'], [dtype1, dtype2])
     self.assertEqual(base['doc'], 'my first table')
     dtype3 = DtypeSpec('column3', 'the third column', 'str')
     ext = DatasetSpec('my first table extension', [dtype3],
                       namespace='core',
                       data_type_inc=base,
                       data_type_def='ExtendedTable')
     self.assertEqual(ext['dtype'], [dtype1, dtype2, dtype3])
     self.assertEqual(ext['doc'], 'my first table extension')
Пример #6
0
 def test_datatype_table_extension_higher_precision(self):
     dtype1 = DtypeSpec('column1', 'the first column', 'int')
     dtype2 = DtypeSpec('column2', 'the second column', 'float32')
     base = DatasetSpec('my first table',
                        [dtype1, dtype2],
                        attributes=self.attributes,
                        data_type_def='SimpleTable')
     self.assertEqual(base['dtype'], [dtype1, dtype2])
     self.assertEqual(base['doc'], 'my first table')
     dtype3 = DtypeSpec('column2', 'the second column, with greater precision', 'float64')
     ext = DatasetSpec('my first table extension',
                       [dtype3],
                       data_type_inc=base,
                       data_type_def='ExtendedTable')
     self.assertEqual(ext['dtype'], [dtype1, dtype3])
     self.assertEqual(ext['doc'], 'my first table extension')
Пример #7
0
 def test_constructor_invalid_table(self):
     with self.assertRaises(ValueError):
         DatasetSpec('my first table',
                     [DtypeSpec('column1', 'the first column', 'int'),
                      {}     # <--- Bad compound type spec must raise an error
                      ],
                     name='table1',
                     attributes=self.attributes)
Пример #8
0
 def test_invalid_dtype(self):
     with self.assertRaises(AssertionError):
         DtypeSpec(
             'column1',
             'an example column',
             dtype=
             'bad dtype'  # <-- make sure a bad type string raises an error
         )
Пример #9
0
 def test_build_spec(self):
     spec = DtypeSpec.build_spec({
         'doc': 'an example column',
         'name': 'column1',
         'dtype': 'int'
     })
     self.assertEqual(spec.doc, 'an example column')
     self.assertEqual(spec.name, 'column1')
     self.assertEqual(spec.dtype, 'int')
Пример #10
0
 def test_constructor(self):
     spec = DtypeSpec('column1', 'an example column', 'int')
     self.assertEqual(spec.doc, 'an example column')
     self.assertEqual(spec.name, 'column1')
     self.assertEqual(spec.dtype, 'int')
Пример #11
0
 def test_is_ref(self):
     spec = DtypeSpec('column1', 'an example column',
                      RefSpec('TimeSeries', 'object'))
     self.assertTrue(DtypeSpec.is_ref(spec))
     spec = DtypeSpec('column1', 'an example column', 'int')
     self.assertFalse(DtypeSpec.is_ref(spec))
Пример #12
0
 def test_refspec_dtype(self):
     # just making sure this does not cause an error
     DtypeSpec('column1', 'an example column',
               RefSpec('TimeSeries', 'object'))