Skip to content

Commit 8610920

Browse files
author
David Erb
committed
allows other stuff to be put on visit name after underscore
1 parent 079b7a5 commit 8610920

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/dls_utilpack/visit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def get_visit_year(beamline, visit):
3838
def get_xchem_subdirectory(visit):
3939

4040
# This is the pattern all visits must have.
41-
pattern = r"^([a-z][a-z][0-9][0-9][0-9][0-9][0-9])[-]([0-9]+)$"
41+
pattern = r"^([a-z][a-z][0-9][0-9][0-9][0-9][0-9])[-]([0-9]+)([_].*)?$"
4242

4343
match = re.search(pattern, visit)
4444

4545
if not match:
46-
raise RuntimeError(
46+
raise ValueError(
4747
f'the visit name "{visit}" does not conform to the visit naming convention'
4848
)
4949

tests/test_visit.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,28 @@ async def _main_coroutine(
2929
# Check valid visits.
3030
assert get_xchem_subdirectory("aa12345-1") == "aa12345/aa12345-1"
3131
assert get_xchem_subdirectory("aa12345-1234") == "aa12345/aa12345-1234"
32+
assert get_xchem_subdirectory("aa12345-1234_") == "aa12345/aa12345-1234"
33+
assert (
34+
get_xchem_subdirectory("aa12345-1234_some stuff") == "aa12345/aa12345-1234"
35+
)
3236

3337
# Check invalid visit formats.
34-
with pytest.raises(RuntimeError) as excinfo:
38+
with pytest.raises(ValueError) as excinfo:
3539
get_xchem_subdirectory("aa12345")
3640
assert "convention" in str(excinfo.value)
3741

38-
with pytest.raises(RuntimeError) as excinfo:
42+
with pytest.raises(ValueError) as excinfo:
3943
get_xchem_subdirectory("a12345-1")
4044
assert "convention" in str(excinfo.value)
4145

42-
with pytest.raises(RuntimeError) as excinfo:
46+
with pytest.raises(ValueError) as excinfo:
4347
get_xchem_subdirectory("[aa12345-1]")
4448
assert "convention" in str(excinfo.value)
4549

50+
with pytest.raises(ValueError) as excinfo:
51+
get_xchem_subdirectory("aa12345-1-somestuff")
52+
assert "convention" in str(excinfo.value)
53+
4654
# Check good directory.
4755
parent = Path(output_directory) / "processing/lab36"
4856
full_path = parent / "aa12345/aa12345-1"

0 commit comments

Comments
 (0)