Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start adding tests for orca fc #16

Merged
merged 18 commits into from
Oct 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style: pre-commit fixes
  • Loading branch information
pre-commit-ci[bot] committed Oct 19, 2023
commit ab79de46b399a8ca980fbea9a75b4cdfea12a402
4 changes: 2 additions & 2 deletions src/daq2lh5/orca/orca_streamer.py
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ def build_packet_locs(self, saveloc=True) -> None:
pid = self.packet_id
if len(self.packet_locs) > 0:
self.in_stream.seek(self.packet_locs[-1])
self.packet_id = len(self.packet_locs)-2
self.packet_id = len(self.packet_locs) - 2
while self.skip_packet():
pass # builds the rest of the packet_locs list
if saveloc:
@@ -162,7 +162,7 @@ def load_packet(
if self.skip_packet() == False:
return None
self.in_stream.seek(self.packet_locs[index])
self.packet_id = index-1
self.packet_id = index - 1

# load packet header
pkt_hdr = self.load_packet_header()
13 changes: 6 additions & 7 deletions tests/orca/test_orca_fc.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest



@pytest.fixture(scope="module")
def fc_packets(orca_stream):
packets = []
packets.append(orca_stream.load_packet(3).copy()) # config
packets.append(orca_stream.load_packet(4).copy()) # status
packets.append(orca_stream.load_packet(13).copy()) # waveform
packets.append(orca_stream.load_packet(3).copy()) # config
packets.append(orca_stream.load_packet(4).copy()) # status
packets.append(orca_stream.load_packet(13).copy()) # waveform
orca_stream.close_stream() # avoid warning that file is still open
return packets

@@ -18,7 +17,7 @@ def test_orfc_config_decoding(orca_stream, fc_packets):

data_id = orca_packet.get_data_id(config_packet)
name = orca_stream.header.get_id_to_decoder_name_dict()[data_id]
assert name == 'ORFlashCamListenerConfigDecoder'
assert name == "ORFlashCamListenerConfigDecoder"


def test_orfc_status_decoding(orca_stream, fc_packets):
@@ -27,7 +26,7 @@ def test_orfc_status_decoding(orca_stream, fc_packets):

data_id = orca_packet.get_data_id(status_packet)
name = orca_stream.header.get_id_to_decoder_name_dict()[data_id]
assert name == 'ORFlashCamListenerStatusDecoder'
assert name == "ORFlashCamListenerStatusDecoder"


def test_orfc_waveform_decoding(orca_stream, fc_packets):
@@ -36,4 +35,4 @@ def test_orfc_waveform_decoding(orca_stream, fc_packets):

data_id = orca_packet.get_data_id(wf_packet)
name = orca_stream.header.get_id_to_decoder_name_dict()[data_id]
assert name == 'ORFlashCamWaveformDecoder'
assert name == "ORFlashCamWaveformDecoder"
29 changes: 17 additions & 12 deletions tests/orca/test_orca_packet.py
Original file line number Diff line number Diff line change
@@ -11,25 +11,30 @@ def test_orca_packet_funcs(orca_stream):
assert orca_packet.is_short(packet) == False
assert orca_packet.get_data_id(packet) == 3
assert orca_packet.get_n_words(packet) == 4
assert orca_packet.hex_dump(packet, return_output=True)[-1] == '3 0x63c1977a'
assert orca_packet.hex_dump(packet, return_output=True)[-1] == "3 0x63c1977a"

id_dict = orca_stream.header.get_id_to_decoder_name_dict()
seen = []
for ii in range(100):
packet = orca_stream.load_packet(ii)
if packet is None: break
if packet is None:
break
name = id_dict[orca_packet.get_data_id(packet)]
#if ii < 20: print(ii, name)
if ii == 0: assert name == 'OrcaHeaderDecoder'
if ii == 1: assert name == 'ORRunDecoderForRun'
if ii == 910: assert name == 'ORRunDecoderForRun'
if name not in seen: seen.append(name)
# if ii < 20: print(ii, name)
if ii == 0:
assert name == "OrcaHeaderDecoder"
if ii == 1:
assert name == "ORRunDecoderForRun"
if ii == 910:
assert name == "ORRunDecoderForRun"
if name not in seen:
seen.append(name)
expected = [
'OrcaHeaderDecoder',
'ORRunDecoderForRun',
'ORFlashCamListenerConfigDecoder',
'ORFlashCamListenerStatusDecoder',
'ORFlashCamWaveformDecoder'
"OrcaHeaderDecoder",
"ORRunDecoderForRun",
"ORFlashCamListenerConfigDecoder",
"ORFlashCamListenerStatusDecoder",
"ORFlashCamWaveformDecoder",
]
assert seen == expected