|
7 | 7 | from diffpy.labpdfproc.labpdfprocapp import get_args |
8 | 8 | from diffpy.labpdfproc.tools import ( |
9 | 9 | known_sources, |
| 10 | + load_user_info, |
10 | 11 | load_user_metadata, |
11 | 12 | set_input_lists, |
12 | 13 | set_output_directory, |
@@ -241,3 +242,26 @@ def test_load_user_metadata_bad(inputs, msg): |
241 | 242 | actual_args = get_args(cli_inputs) |
242 | 243 | with pytest.raises(ValueError, match=msg[0]): |
243 | 244 | actual_args = load_user_metadata(actual_args) |
| 245 | + |
| 246 | + |
| 247 | +params_user_info = [ |
| 248 | + ([None, None], ["home_username", "home@email.com"]), |
| 249 | + (["cli_username", None], ["cli_username", "home@email.com"]), |
| 250 | + ([None, "cli@email.com"], ["home_username", "cli@email.com"]), |
| 251 | + (["cli_username", "cli@email.com"], ["cli_username", "cli@email.com"]), |
| 252 | +] |
| 253 | + |
| 254 | + |
| 255 | +@pytest.mark.parametrize("inputs, expected", params_user_info) |
| 256 | +def test_load_user_info(monkeypatch, inputs, expected, user_filesystem): |
| 257 | + cwd = Path(user_filesystem) |
| 258 | + home_dir = cwd / "home_dir" |
| 259 | + monkeypatch.setattr("pathlib.Path.home", lambda _: home_dir) |
| 260 | + os.chdir(cwd) |
| 261 | + |
| 262 | + expected_username, expected_email = expected |
| 263 | + cli_inputs = ["2.5", "data.xy", "--username", inputs[0], "--email", inputs[1]] |
| 264 | + actual_args = get_args(cli_inputs) |
| 265 | + actual_args = load_user_info(actual_args) |
| 266 | + assert actual_args.username == expected_username |
| 267 | + assert actual_args.email == expected_email |
0 commit comments