Esempio n. 1
0
def test_read_write_sweepstreamarray():
    with TempDirectory() as directory:
        io = npy.NumpyDirectory(directory.path)
        original = utilities.fake_sweep_stream_array()
        name = 'sweep_stream_array'
        io.write(original, name)
        assert original == io.read(name)
Esempio n. 2
0
def test_read_write_sweepstreamarray():
    with TempDirectory() as directory:
        filename = 'test.nc'
        io = nc.NCFile(os.path.join(directory.path, filename))
        original = utilities.fake_sweep_stream_array()
        name = 'sweep_stream_array'
        io.write(original, name)
        assert original == io.read(name)
Esempio n. 3
0
def test_read_write_sweepstreamarray():
    with TempDirectory() as directory:
        filename = 'test.nc'
        io = nc.NCFile(os.path.join(directory.path, filename))
        original = utilities.fake_sweep_stream_array()
        name = 'sweep_stream_array'
        io.write(original, name)
        assert original == io.read(name)
Esempio n. 4
0
def test_sweep_stream_array_node_path():
    original = utilities.fake_sweep_stream_array()
    # The current node path reflects the existing structure, while the IO node path is None until a read or write.
    assert original.current_node_path == '/'
    assert original.io_node_path is None
    assert original.sweep_array.current_node_path == '/sweep_array'
    assert original.sweep_array.io_node_path is None
    assert original.sweep_array.stream_arrays.current_node_path == '/sweep_array/stream_arrays'
    assert original.sweep_array.stream_arrays.io_node_path is None
    assert original.sweep_array.stream_arrays[
        0].current_node_path == '/sweep_array/stream_arrays/0'
    assert original.sweep_array.stream_arrays[0].io_node_path is None
    # Write the tree to disk.
    io = memory.Dictionary()
    name = 'ssa'
    io.write(original, name)
    # The current node path is unchanged, while the IO node path reflects how it has been stored to disk.
    assert original.current_node_path == '/'
    assert original.io_node_path == '/ssa'
    assert original.sweep_array.current_node_path == '/sweep_array'
    assert original.sweep_array.io_node_path == '/ssa/sweep_array'
    assert original.sweep_array.stream_arrays.current_node_path == '/sweep_array/stream_arrays'
    assert original.sweep_array.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert original.sweep_array.stream_arrays[
        0].current_node_path == '/sweep_array/stream_arrays/0'
    assert original.sweep_array.stream_arrays[
        0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    # The IO node path should be the same regardless of how much of the tree was loaded, while the current node path
    # depends on the actual measurement structure that exists.
    ssa = io.read(name)
    assert ssa.current_node_path == '/'
    assert ssa._io_node_path == '/ssa'
    assert ssa.sweep_array.current_node_path == '/sweep_array'
    assert ssa.sweep_array.io_node_path == '/ssa/sweep_array'
    assert ssa.sweep_array.stream_arrays.current_node_path == '/sweep_array/stream_arrays'
    assert ssa.sweep_array.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert ssa.sweep_array.stream_arrays[
        0].current_node_path == '/sweep_array/stream_arrays/0'
    assert ssa.sweep_array.stream_arrays[
        0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    sweep_array = io.read(core.join(name, 'sweep_array'))
    assert sweep_array.current_node_path == '/'
    assert sweep_array._io_node_path == '/ssa/sweep_array'
    assert sweep_array.stream_arrays.current_node_path == '/stream_arrays'
    assert sweep_array.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert sweep_array.stream_arrays[0].current_node_path == '/stream_arrays/0'
    assert sweep_array.stream_arrays[
        0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    stream_arrays = io.read(core.join(name, 'sweep_array', 'stream_arrays'))
    assert stream_arrays.current_node_path == '/'
    assert stream_arrays._io_node_path == '/ssa/sweep_array/stream_arrays'
    assert stream_arrays[0].current_node_path == '/0'
    assert stream_arrays[0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    stream_array_0 = io.read(
        core.join(name, 'sweep_array', 'stream_arrays', '0'))
    assert stream_array_0.current_node_path == '/'
    assert stream_array_0._io_node_path == '/ssa/sweep_array/stream_arrays/0'
    # Add the tree to a new measurement:
    m = core.Measurement()
    moved = ssa.sweep_array
    m.moved = moved
    # The IO node path is unchanged, while the current node path now reflects that the sweep array was last added to
    # the new measurement with the name 'moved'.
    assert ssa.current_node_path == '/'
    assert ssa._io_node_path == '/ssa'
    assert moved.current_node_path == '/moved'
    assert moved.io_node_path == '/ssa/sweep_array'
    assert moved.stream_arrays.current_node_path == '/moved/stream_arrays'
    assert moved.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert moved.stream_arrays[0].current_node_path == '/moved/stream_arrays/0'
    assert moved.stream_arrays[
        0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
Esempio n. 5
0
def test_sweep_stream_array_node_path():
    original = utilities.fake_sweep_stream_array()
    # The current node path reflects the existing structure, while the IO node path is None until a read or write.
    assert original.current_node_path == '/'
    assert original.io_node_path is None
    assert original.sweep_array.current_node_path == '/sweep_array'
    assert original.sweep_array.io_node_path is None
    assert original.sweep_array.stream_arrays.current_node_path == '/sweep_array/stream_arrays'
    assert original.sweep_array.stream_arrays.io_node_path is None
    assert original.sweep_array.stream_arrays[0].current_node_path == '/sweep_array/stream_arrays/0'
    assert original.sweep_array.stream_arrays[0].io_node_path is None
    # Write the tree to disk.
    io = memory.Dictionary()
    name = 'ssa'
    io.write(original, name)
    # The current node path is unchanged, while the IO node path reflects how it has been stored to disk.
    assert original.current_node_path == '/'
    assert original.io_node_path == '/ssa'
    assert original.sweep_array.current_node_path == '/sweep_array'
    assert original.sweep_array.io_node_path == '/ssa/sweep_array'
    assert original.sweep_array.stream_arrays.current_node_path == '/sweep_array/stream_arrays'
    assert original.sweep_array.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert original.sweep_array.stream_arrays[0].current_node_path == '/sweep_array/stream_arrays/0'
    assert original.sweep_array.stream_arrays[0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    # The IO node path should be the same regardless of how much of the tree was loaded, while the current node path
    # depends on the actual measurement structure that exists.
    ssa = io.read(name)
    assert ssa.current_node_path == '/'
    assert ssa._io_node_path == '/ssa'
    assert ssa.sweep_array.current_node_path == '/sweep_array'
    assert ssa.sweep_array.io_node_path == '/ssa/sweep_array'
    assert ssa.sweep_array.stream_arrays.current_node_path == '/sweep_array/stream_arrays'
    assert ssa.sweep_array.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert ssa.sweep_array.stream_arrays[0].current_node_path == '/sweep_array/stream_arrays/0'
    assert ssa.sweep_array.stream_arrays[0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    sweep_array = io.read(core.join(name, 'sweep_array'))
    assert sweep_array.current_node_path == '/'
    assert sweep_array._io_node_path == '/ssa/sweep_array'
    assert sweep_array.stream_arrays.current_node_path == '/stream_arrays'
    assert sweep_array.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert sweep_array.stream_arrays[0].current_node_path == '/stream_arrays/0'
    assert sweep_array.stream_arrays[0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    stream_arrays = io.read(core.join(name, 'sweep_array', 'stream_arrays'))
    assert stream_arrays.current_node_path == '/'
    assert stream_arrays._io_node_path == '/ssa/sweep_array/stream_arrays'
    assert stream_arrays[0].current_node_path == '/0'
    assert stream_arrays[0].io_node_path == '/ssa/sweep_array/stream_arrays/0'
    stream_array_0 = io.read(core.join(name, 'sweep_array', 'stream_arrays', '0'))
    assert stream_array_0.current_node_path == '/'
    assert stream_array_0._io_node_path == '/ssa/sweep_array/stream_arrays/0'
    # Add the tree to a new measurement:
    m = core.Measurement()
    moved = ssa.sweep_array
    m.moved = moved
    # The IO node path is unchanged, while the current node path now reflects that the sweep array was last added to
    # the new measurement with the name 'moved'.
    assert ssa.current_node_path == '/'
    assert ssa._io_node_path == '/ssa'
    assert moved.current_node_path == '/moved'
    assert moved.io_node_path == '/ssa/sweep_array'
    assert moved.stream_arrays.current_node_path == '/moved/stream_arrays'
    assert moved.stream_arrays.io_node_path == '/ssa/sweep_array/stream_arrays'
    assert moved.stream_arrays[0].current_node_path == '/moved/stream_arrays/0'
    assert moved.stream_arrays[0].io_node_path == '/ssa/sweep_array/stream_arrays/0'