|
| 1 | +import logging |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from dls_utilpack.visit import get_xchem_directory, get_xchem_subdirectory |
| 7 | + |
| 8 | +# Base class for the tester. |
| 9 | +from tests.base_tester import BaseTester |
| 10 | + |
| 11 | +logger = logging.getLogger(__name__) |
| 12 | + |
| 13 | + |
| 14 | +# ---------------------------------------------------------------------------------------- |
| 15 | +class TestVisit(BaseTester): |
| 16 | + def test(self, constants, logging_setup, output_directory): |
| 17 | + """ """ |
| 18 | + |
| 19 | + self.main(constants, output_directory) |
| 20 | + |
| 21 | + # ---------------------------------------------------------------------------------------- |
| 22 | + async def _main_coroutine( |
| 23 | + self, |
| 24 | + constants, |
| 25 | + output_directory, |
| 26 | + ): |
| 27 | + """ """ |
| 28 | + |
| 29 | + # Check valid visits. |
| 30 | + assert get_xchem_subdirectory("aa12345-1") == "aa12345/aa12345-1" |
| 31 | + assert get_xchem_subdirectory("aa12345-1234") == "aa12345/aa12345-1234" |
| 32 | + |
| 33 | + # Check invalid visit formats. |
| 34 | + with pytest.raises(RuntimeError) as excinfo: |
| 35 | + get_xchem_subdirectory("aa12345") |
| 36 | + assert "convention" in str(excinfo.value) |
| 37 | + |
| 38 | + with pytest.raises(RuntimeError) as excinfo: |
| 39 | + get_xchem_subdirectory("a12345-1") |
| 40 | + assert "convention" in str(excinfo.value) |
| 41 | + |
| 42 | + with pytest.raises(RuntimeError) as excinfo: |
| 43 | + get_xchem_subdirectory("[aa12345-1]") |
| 44 | + assert "convention" in str(excinfo.value) |
| 45 | + |
| 46 | + # Check good directory. |
| 47 | + parent = Path(output_directory) / "processing/lab36" |
| 48 | + full_path = parent / "aa12345/aa12345-1" |
| 49 | + full_path.mkdir(parents=True, exist_ok=True) |
| 50 | + |
| 51 | + assert get_xchem_directory(str(parent), "aa12345-1") == str(full_path) |
| 52 | + |
| 53 | + # Check invalid directory. |
| 54 | + with pytest.raises(RuntimeError) as excinfo: |
| 55 | + get_xchem_directory("something", "aa12345-1") |
| 56 | + assert "does not exist" in str(excinfo.value) |
0 commit comments