|
3 | 3 | # in this project's top-level directory, and also on-line at:
|
4 | 4 | # https://github.com/ipums/hlink
|
5 | 5 |
|
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
6 | 10 | from hlink.configs.load_config import load_conf_file
|
7 |
| -import os.path |
| 11 | +from hlink.errors import UsageError |
8 | 12 |
|
9 | 13 |
|
10 |
| -def test_load_conf_file_json(conf_dir_path): |
11 |
| - conf_file = os.path.join(conf_dir_path, "test") |
12 |
| - _path, conf = load_conf_file(conf_file) |
| 14 | +@pytest.mark.parametrize("file_name", ["test", "test.json"]) |
| 15 | +def test_load_conf_file_json(conf_dir_path: str, file_name: str) -> None: |
| 16 | + conf_file = Path(conf_dir_path) / file_name |
| 17 | + path, conf = load_conf_file(str(conf_file)) |
13 | 18 | assert conf["id_column"] == "id"
|
| 19 | + assert path == conf_file.with_suffix(".json") |
14 | 20 |
|
15 | 21 |
|
16 |
| -def test_load_conf_file_toml(conf_dir_path): |
17 |
| - conf_file = os.path.join(conf_dir_path, "test1") |
18 |
| - _path, conf = load_conf_file(conf_file) |
| 22 | +@pytest.mark.parametrize("file_name", ["test1", "test1.toml"]) |
| 23 | +def test_load_conf_file_toml(conf_dir_path: str, file_name: str) -> None: |
| 24 | + conf_file = Path(conf_dir_path) / file_name |
| 25 | + path, conf = load_conf_file(str(conf_file)) |
19 | 26 | assert conf["id_column"] == "id-toml"
|
| 27 | + assert path == conf_file.with_suffix(".toml") |
20 | 28 |
|
21 | 29 |
|
22 |
| -def test_load_conf_file_json2(conf_dir_path): |
23 |
| - conf_file = os.path.join(conf_dir_path, "test_conf_flag_run") |
24 |
| - _path, conf = load_conf_file(conf_file) |
| 30 | +def test_load_conf_file_json2(conf_dir_path: str) -> None: |
| 31 | + conf_file = Path(conf_dir_path) / "test_conf_flag_run" |
| 32 | + path, conf = load_conf_file(str(conf_file)) |
25 | 33 | assert conf["id_column"] == "id_conf_flag"
|
| 34 | + assert path == conf_file.with_suffix(".json") |
| 35 | + |
| 36 | + |
| 37 | +def test_load_conf_file_does_not_exist(tmp_path: Path) -> None: |
| 38 | + conf_file = tmp_path / "notthere" |
| 39 | + with pytest.raises( |
| 40 | + FileNotFoundError, match="Couldn't find any of these three files:" |
| 41 | + ): |
| 42 | + load_conf_file(str(conf_file)) |
| 43 | + |
| 44 | + |
| 45 | +def test_load_conf_file_unrecognized_extension(tmp_path: Path) -> None: |
| 46 | + conf_file = tmp_path / "test.yaml" |
| 47 | + conf_file.touch() |
| 48 | + with pytest.raises( |
| 49 | + UsageError, |
| 50 | + match="The file .+ exists, but it doesn't have a '.toml' or '.json' extension", |
| 51 | + ): |
| 52 | + load_conf_file(str(conf_file)) |
0 commit comments