Ejemplo n.º 1
0
def test_import_and_open():
    from protozfits import rawzfits
    from protozfits import L0_pb2

    relative_test_file_path = os.path.relpath(example_file_path)
    rawzfits.ProtobufIFits(
        fname=relative_test_file_path,
        tablename="Events"
    )
Ejemplo n.º 2
0
def test_rawreader_can_iterate():
    from protozfits import rawzfits
    from protozfits import L0_pb2

    ifits = rawzfits.ProtobufIFits(
        fname=example_file_path,
        tablename="Events"
    )
    for i in range(ifits.num_rows()):
        event = L0_pb2.CameraEvent()
        event.ParseFromString(ifits.read_event())
Ejemplo n.º 3
0
def test_import_open_read_and_parse():
    from protozfits import rawzfits
    from protozfits import L0_pb2

    relative_test_file_path = os.path.relpath(example_file_path)
    ifits = rawzfits.ProtobufIFits(
        fname=relative_test_file_path,
        tablename="Events"
    )
    raw = ifits.read_event()

    event = L0_pb2.CameraEvent()
    event.ParseFromString(raw)
Ejemplo n.º 4
0
def test_ProtobufIFits_read_a_given_event():
    from protozfits import rawzfits
    from protozfits import L0_pb2

    ifits = rawzfits.ProtobufIFits(
        fname=example_file_path,
        tablename="Events"
    )

    for random_id in [7, 1, 10, 2]:
        event = L0_pb2.CameraEvent()
        event.ParseFromString(ifits.read_a_given_event(random_id))
        assert event.eventNumber == FIRST_EVENT_NUMBER + random_id - 1
Ejemplo n.º 5
0
def test_rawreader_can_work_with_absolute_path():
    from protozfits import rawzfits
    from protozfits import L0_pb2

    ifits = rawzfits.ProtobufIFits(
        fname=example_file_path,
        tablename="Events"
    )
    assert ifits.num_rows() == EVENTS_IN_EXAMPLE_FILE

    raw = ifits.read_event()

    event = L0_pb2.CameraEvent()
    event.ParseFromString(raw)
Ejemplo n.º 6
0
def test_examplefile_has_no_runheader():
    from protozfits import rawzfits
    from protozfits import L0_pb2

    with pytest.raises(RuntimeError):
        ifits = rawzfits.ProtobufIFits(
            fname=example_file_path,
            tablename="RunHeader"
        )
        assert ifits.num_rows() == EVENTS_IN_EXAMPLE_FILE

        raw = ifits.read_event()
        assert raw < 0

        header = L0_pb2.CameraRunHeader()
        with pytest.raises(TypeError):
            header.ParseFromString(raw)
Ejemplo n.º 7
0
def test_no_crash_when_iterating_too_far():
    from protozfits import rawzfits
    from protozfits import L0_pb2

    ifits = rawzfits.ProtobufIFits(
        fname=example_file_path,
        tablename="Events"
    )
    for i in range(ifits.num_rows()):
        event = L0_pb2.CameraEvent()
        event.ParseFromString(ifits.read_event())

    # At this point we iterated through the entire file.
    # In version 0.43 we got a crash (seg fault or so) when iterating too
    # far. This test should ensure this behaviour is fixed in 0.44

    with pytest.raises(StopIteration):
        ifits.read_event()