|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 | 5 | from pathlib import Path
|
6 |
| -from unittest.mock import Mock |
| 6 | +from unittest.mock import Mock, call |
7 | 7 |
|
8 | 8 | from syrupy.assertion import SnapshotAssertion as Snapshot
|
9 | 9 |
|
@@ -62,3 +62,51 @@ def test_edit_day_logs(
|
62 | 62 | stderr=None,
|
63 | 63 | timeout=None,
|
64 | 64 | )
|
| 65 | + |
| 66 | + |
| 67 | +def test_whenEmptyKeepAliveFileExists_shouldRestartVim( |
| 68 | + main: c.MainType, vim_proc_mock: Mock, tmp_path: Path |
| 69 | +) -> None: |
| 70 | + """Test that we can use the keep alive file to have zorg re-run vim.""" |
| 71 | + zettel_dir = tmp_path / "org" |
| 72 | + |
| 73 | + c.keep_alive_file_path.touch() |
| 74 | + exit_code = main("--dir", str(zettel_dir), "edit", "foobar.zo") |
| 75 | + |
| 76 | + assert exit_code == 0 |
| 77 | + vim_proc_mock.assert_called_with( |
| 78 | + ["vim", str(zettel_dir / "foobar.zo")], |
| 79 | + stdout=None, |
| 80 | + stderr=None, |
| 81 | + timeout=None, |
| 82 | + ) |
| 83 | + assert vim_proc_mock.call_count == 2 |
| 84 | + |
| 85 | + |
| 86 | +def test_whenKeepAliveFileContainsPaths_useThosePathsOnRestart( |
| 87 | + main: c.MainType, vim_proc_mock: Mock, tmp_path: Path |
| 88 | +) -> None: |
| 89 | + """Test that we can use the keep alive file to change our vim file args.""" |
| 90 | + zettel_dir = tmp_path / "org" |
| 91 | + |
| 92 | + c.keep_alive_file_path.write_text("baz.zo buz.zo") |
| 93 | + exit_code = main("--dir", str(zettel_dir), "edit", "foobar.zo") |
| 94 | + |
| 95 | + assert exit_code == 0 |
| 96 | + vim_proc_mock.assert_has_calls([ |
| 97 | + call( |
| 98 | + ["vim", str(zettel_dir / "foobar.zo")], |
| 99 | + stdout=None, |
| 100 | + stderr=None, |
| 101 | + timeout=None, |
| 102 | + ), |
| 103 | + call().unwrap(), |
| 104 | + call( |
| 105 | + ["vim", "baz.zo", "buz.zo"], |
| 106 | + stdout=None, |
| 107 | + stderr=None, |
| 108 | + timeout=None, |
| 109 | + ), |
| 110 | + call().unwrap(), |
| 111 | + ]) |
| 112 | + assert vim_proc_mock.call_count == 2 |
0 commit comments