|
6 | 6 | from littlepay.config import (
|
7 | 7 | DEFAULT_CONFIG,
|
8 | 8 | DEFAULT_CREDENTIALS,
|
| 9 | + _ensure_current_exists, |
9 | 10 | _get_current_path,
|
10 | 11 | _read_config,
|
11 | 12 | _write_config,
|
|
15 | 16 | from tests.conftest import CUSTOM_CONFIG_FILE
|
16 | 17 |
|
17 | 18 |
|
18 |
| -def test_get_current_path_default(custom_config_file: Path): |
| 19 | +@pytest.fixture |
| 20 | +def spy_ensure_current_exists(mocker): |
| 21 | + return mocker.spy(littlepay.config, "_ensure_current_exists") |
| 22 | + |
| 23 | + |
| 24 | +def test_ensure_current_exists(): |
| 25 | + # reminder: the module-level variable littlepay.config.CONFIG_FILE_CURRENT |
| 26 | + # is overwritten by the autouse fixture custom_current_file |
| 27 | + |
| 28 | + # the .current file should not exist to begin with |
| 29 | + assert not littlepay.config.CONFIG_FILE_CURRENT.exists() |
| 30 | + assert _ensure_current_exists() is False |
| 31 | + |
| 32 | + # now having ensured, the current file should exist |
| 33 | + assert littlepay.config.CONFIG_FILE_CURRENT.exists() |
| 34 | + # subsequent calls to ensure should indicate that it already exists |
| 35 | + assert _ensure_current_exists() |
| 36 | + |
| 37 | + |
| 38 | +def test_get_current_path_default(custom_config_file: Path, spy_ensure_current_exists): |
19 | 39 | result = _get_current_path()
|
20 | 40 |
|
21 | 41 | assert isinstance(result, Path)
|
22 | 42 | assert result.absolute() == custom_config_file.absolute()
|
| 43 | + assert spy_ensure_current_exists.call_count > 0 |
23 | 44 |
|
24 | 45 |
|
25 |
| -def test_get_current_path_custom(custom_current_file: Path): |
| 46 | +def test_get_current_path_custom(custom_current_file: Path, spy_ensure_current_exists): |
26 | 47 | expected = "."
|
27 | 48 | custom_current_file.write_text(expected)
|
28 | 49 |
|
29 | 50 | result = _get_current_path()
|
30 | 51 |
|
31 | 52 | assert result == Path(expected)
|
| 53 | + assert spy_ensure_current_exists.call_count > 0 |
32 | 54 |
|
33 | 55 |
|
34 |
| -def test_get_current_path_newline(custom_current_file: Path): |
| 56 | +def test_get_current_path_newline(custom_current_file: Path, spy_ensure_current_exists): |
35 | 57 | expected = "."
|
36 | 58 | custom_current_file.write_text(".\n")
|
37 | 59 |
|
38 | 60 | result = _get_current_path()
|
39 | 61 |
|
40 | 62 | assert result == Path(expected)
|
| 63 | + assert spy_ensure_current_exists.call_count > 0 |
41 | 64 |
|
42 | 65 |
|
43 |
| -def test_update_current_path_str(custom_current_file: Path): |
| 66 | +def test_update_current_path_str(custom_current_file: Path, spy_ensure_current_exists): |
44 | 67 | assert not custom_current_file.exists()
|
45 | 68 |
|
46 | 69 | _update_current_path("/the/path")
|
47 | 70 |
|
48 | 71 | assert custom_current_file.read_text() == "/the/path"
|
| 72 | + assert spy_ensure_current_exists.call_count > 0 |
49 | 73 |
|
50 | 74 |
|
51 |
| -def test_update_current_path_Path(custom_current_file: Path): |
| 75 | +def test_update_current_path_Path(custom_current_file: Path, spy_ensure_current_exists): |
52 | 76 | assert not custom_current_file.exists()
|
53 | 77 |
|
54 | 78 | _update_current_path(Path("/the/path"))
|
55 | 79 |
|
56 | 80 | assert custom_current_file.read_text() == "/the/path"
|
| 81 | + assert spy_ensure_current_exists.call_count > 0 |
57 | 82 |
|
58 | 83 |
|
59 | 84 | def test_read_config(custom_config_file: Path):
|
|
0 commit comments