Ejemplo n.º 1
0
 def test_04_01_write2_read2(self):
     a = np.random.randint(0, 65535, (64, 64, 64), np.uint16)
     b = np.random.randint(0, 65535, (64, 64, 64), np.uint16)
     with make_files(1) as (dir_file, block_files):
         directory = Directory(1024, 1024, 1024, np.uint16, dir_file,
                               compression=Compression.zstd,
                               block_filenames=block_files)
         directory.create()
         directory.write_block(a, 64, 128, 192)
         directory.write_block(b, 0, 0, 0)
         directory.close()
         directory = Directory.open(dir_file)
         a_out = directory.read_block(64, 128, 192)
         np.testing.assert_array_equal(a, a_out)
         b_out = directory.read_block(0, 0, 0)
         np.testing.assert_array_equal(b, b_out)
Ejemplo n.º 2
0
 def test_05_write_not_there(self):
     a = np.random.randint(0, 65535, (64, 64, 64), np.uint16)
     with make_files(1) as (dir_file, block_files):
         directory = Directory(1024, 1024, 1024, np.uint16, dir_file,
                               compression=Compression.zstd,
                               block_filenames=block_files)
         directory.create()
         directory.write_block(a, 64, 128, 192)
         directory.close()
         a_out = directory.read_block(192, 128, 64)
         np.testing.assert_array_equal(a_out, 0)
     #
     # Test for read in directory beyond EOF
     #
     with make_files(1) as (dir_file, block_files):
         directory = Directory(1024, 1024, 1024, np.uint16, dir_file,
                               compression=Compression.zstd,
                               block_filenames=block_files)
         directory.create()
         directory.write_block(a, 192, 128, 64)
         directory.close()
         a_out = directory.read_block(64, 128, 192)
         np.testing.assert_array_equal(a_out, 0)
Ejemplo n.º 3
0
 def test_case(self):
     src_dir = pathlib.Path(tempfile.mkdtemp())
     dest_dir_parent = pathlib.Path(tempfile.mkdtemp())
     dest_dir = dest_dir_parent / "dest"
     dest_dir.mkdir()
     all_files = []
     rs = np.random.RandomState(1234)
     a = rs.randint(0, 65535, (256, 256, 256), dtype=np.uint16)
     try:
         dir_file = src_dir / "my.blockfs"
         block_files = [src_dir / ("my.blockfs.%d" % i) for i in range(4)]
         directory = Directory(256, 256, 256, np.uint16, str(dir_file),
                               compression=Compression.zstd,
                               block_filenames=
                               [str(_) for _ in block_files])
         directory.create()
         for x, y, z in itertools.product(range(0, 256, 64),
                                          range(0, 256, 64),
                                          range(0, 256, 64)):
             directory.write_block(
                 a[z:z + 64, y:y + 64, x:x + 64], x, y, z)
         directory.close()
         for path in [dir_file] + list(block_files):
             dest_path = dest_dir / path.name
             path.replace(dest_path)
             all_files.append(dest_path)
         dest_directory_file = dest_dir / pathlib.Path(dir_file).name
         main([str(dest_directory_file)])
         directory = Directory.open(str(dest_directory_file))
         for x, y, z in itertools.product(range(0, 256, 64),
                                          range(0, 256, 64),
                                          range(0, 256, 64)):
             np.testing.assert_array_equal(a[z:z+64, y:y+64, x:x+64],
                                           directory.read_block(x, y, z))
     finally:
         try:
             for path in all_files:
                 path.unlink()
             dest_dir.rmdir()
             dest_dir_parent.rmdir()
         except:
             traceback.print_exc()
             print("Failed to remove files")