Skip to content

Commit

Permalink
Formatting and linting commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 10, 2024
1 parent 9431635 commit caff7ad
Showing 1 changed file with 195 additions and 64 deletions.
259 changes: 195 additions & 64 deletions test/rules/test_loq_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]


Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand All @@ -168,62 +165,130 @@ 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)
assert job_request.will_reduce is False


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
assert job_request.additional_values["run_number"] == 0


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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit caff7ad

Please sign in to comment.