示例#1
0
 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)
示例#2
0
 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)
示例#3
0
    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)
示例#4
0
 def test_64(self):
     field = Field(list(range(45)), list(range(19)), None)
     self.assertEqual(field.num_values(), 64)
示例#5
0
 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))
示例#6
0
 def test_invalid(self):
     field1 = Field(list(range(45)), list(range(19)), None)
     self.assertIs(field1.__ne__('foo'), NotImplemented)
示例#7
0
 def test_equal(self):
     field1 = Field(range(45), range(19), None)
     field2 = Field(range(45), range(19), None)
     self.assertFalse(field1.__ne__(field2))
示例#8
0
 def test_invalid(self):
     field1 = Field(list(range(45)), list(range(19)), None)
     self.assertIs(field1.__ne__('foo'), NotImplemented)
示例#9
0
 def test_ndarray(self):
     data = np.arange(12).reshape(3, 4)
     field = Field([], [], data)
     self.assertIs(field.get_data(), data)
示例#10
0
 def test_ndarray(self):
     field = Field([], [], None)
     data = np.arange(12).reshape(3, 4)
     field.set_data(data)
     self.assertArrayEqual(field.get_data(), data)
示例#11
0
 def test_ndarray(self):
     field = Field([], [], None)
     data = np.arange(12).reshape(3, 4)
     field.set_data(data)
     self.assertArrayEqual(field.get_data(), data)
示例#12
0
 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)
示例#13
0
 def test_ndarray(self):
     data = np.arange(12).reshape(3, 4)
     field = Field([], [], data)
     self.assertIs(field.get_data(), data)
示例#14
0
 def test_None(self):
     data = np.arange(12).reshape(3, 4)
     field = Field([], [], data)
     field.set_data(None)
     self.assertIsNone(field.get_data())
示例#15
0
 def test_None(self):
     field = Field([], [], None)
     self.assertIsNone(field.get_data())
示例#16
0
 def test_128(self):
     field = Field(list(range(45)), list(range(83)), None)
     self.assertEqual(field.num_values(), 128)
示例#17
0
 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))
示例#18
0
 def test_128(self):
     field = Field(list(range(45)), list(range(83)), None)
     self.assertEqual(field.num_values(), 128)
示例#19
0
 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))
示例#20
0
 def test_None(self):
     field = Field([], [], None)
     self.assertIsNone(field.get_data())
示例#21
0
 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))
示例#22
0
 def test_None(self):
     data = np.arange(12).reshape(3, 4)
     field = Field([], [], data)
     field.set_data(None)
     self.assertIsNone(field.get_data())
示例#23
0
 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))
示例#24
0
 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)
示例#25
0
 def test_invalid(self):
     field1 = Field(range(45), range(19), None)
     self.assertIs(field1.__eq__('foo'), NotImplemented)
示例#26
0
 def test(self):
     field = Field(list(range(45)), np.arange(19), None)
     self.assertArrayEqual(field.real_headers, np.arange(19))
示例#27
0
 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))
示例#28
0
 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))
示例#29
0
 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))
示例#30
0
 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))
示例#31
0
 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))
示例#32
0
 def test_64(self):
     field = Field(list(range(45)), list(range(19)), None)
     self.assertEqual(field.num_values(), 64)
示例#33
0
 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))