|
1 | 1 | from abc import ABCMeta, abstractmethod |
2 | | -from datetime import datetime |
| 2 | +from datetime import datetime, date |
3 | 3 | from unittest import mock, skip |
4 | 4 |
|
5 | 5 | import numpy as np |
@@ -104,46 +104,58 @@ def test_valid(self): |
104 | 104 | class TestDateTimeInSpec(ValidatorTestBase): |
105 | 105 |
|
106 | 106 | def getSpecs(self): |
107 | | - ret = GroupSpec('A test group specification with a data type', |
108 | | - data_type_def='Bar', |
109 | | - datasets=[DatasetSpec('an example dataset', 'int', name='data', |
110 | | - attributes=[AttributeSpec( |
111 | | - 'attr2', 'an example integer attribute', 'int')]), |
112 | | - DatasetSpec('an example time dataset', 'isodatetime', name='time'), |
113 | | - DatasetSpec('an array of times', 'isodatetime', name='time_array', |
114 | | - dims=('num_times',), shape=(None,))], |
115 | | - attributes=[AttributeSpec('attr1', 'an example string attribute', 'text')]) |
116 | | - return (ret,) |
| 107 | + ret = GroupSpec( |
| 108 | + 'A test group specification with a data type', |
| 109 | + data_type_def='Bar', |
| 110 | + datasets=[ |
| 111 | + DatasetSpec( |
| 112 | + 'an example dataset', |
| 113 | + 'int', |
| 114 | + name='data', |
| 115 | + attributes=[AttributeSpec('attr2', 'an example integer attribute', 'int')] |
| 116 | + ), |
| 117 | + DatasetSpec('an example time dataset', 'isodatetime', name='datetime'), |
| 118 | + DatasetSpec('an example time dataset', 'isodatetime', name='date', quantity='?'), |
| 119 | + DatasetSpec('an array of times', 'isodatetime', name='time_array', dims=('num_times',), shape=(None,)) |
| 120 | + ], |
| 121 | + attributes=[AttributeSpec('attr1', 'an example string attribute', 'text')]) |
| 122 | + return ret, |
117 | 123 |
|
118 | 124 | def test_valid_isodatetime(self): |
119 | | - builder = GroupBuilder('my_bar', |
120 | | - attributes={'data_type': 'Bar', 'attr1': 'a string attribute'}, |
121 | | - datasets=[DatasetBuilder('data', 100, attributes={'attr2': 10}), |
122 | | - DatasetBuilder('time', |
123 | | - datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())), |
124 | | - DatasetBuilder('time_array', |
125 | | - [datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())])]) |
| 125 | + builder = GroupBuilder( |
| 126 | + 'my_bar', |
| 127 | + attributes={'data_type': 'Bar', 'attr1': 'a string attribute'}, |
| 128 | + datasets=[ |
| 129 | + DatasetBuilder('data', 100, attributes={'attr2': 10}), |
| 130 | + DatasetBuilder('datetime', datetime(2017, 5, 1, 12, 0, 0)), |
| 131 | + DatasetBuilder('date', date(2017, 5, 1)), |
| 132 | + DatasetBuilder('time_array', [datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())]) |
| 133 | + ] |
| 134 | + ) |
126 | 135 | validator = self.vmap.get_validator('Bar') |
127 | 136 | result = validator.validate(builder) |
128 | 137 | self.assertEqual(len(result), 0) |
129 | 138 |
|
130 | 139 | def test_invalid_isodatetime(self): |
131 | | - builder = GroupBuilder('my_bar', |
132 | | - attributes={'data_type': 'Bar', 'attr1': 'a string attribute'}, |
133 | | - datasets=[DatasetBuilder('data', 100, attributes={'attr2': 10}), |
134 | | - DatasetBuilder('time', 100), |
135 | | - DatasetBuilder('time_array', |
136 | | - [datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())])]) |
| 140 | + builder = GroupBuilder( |
| 141 | + 'my_bar', |
| 142 | + attributes={'data_type': 'Bar', 'attr1': 'a string attribute'}, |
| 143 | + datasets=[ |
| 144 | + DatasetBuilder('data', 100, attributes={'attr2': 10}), |
| 145 | + DatasetBuilder('datetime', 100), |
| 146 | + DatasetBuilder('time_array', [datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())]) |
| 147 | + ] |
| 148 | + ) |
137 | 149 | validator = self.vmap.get_validator('Bar') |
138 | 150 | result = validator.validate(builder) |
139 | 151 | self.assertEqual(len(result), 1) |
140 | | - self.assertValidationError(result[0], DtypeError, name='Bar/time') |
| 152 | + self.assertValidationError(result[0], DtypeError, name='Bar/datetime') |
141 | 153 |
|
142 | 154 | def test_invalid_isodatetime_array(self): |
143 | 155 | builder = GroupBuilder('my_bar', |
144 | 156 | attributes={'data_type': 'Bar', 'attr1': 'a string attribute'}, |
145 | 157 | datasets=[DatasetBuilder('data', 100, attributes={'attr2': 10}), |
146 | | - DatasetBuilder('time', |
| 158 | + DatasetBuilder('datetime', |
147 | 159 | datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())), |
148 | 160 | DatasetBuilder('time_array', |
149 | 161 | datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()))]) |
|
0 commit comments