-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start adding tests for orca fc (#16)
* avoid error when running tests that don't use the tmpdir * add option to return hexdump output as list of strings * add tests of orca_packet.py * add ability to load packets by index * add start of tests for orca fc decoding * check packet counting function * keep packet_id aligned with loc * switch to new file and add some more tests * fix last-packet check * start to add status packet tests * eliminate unneccessary build_raw warnings (do late eval) * add missing include * style: pre-commit fixes * fixes for flake8 and dox --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a564e3f
commit 18eb650
Showing
6 changed files
with
223 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
|
||
from daq2lh5.orca import orca_packet | ||
|
||
|
||
@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 | ||
orca_stream.close_stream() # avoid warning that file is still open | ||
return packets | ||
|
||
|
||
def test_orfc_config_decoding(orca_stream, fc_packets): | ||
config_packet = fc_packets[0] | ||
assert config_packet is not None | ||
|
||
data_id = orca_packet.get_data_id(config_packet) | ||
name = orca_stream.header.get_id_to_decoder_name_dict()[data_id] | ||
assert name == "ORFlashCamListenerConfigDecoder" | ||
|
||
|
||
def test_orfc_status_decoding(orca_stream, fc_packets): | ||
status_packet = fc_packets[1] | ||
assert status_packet is not None | ||
|
||
data_id = orca_packet.get_data_id(status_packet) | ||
name = orca_stream.header.get_id_to_decoder_name_dict()[data_id] | ||
assert name == "ORFlashCamListenerStatusDecoder" | ||
|
||
|
||
def test_orfc_waveform_decoding(orca_stream, fc_packets): | ||
wf_packet = fc_packets[2] | ||
assert wf_packet is not None | ||
|
||
data_id = orca_packet.get_data_id(wf_packet) | ||
name = orca_stream.header.get_id_to_decoder_name_dict()[data_id] | ||
assert name == "ORFlashCamWaveformDecoder" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,41 @@ | ||
def test_orca_packet_import(): | ||
pass | ||
from daq2lh5.orca import orca_packet | ||
|
||
|
||
def test_orca_packet_funcs(orca_stream): | ||
# The values in this test are particular to the test orca file in | ||
# legend-testdata and may need to be changed if that file is changed | ||
|
||
assert orca_stream.count_packets() == 911 | ||
|
||
packet = orca_stream.load_packet() | ||
assert orca_packet.is_short(packet) is 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" | ||
|
||
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 | ||
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) | ||
expected = [ | ||
"OrcaHeaderDecoder", | ||
"ORRunDecoderForRun", | ||
"ORFlashCamListenerConfigDecoder", | ||
"ORFlashCamListenerStatusDecoder", | ||
"ORFlashCamWaveformDecoder", | ||
] | ||
assert seen == expected | ||
|
||
orca_stream.close_stream() # avoid warning that file is still open |