From caff7ada75e5fd726bec9ef5d222873b49417c20 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 10 Oct 2024 10:28:50 +0000 Subject: [PATCH] Formatting and linting commit --- test/rules/test_loq_rules.py | 259 ++++++++++++++++++++++++++--------- 1 file changed, 195 insertions(+), 64 deletions(-) diff --git a/test/rules/test_loq_rules.py b/test/rules/test_loq_rules.py index c9cb8db..84a1d8a 100644 --- a/test/rules/test_loq_rules.py +++ b/test/rules/test_loq_rules.py @@ -30,7 +30,7 @@ SansFileData(title="{Banana}", type="TRANS", run_number="1"), SansFileData(title="{Apple}", type="SANS/TRANS", run_number="2"), SansFileData(title="{Apple}", type="TRANS", run_number="3"), - SansFileData(title="{direct beam}", type="TRANS", run_number="4") + SansFileData(title="{direct beam}", type="TRANS", run_number="4"), ] @@ -107,10 +107,7 @@ def test_is_can_transmission_file(sans_file, can_title, result): @pytest.mark.parametrize( ("sans_files", "sample_title", "expected"), - [ - (SANS_FILES, "{Apple}", SANS_FILES[4]), - (SANS_FILES, "{Banana}", SANS_FILES[2]) - ], + [(SANS_FILES, "{Apple}", SANS_FILES[4]), (SANS_FILES, "{Banana}", SANS_FILES[2])], ) def test_find_trans_file_success(sans_files, sample_title, expected): assert _find_trans_file(sans_files, sample_title) == expected @@ -136,14 +133,14 @@ def test_path_for_run_number_with_some_zeros(): tempdir = tempfile.mkdtemp() path = f"{tempdir}/LOQ0012345.nxs" with Path(path).open("a"): - assert find_path_for_run_number(tempdir, 12345) == Path(path) + assert find_path_for_run_number(tempdir, 12345) == Path(path) def test_path_for_run_number_with_no_zeros(): tempdir = tempfile.mkdtemp() path = f"{tempdir}/LOQ12345.nxs" with Path(path).open("a"): - assert find_path_for_run_number(tempdir, 12345) == Path(path) + assert find_path_for_run_number(tempdir, 12345) == Path(path) def test_path_for_run_number_too_many_zeros(): @@ -168,34 +165,68 @@ def test_strip_excess_files(): files = [ SansFileData(title="", type="", run_number="0"), SansFileData(title="", type="", run_number="1"), - SansFileData(title="", type="", run_number="2") + SansFileData(title="", type="", run_number="2"), ] new_list = strip_excess_files(files, 1) - assert new_list == [ - SansFileData(title="", type="", run_number="0") - ] + assert new_list == [SansFileData(title="", type="", run_number="0")] def test_loq_find_files_verify_title_too_long(): - job_request = JobRequest(run_number=0, instrument="", experiment_title="too_long_problems_here", experiment_number="", - filepath=Path(), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) + job_request = JobRequest( + run_number=0, + instrument="", + experiment_title="too_long_problems_here", + experiment_number="", + filepath=Path(), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) LoqFindFiles(value=True).verify(job_request) assert job_request.will_reduce is False def test_loq_find_files_verify_title_too_short(): - job_request = JobRequest(run_number=0, instrument="", experiment_title="tooshortproblemshere", experiment_number="", - filepath=Path(), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) + job_request = JobRequest( + run_number=0, + instrument="", + experiment_title="tooshortproblemshere", + experiment_number="", + filepath=Path(), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) LoqFindFiles(value=True).verify(job_request) assert job_request.will_reduce is False def test_loq_find_files_verify_no_files_left(): - job_request = JobRequest(run_number=0, instrument="", experiment_title="{}_{}_sans/trans", experiment_number="", - filepath=Path(), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) + job_request = JobRequest( + run_number=0, + instrument="", + experiment_title="{}_{}_sans/trans", + experiment_number="", + filepath=Path(), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) with mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[]): loq_find_files = LoqFindFiles(value=True) loq_find_files.verify(job_request) @@ -203,12 +234,28 @@ def test_loq_find_files_verify_no_files_left(): def test_loq_find_files_verify_some_files_found_but_none_valid(): - job_request = JobRequest(run_number=0, instrument="", experiment_title="{}_{}_sans/trans", experiment_number="", - filepath=Path("/path/cycle_24_2/LOQ.nxs"), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) - with (mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), - mock.patch("rundetection.rules.loq_rules.strip_excess_files", - return_value=[SansFileData("", "", ""), SansFileData("", "", ""), SansFileData("", "", "")])): + job_request = JobRequest( + run_number=0, + instrument="", + experiment_title="{}_{}_sans/trans", + experiment_number="", + filepath=Path("/path/cycle_24_2/LOQ.nxs"), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) + with ( + mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), + mock.patch( + "rundetection.rules.loq_rules.strip_excess_files", + return_value=[SansFileData("", "", ""), SansFileData("", "", ""), SansFileData("", "", "")], + ), + ): loq_find_files = LoqFindFiles(value=True) loq_find_files.verify(job_request) assert job_request.will_reduce is True @@ -216,14 +263,32 @@ def test_loq_find_files_verify_some_files_found_but_none_valid(): def test_loq_find_files_trans_file_found(): - job_request = JobRequest(run_number=5, instrument="", experiment_title="{scatter}_{background}_sans/trans", experiment_number="", - filepath=Path("/path/cycle_24_2/LOQ.nxs"), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) - with (mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), - mock.patch("rundetection.rules.loq_rules.strip_excess_files", - return_value=[SansFileData(title="{scatter}", type="TRANS", run_number="1"), - SansFileData(title="{background}", type="TRANS", run_number="2"), - SansFileData(title="{direct}", type="SANS/TRANS", run_number="3")])): + job_request = JobRequest( + run_number=5, + instrument="", + experiment_title="{scatter}_{background}_sans/trans", + experiment_number="", + filepath=Path("/path/cycle_24_2/LOQ.nxs"), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) + with ( + mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), + mock.patch( + "rundetection.rules.loq_rules.strip_excess_files", + return_value=[ + SansFileData(title="{scatter}", type="TRANS", run_number="1"), + SansFileData(title="{background}", type="TRANS", run_number="2"), + SansFileData(title="{direct}", type="SANS/TRANS", run_number="3"), + ], + ), + ): loq_find_files = LoqFindFiles(value=True) loq_find_files.verify(job_request) assert job_request.will_reduce is True @@ -232,15 +297,33 @@ def test_loq_find_files_trans_file_found(): def test_loq_find_files_can_transmission_file_found(): - job_request = JobRequest(run_number=5, instrument="", experiment_title="{scatter}_{background}_sans/trans", experiment_number="", - filepath=Path("/path/cycle_24_2/LOQ.nxs"), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) - with (mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), - mock.patch("rundetection.rules.loq_rules.strip_excess_files", - return_value=[SansFileData(title="{scatter}", type="TRANS", run_number="1"), - SansFileData(title="{background}", type="SANS/TRANS", run_number="2"), - SansFileData(title="{background}", type="TRANS", run_number="3"), - SansFileData(title="{direct}", type="SANS/TRANS", run_number="4")])): + job_request = JobRequest( + run_number=5, + instrument="", + experiment_title="{scatter}_{background}_sans/trans", + experiment_number="", + filepath=Path("/path/cycle_24_2/LOQ.nxs"), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) + with ( + mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), + mock.patch( + "rundetection.rules.loq_rules.strip_excess_files", + return_value=[ + SansFileData(title="{scatter}", type="TRANS", run_number="1"), + SansFileData(title="{background}", type="SANS/TRANS", run_number="2"), + SansFileData(title="{background}", type="TRANS", run_number="3"), + SansFileData(title="{direct}", type="SANS/TRANS", run_number="4"), + ], + ), + ): loq_find_files = LoqFindFiles(value=True) loq_find_files.verify(job_request) assert job_request.will_reduce is True @@ -249,15 +332,33 @@ def test_loq_find_files_can_transmission_file_found(): def test_loq_find_files_direct_file_found(): - job_request = JobRequest(run_number=5, instrument="", experiment_title="{scatter}_{background}_sans/trans", experiment_number="", - filepath=Path("/path/cycle_24_2/LOQ.nxs"), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) - with (mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), - mock.patch("rundetection.rules.loq_rules.strip_excess_files", - return_value=[SansFileData(title="{scatter}", type="TRANS", run_number="1"), - SansFileData(title="{background}", type="SANS/TRANS", run_number="2"), - SansFileData(title="{background}", type="TRANS", run_number="3"), - SansFileData(title="{direct}", type="TRANS", run_number="4")])): + job_request = JobRequest( + run_number=5, + instrument="", + experiment_title="{scatter}_{background}_sans/trans", + experiment_number="", + filepath=Path("/path/cycle_24_2/LOQ.nxs"), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) + with ( + mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), + mock.patch( + "rundetection.rules.loq_rules.strip_excess_files", + return_value=[ + SansFileData(title="{scatter}", type="TRANS", run_number="1"), + SansFileData(title="{background}", type="SANS/TRANS", run_number="2"), + SansFileData(title="{background}", type="TRANS", run_number="3"), + SansFileData(title="{direct}", type="TRANS", run_number="4"), + ], + ), + ): loq_find_files = LoqFindFiles(value=True) loq_find_files.verify(job_request) assert job_request.will_reduce is True @@ -267,15 +368,33 @@ def test_loq_find_files_direct_file_found(): def test_loq_find_files_can_scatter_file_found(): - job_request = JobRequest(run_number=5, instrument="", experiment_title="{scatter}_{background}_sans/trans", experiment_number="", - filepath=Path("/path/cycle_24_2/LOQ.nxs"), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) - with (mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), - mock.patch("rundetection.rules.loq_rules.strip_excess_files", - return_value=[SansFileData(title="{scatter}", type="TRANS", run_number="1"), - SansFileData(title="{background}", type="SANS/TRANS", run_number="2"), - SansFileData(title="{background}", type="TRANS", run_number="3"), - SansFileData(title="{direct}", type="SANS/TRANS", run_number="4")])): + job_request = JobRequest( + run_number=5, + instrument="", + experiment_title="{scatter}_{background}_sans/trans", + experiment_number="", + filepath=Path("/path/cycle_24_2/LOQ.nxs"), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) + with ( + mock.patch("rundetection.rules.loq_rules.create_list_of_files", return_value=[SansFileData("", "", "")]), + mock.patch( + "rundetection.rules.loq_rules.strip_excess_files", + return_value=[ + SansFileData(title="{scatter}", type="TRANS", run_number="1"), + SansFileData(title="{background}", type="SANS/TRANS", run_number="2"), + SansFileData(title="{background}", type="TRANS", run_number="3"), + SansFileData(title="{direct}", type="SANS/TRANS", run_number="4"), + ], + ), + ): loq_find_files = LoqFindFiles(value=True) loq_find_files.verify(job_request) assert job_request.will_reduce is True @@ -284,9 +403,21 @@ def test_loq_find_files_can_scatter_file_found(): def test_loq_user_file_(): - job_request = JobRequest(run_number=0, instrument="", experiment_title="", experiment_number="", - filepath=Path(), run_start="", run_end="", raw_frames=0, good_frames=0, users="", - will_reduce=True, additional_values={}, additional_requests=[]) + job_request = JobRequest( + run_number=0, + instrument="", + experiment_title="", + experiment_number="", + filepath=Path(), + run_start="", + run_end="", + raw_frames=0, + good_frames=0, + users="", + will_reduce=True, + additional_values={}, + additional_requests=[], + ) LoqUserFile(value="loq_user_file").verify(job_request) assert job_request.additional_values["user_file"] == "/extras/loq/loq_user_file" assert len(job_request.additional_values) == 1