def _check_formats(self, old_lbpack, new_lbpack, old_bacc=-6, new_bacc=-6, absent_provider=False): lookup_entry = mock.Mock(lbpack=old_lbpack, bacc=old_bacc) provider = mock.Mock(lookup_entry=lookup_entry) if absent_provider: # Replace the provider with a simple array. provider = np.zeros(2) field = Field(list(range(45)), list(range(19)), provider) return field._can_copy_deferred_data(new_lbpack, new_bacc)
def test_large_lookup(self): # Check more space is allocated for the lookups when a lot of blank # lookups are added. src_path = tests.get_data_path(('FF', 'ancillary', 'qrparm.mask')) with self.temp_filename() as temp_path: shutil.copyfile(src_path, temp_path) ffv = FieldsFileVariant(temp_path, FieldsFileVariant.UPDATE_MODE) field = ffv.fields[0] original_field_data = field.get_data() blank_int_headers = field.int_headers.copy() blank_real_headers = field.real_headers.copy() blank_int_headers[:] = -99 # The 'invalid' signature blank_real_headers[:] = 0.0 # Work out how many lookups fills a file 'sector'. lookups_per_sector = ffv._WORDS_PER_SECTOR / field.num_values() # Make a new fields list with many "blank" and one "real" field. n_blank_lookups = 2 * int(np.ceil(lookups_per_sector)) new_fields = [ Field(int_headers=blank_int_headers, real_headers=blank_real_headers, data_provider=None) for _ in range(n_blank_lookups) ] new_fields.append(field) ffv.fields = new_fields ffv.close() ffv = FieldsFileVariant(temp_path) self.assertEqual(len(ffv.fields), n_blank_lookups + 1) # Check that the data of the last ("real") field is correct. field = ffv.fields[-1] self.assertArrayEqual(field.get_data(), original_field_data)
def test_64(self): field = Field(list(range(45)), list(range(19)), None) self.assertEqual(field.num_values(), 64)
def test_not_equal_reals(self): field1 = Field(range(45), range(19), None) field2 = Field(range(45), range(19, 38), None) self.assertFalse(field1.__eq__(field2))
def test_invalid(self): field1 = Field(list(range(45)), list(range(19)), None) self.assertIs(field1.__ne__('foo'), NotImplemented)
def test_equal(self): field1 = Field(range(45), range(19), None) field2 = Field(range(45), range(19), None) self.assertFalse(field1.__ne__(field2))
def test_ndarray(self): data = np.arange(12).reshape(3, 4) field = Field([], [], data) self.assertIs(field.get_data(), data)
def test_ndarray(self): field = Field([], [], None) data = np.arange(12).reshape(3, 4) field.set_data(data) self.assertArrayEqual(field.get_data(), data)
def test_provider(self): provider = mock.Mock(read_data=lambda: mock.sentinel.DATA) field = Field([], [], None) field.set_data(provider) self.assertIs(field.get_data(), mock.sentinel.DATA)
def test_None(self): data = np.arange(12).reshape(3, 4) field = Field([], [], data) field.set_data(None) self.assertIsNone(field.get_data())
def test_None(self): field = Field([], [], None) self.assertIsNone(field.get_data())
def test_128(self): field = Field(list(range(45)), list(range(83)), None) self.assertEqual(field.num_values(), 128)
def test_not_equal_ints(self): field1 = Field(range(45), range(19), None) field2 = Field(range(45, 90), range(19), None) self.assertTrue(field1.__ne__(field2))
def test_not_equal_data(self): field1 = Field(range(45), range(19), None) field2 = Field(range(45), range(19), np.zeros(3)) self.assertFalse(field1.__eq__(field2))
def test_not_equal_ints(self): field1 = Field(list(range(45)), list(range(19)), None) field2 = Field(np.arange(45, 90), np.arange(19), None) self.assertFalse(field1.__eq__(field2))
def test_not_equal_reals(self): field1 = Field(list(range(45)), list(range(19)), None) field2 = Field(np.arange(45), np.arange(19, 38), None) self.assertTrue(field1.__ne__(field2))
def test_invalid(self): field1 = Field(range(45), range(19), None) self.assertIs(field1.__eq__('foo'), NotImplemented)
def test(self): field = Field(list(range(45)), np.arange(19), None) self.assertArrayEqual(field.real_headers, np.arange(19))
def test_equal(self): field1 = Field(list(range(45)), list(range(19)), None) field2 = Field(np.arange(45), np.arange(19), None) self.assertFalse(field1.__ne__(field2))
def test_not_equal_data(self): field1 = Field(list(range(45)), list(range(19)), None) field2 = Field(np.arange(45), np.arange(19), np.zeros(3)) self.assertTrue(field1.__ne__(field2))