44
55import logging
66import shutil
7- from collections .abc import Callable , Generator
87from pathlib import Path
98from typing import TYPE_CHECKING
109
1514import atomate2 .lobster .run
1615
1716if TYPE_CHECKING :
18- from collections .abc import Sequence
17+ from collections .abc import Callable , Generator , Sequence
1918
2019logger = logging .getLogger ("atomate2" )
2120
2625
2726
2827@pytest .fixture (scope = "session" )
29- def lobster_test_dir (test_dir ) -> Path :
28+ def lobster_test_dir (test_dir : str | Path ) -> Path :
3029 """Fixture to provide the test directory for LOBSTER tests.
3130
3231 Args:
@@ -36,7 +35,7 @@ def lobster_test_dir(test_dir) -> Path:
3635 -------
3736 Path: The test directory for LOBSTER tests.
3837 """
39- return test_dir / "lobster"
38+ return Path ( test_dir ) / "lobster"
4039
4140
4241def monkeypatch_lobster (
@@ -52,34 +51,54 @@ def monkeypatch_lobster(
5251 It replaces calls to run_lobster with a mock function that copies reference files
5352 instead of running LOBSTER.
5453
55- The primary idea is that instead of running LOBSTER to generate the output files,
56- reference files will be copied into the directory instead. This ensures that the
57- calculation inputs are generated correctly and that the outputs are parsed properly.
54+ The primary idea is that instead of running LOBSTER to
55+ generate the output files, reference files will be copied
56+ into the directory instead. This ensures that the calculation
57+ inputs are generated correctly and that the outputs are
58+ parsed properly.
5859
5960 To use the fixture successfully, follow these steps:
60- 1. Include "mock_lobster" as an argument to any test that would like to use its functionality.
61- 2. For each job in your workflow, prepare a reference directory containing two folders:
62- "inputs" (containing the reference input files expected to be produced by
63- Lobsterin.standard_calculations_from_vasp_files) and "outputs" (containing the expected
64- output files to be produced by run_lobster). These files should reside in a subdirectory
61+ 1. Include "mock_lobster" as an argument to any test that
62+ would like to use its functionality.
63+ 2. For each job in your workflow, prepare a reference
64+ directory containing two folders:
65+ "inputs" (containing the reference input files expected
66+ to be produced by Lobsterin.standard_calculations_from_vasp_files)
67+ and "outputs" (containing the expected
68+ output files to be produced by run_lobster).
69+ These files should reside in a subdirectory
6570 of "tests/test_data/lobster".
66- 3. Create a dictionary mapping each job name to its reference directory. Note that you should
67- supply the reference directory relative to the "tests/test_data/lobster" folder. For example,
68- if your calculation has one job named "lobster_run_0" and the reference files are present in
69- "tests/test_data/lobster/Si_lobster_run_0", the dictionary would look like:
71+ 3. Create a dictionary mapping each job name
72+ to its reference directory. Note that you should
73+ supply the reference directory relative
74+ to the "tests/test_data/lobster" folder. For example,
75+ if your calculation has one job named
76+ "lobster_run_0" and the reference files are present in
77+ "tests/test_data/lobster/Si_lobster_run_0",
78+ the dictionary would look like:
7079 {"lobster_run_0": "Si_lobster_run_0"}.
71- 4. Optionally, create a dictionary mapping each job name to custom keyword arguments that will be
72- supplied to fake_run_lobster. This way you can configure which lobsterin settings are expected
73- for each job. For example, if your calculation has one job named "lobster_run_0" and you wish
74- to validate that "basisfunctions" is set correctly in the lobsterin, your dictionary would look like:
75- {"lobster_run_0": {"lobsterin_settings": {"basisfunctions": Ba 5p 5s 6s}}.
76- 5. Inside the test function, call `mock_lobster(ref_paths, fake_lobster_kwargs)`, where ref_paths is the
77- dictionary created in step 3 and fake_lobster_kwargs is the dictionary created in step 4.
80+ 4. Optionally, create a dictionary mapping each
81+ job name to custom keyword arguments that will be
82+ supplied to fake_run_lobster. This way you can
83+ configure which lobsterin settings are expected
84+ for each job. For example, if your calculation
85+ has one job named "lobster_run_0" and you wish
86+ to validate that "basisfunctions" is set correctly
87+ in the lobsterin, your dictionary would look like:
88+ {"lobster_run_0": {"lobsterin_settings":
89+ {"basisfunctions": Ba 5p 5s 6s}}.
90+ 5. Inside the test function, call
91+ `mock_lobster(ref_paths, fake_lobster_kwargs)`,
92+ where ref_paths is the
93+ dictionary created in step 3 and
94+ fake_lobster_kwargs is the dictionary created in step 4.
7895 6. Run your LOBSTER job after calling `mock_lobster`.
7996
8097 Args:
81- monkeypatch (pytest.MonkeyPatch): The pytest monkeypatch fixture.
82- lobster_test_dir (Path): The directory containing reference files for LOBSTER tests.
98+ monkeypatch (pytest.MonkeyPatch):
99+ The pytest monkeypatch fixture.
100+ lobster_test_dir (Path):
101+ The directory containing reference files for LOBSTER tests.
83102 """
84103
85104 def mock_run_lobster (* _args , ** _kwargs ) -> None :
@@ -110,7 +129,7 @@ def fake_run_lobster(
110129 check_lobster_inputs : Sequence [str ] = _LFILES ,
111130 check_dft_inputs : Sequence [str ] = _DFT_FILES ,
112131 lobsterin_settings : Sequence [str ] = (),
113- ):
132+ ) -> None :
114133 """
115134 Emulate running LOBSTER and validate LOBSTER input files.
116135
0 commit comments