Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jan 8, 2025
1 parent f45aa76 commit 9f69218
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def pytest_sessionfinish(session, exitstatus):
@pytest.fixture(scope="session")
def lgnd_test_data():
ldata = LegendTestData()
#ldata.checkout("ecb370e")
# ldata.checkout("ecb370e")
return ldata


Expand Down
3 changes: 1 addition & 2 deletions tests/llama/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fcutils
import pytest


# lgnd_test_data (LegendTestData) from fixture in root conftest.py
@pytest.fixture(scope="module")
def test_data_path(lgnd_test_data):
return lgnd_test_data.get_path("llamaDAQ/20241218-150158-pulser.bin")
return lgnd_test_data.get_path("llamaDAQ/20241218-150158-pulser.bin")
63 changes: 44 additions & 19 deletions tests/llama/test_llama_event_decoder.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
from daq2lh5.llama.llama_streamer import LLAMAStreamer
from daq2lh5.llama.llama_event_decoder import LLAMAEventDecoder, check_dict_spec_equal
import pytest
import lgdo
import pytest

from daq2lh5.llama.llama_event_decoder import LLAMAEventDecoder, check_dict_spec_equal
from daq2lh5.llama.llama_streamer import LLAMAStreamer


def test_check_dict_spec_equal():
d1 = {"X": "1", "Y": "2", "Z": "3"}
d2 = {"X": "2", "Y": "2", "Z": "3"}
assert check_dict_spec_equal(d1, d2, ["Y", "Z"])
assert not check_dict_spec_equal(d1, d2, ["X", "Y"])


@pytest.fixture(scope="module")
def open_stream(test_data_path):
streamer = LLAMAStreamer()
streamer.open_stream(test_data_path)
yield streamer
streamer.close_stream()


def test_get_key_lists(open_stream):
evt_dec : LLAMAEventDecoder = open_stream.event_decoder
assert evt_dec.get_key_lists() == [[0],[4]]
evt_dec: LLAMAEventDecoder = open_stream.event_decoder
assert evt_dec.get_key_lists() == [[0], [4]]


def test_get_decoded_values(open_stream):
evt_dec : LLAMAEventDecoder = open_stream.event_decoder
evt_dec: LLAMAEventDecoder = open_stream.event_decoder
dec_vals_0 = evt_dec.get_decoded_values(0)
assert dec_vals_0["waveform"]["wf_len"] == 2000
assert dec_vals_0["avgwaveform"]["wf_len"] == 10000
Expand All @@ -40,7 +45,7 @@ def test_first_packet(open_stream):
assert isinstance(tbl, lgdo.Table)
ii = evt_rbkd[0].loc
assert ii == 1
ii = ii - 1 # use the last written entry (which is the only one, actually)
ii = ii - 1 # use the last written entry (which is the only one, actually)
assert tbl["fch_id"].nda[ii] == 0
assert tbl["packet_id"].nda[ii] == 1
assert tbl["timestamp"].nda[ii] == 757530
Expand All @@ -55,10 +60,22 @@ def test_first_packet(open_stream):
assert tbl["accSum6"].nda[ii] == 7826
assert tbl["accSum7"].nda[ii] == 7826
assert tbl["accSum8"].nda[ii] == 7826
assert tbl["waveform"]["dt"].nda[ii] > 3.999 and tbl["waveform"]["dt"].nda[ii] < 4.001
assert tbl["avgwaveform"]["dt"].nda[ii] > 15.999 and tbl["avgwaveform"]["dt"].nda[ii] < 16.001
assert tbl["waveform"]["t0"].nda[ii] > -4000.1 and tbl["waveform"]["t0"].nda[ii] < -3999.9
assert tbl["avgwaveform"]["t0"].nda[ii] > -8000.1 and tbl["avgwaveform"]["t0"].nda[ii] < -7999.9
assert (
tbl["waveform"]["dt"].nda[ii] > 3.999 and tbl["waveform"]["dt"].nda[ii] < 4.001
)
assert (
tbl["avgwaveform"]["dt"].nda[ii] > 15.999
and tbl["avgwaveform"]["dt"].nda[ii] < 16.001
)
assert (
tbl["waveform"]["t0"].nda[ii] > -4000.1
and tbl["waveform"]["t0"].nda[ii] < -3999.9
)
assert (
tbl["avgwaveform"]["t0"].nda[ii] > -8000.1
and tbl["avgwaveform"]["t0"].nda[ii] < -7999.9
)


def test_first_packet_ch4(open_stream):
evt_rbkd = open_stream.event_rbkd
Expand All @@ -83,10 +100,22 @@ def test_first_packet_ch4(open_stream):
assert tbl["accSum6"].nda[ii] == 7912
assert tbl["accSum7"].nda[ii] == 7912
assert tbl["accSum8"].nda[ii] == 7912
assert tbl["waveform"]["dt"].nda[ii] > 3.999 and tbl["waveform"]["dt"].nda[ii] < 4.001
assert tbl["avgwaveform"]["dt"].nda[ii] > 31.999 and tbl["avgwaveform"]["dt"].nda[ii] < 32.001
assert tbl["waveform"]["t0"].nda[ii] > -4000.1 and tbl["waveform"]["t0"].nda[ii] < -3999.9
assert tbl["avgwaveform"]["t0"].nda[ii] > -4000.1 and tbl["avgwaveform"]["t0"].nda[ii] < -3999.9
assert (
tbl["waveform"]["dt"].nda[ii] > 3.999 and tbl["waveform"]["dt"].nda[ii] < 4.001
)
assert (
tbl["avgwaveform"]["dt"].nda[ii] > 31.999
and tbl["avgwaveform"]["dt"].nda[ii] < 32.001
)
assert (
tbl["waveform"]["t0"].nda[ii] > -4000.1
and tbl["waveform"]["t0"].nda[ii] < -3999.9
)
assert (
tbl["avgwaveform"]["t0"].nda[ii] > -4000.1
and tbl["avgwaveform"]["t0"].nda[ii] < -3999.9
)


def test_event_count(open_stream):
evt_rbkd = open_stream.event_rbkd
Expand All @@ -96,7 +125,3 @@ def test_event_count(open_stream):
break
assert evt_rbkd[0].loc == 37
assert evt_rbkd[4].loc == 37




2 changes: 1 addition & 1 deletion tests/llama/test_llama_header_decoder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from daq2lh5.llama.llama_header_decoder import LLAMAHeaderDecoder
from daq2lh5.llama.llama_streamer import LLAMAStreamer


def test_read_header(test_data_path):
streamer = LLAMAStreamer()
streamer.open_stream(test_data_path)
Expand Down
10 changes: 6 additions & 4 deletions tests/llama/test_llama_streamer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from daq2lh5.llama.llama_streamer import LLAMAStreamer
from daq2lh5.llama.llama_header_decoder import LLAMAHeaderDecoder
from daq2lh5.llama.llama_event_decoder import LLAMAEventDecoder
from daq2lh5.llama.llama_header_decoder import LLAMAHeaderDecoder
from daq2lh5.llama.llama_streamer import LLAMAStreamer
from daq2lh5.raw_buffer import RawBuffer


def test_get_decoder_list():
streamer = LLAMAStreamer()
assert len(streamer.get_decoder_list()) == 2
assert isinstance(streamer.get_decoder_list()[0], LLAMAHeaderDecoder)
assert isinstance(streamer.get_decoder_list()[1], LLAMAEventDecoder)


# test_data_path (str) from fixture in ./conftest.py
def test_open_stream(test_data_path):
streamer = LLAMAStreamer()
Expand All @@ -18,7 +20,7 @@ def test_open_stream(test_data_path):
assert streamer.rb_lib is not None
nbytes_hdr = streamer.n_bytes_read
assert nbytes_hdr > 0
assert streamer.read_packet() # there has to be at last a single good packet
assert streamer.read_packet() # there has to be at last a single good packet
assert streamer.packet_id == 1
assert streamer.n_bytes_read > nbytes_hdr
streamer.close_stream()
Expand All @@ -31,4 +33,4 @@ def test_open_stream_multiple(test_data_path):
streamer.close_stream()
rbl: list[RawBuffer] = streamer.open_stream(test_data_path)
assert len(rbl) == 1
streamer.close_stream()
streamer.close_stream()

0 comments on commit 9f69218

Please sign in to comment.