From 9f69218fb3687abe85f45bcde15cc2f68de50709 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:40:36 +0000 Subject: [PATCH] style: pre-commit fixes --- tests/conftest.py | 2 +- tests/llama/conftest.py | 3 +- tests/llama/test_llama_event_decoder.py | 63 +++++++++++++++++------- tests/llama/test_llama_header_decoder.py | 2 +- tests/llama/test_llama_streamer.py | 10 ++-- 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 9104ae0..4292d93 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/llama/conftest.py b/tests/llama/conftest.py index d3fbc2b..0f5e457 100644 --- a/tests/llama/conftest.py +++ b/tests/llama/conftest.py @@ -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") \ No newline at end of file + return lgnd_test_data.get_path("llamaDAQ/20241218-150158-pulser.bin") diff --git a/tests/llama/test_llama_event_decoder.py b/tests/llama/test_llama_event_decoder.py index 024a324..a6bac4a 100644 --- a/tests/llama/test_llama_event_decoder.py +++ b/tests/llama/test_llama_event_decoder.py @@ -1,7 +1,9 @@ -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"} @@ -9,6 +11,7 @@ def test_check_dict_spec_equal(): 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() @@ -16,12 +19,14 @@ def 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 @@ -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 @@ -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 @@ -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 @@ -96,7 +125,3 @@ def test_event_count(open_stream): break assert evt_rbkd[0].loc == 37 assert evt_rbkd[4].loc == 37 - - - - diff --git a/tests/llama/test_llama_header_decoder.py b/tests/llama/test_llama_header_decoder.py index fce819f..2ba8d72 100644 --- a/tests/llama/test_llama_header_decoder.py +++ b/tests/llama/test_llama_header_decoder.py @@ -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) diff --git a/tests/llama/test_llama_streamer.py b/tests/llama/test_llama_streamer.py index 16549a0..eb83192 100644 --- a/tests/llama/test_llama_streamer.py +++ b/tests/llama/test_llama_streamer.py @@ -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() @@ -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() @@ -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() \ No newline at end of file + streamer.close_stream()