Exemple #1
0
 def make_bad_item_types(self):
     items = {"a": []}
     descriptors, file_size = store.pack_items(items)
     num_types = len(store.np_dtype_to_type_map)
     for bad_type in [num_types + 1, 2 * num_types]:
         filename = os.path.join(self.destination_dir,
                                 f"bad_type_{bad_type}.kas")
         with open(filename, "wb") as f:
             descriptors[0].type = bad_type
             store.write_file(f, descriptors, file_size)
Exemple #2
0
 def test_bad_array_packing(self):
     items = {"a": np.arange(100, dtype=np.int8), "b": []}
     descriptors, file_size = store.pack_items(items)
     descriptors[0].array_start += 8
     descriptors[0].array_len -= 8
     with open(self.temp_file, "wb") as f:
         store.write_file(f, descriptors, file_size)
     with self.assertRaises(kas.FileFormatError):
         kas.load(self.temp_file,
                  engine=self.engine,
                  read_all=self.read_all)
Exemple #3
0
 def test_bad_array_non_sequential(self):
     items = {"a": np.arange(100), "b": []}
     for offset in [-1, 1, 2, -8, 8, 100]:
         descriptors, file_size = store.pack_items(items)
         descriptors[1].array_start += offset
         with open(self.temp_file, "wb") as f:
             store.write_file(f, descriptors, file_size)
         self.assertRaises(kas.FileFormatError,
                           kas.load,
                           self.temp_file,
                           engine=self.engine,
                           read_all=self.read_all)
Exemple #4
0
 def test_bad_item_types(self):
     items = {"a": []}
     descriptors, file_size = store.pack_items(items)
     num_types = len(store.np_dtype_to_type_map)
     for bad_type in [num_types + 1, 2 * num_types]:
         with open(self.temp_file, "wb") as f:
             descriptors[0].type = bad_type
             store.write_file(f, descriptors, file_size)
         with self.assertRaises(kas.FileFormatError):
             kas.load(self.temp_file,
                      engine=self.engine,
                      read_all=self.read_all)
Exemple #5
0
 def test_bad_array_initial_offset(self):
     items = {"a": np.arange(100)}
     for offset in [-1, +1, 2, 8, 16, 100]:
         # First key offset must be at header_size + n * (descriptor_size)
         descriptors, file_size = store.pack_items(items)
         descriptors[0].array_start += offset
         with open(self.temp_file, "wb") as f:
             store.write_file(f, descriptors, file_size)
         self.assertRaises(kas.FileFormatError,
                           kas.load,
                           self.temp_file,
                           engine=self.engine,
                           read_all=self.read_all)