1010import pytest
1111
1212
13- @pytest .fixture ()
13+ @pytest .fixture
1414def rtm () -> Any :
1515 """Reload the module so coverage tracks executed lines precisely."""
16-
1716 module = importlib .import_module ("rsync_time_machine" )
1817 return importlib .reload (module )
1918
2019
2120def test_prepare_exclusion_file_missing_file (tmp_path : Path , rtm : Any ) -> None :
2221 """Missing exclusion files should trigger a fatal error."""
23-
2422 module = rtm
2523 missing = tmp_path / "does-not-exist.txt"
2624 with pytest .raises (SystemExit ):
@@ -29,7 +27,6 @@ def test_prepare_exclusion_file_missing_file(tmp_path: Path, rtm: Any) -> None:
2927
3028def test_prepare_exclusion_file_noop_cleanup (tmp_path : Path , rtm : Any ) -> None :
3129 """A newline-terminated exclusion file is returned untouched."""
32-
3330 module = rtm
3431 exclusion = tmp_path / "exclude.txt"
3532 exclusion .write_bytes (b"pattern\n " )
@@ -41,9 +38,10 @@ def test_prepare_exclusion_file_noop_cleanup(tmp_path: Path, rtm: Any) -> None:
4138 assert exclusion .exists ()
4239
4340
44- def test_prepare_exclusion_file_appends_newline_and_cleans (tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ) -> None :
41+ def test_prepare_exclusion_file_appends_newline_and_cleans (
42+ tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ,
43+ ) -> None :
4544 """Files without a trailing newline are copied and cleaned up after use."""
46-
4745 module = rtm
4846 exclusion = tmp_path / "exclude.txt"
4947 exclusion .write_bytes (b"pattern" )
@@ -72,7 +70,6 @@ def fake_mkstemp(prefix: str, suffix: str) -> tuple[int, str]:
7270
7371def test_normalize_pid_variants (rtm : Any ) -> None :
7472 """Exercise the PID normalisation helper across its branches."""
75-
7673 module = rtm
7774 assert module .normalize_pid ("" , None ) is None
7875 assert module .normalize_pid ("0" , None ) is None
@@ -86,9 +83,10 @@ def test_normalize_pid_variants(rtm: Any) -> None:
8683 assert module .normalize_pid ("1234" , None ) == 1234
8784
8885
89- def test_exit_if_pid_running_invokes_ps (rtm : Any , monkeypatch : pytest .MonkeyPatch ) -> None :
86+ def test_exit_if_pid_running_invokes_ps (
87+ rtm : Any , monkeypatch : pytest .MonkeyPatch ,
88+ ) -> None :
9089 """Valid PIDs should lead to a ps invocation with the stripped PID string."""
91-
9290 module = rtm
9391 commands : list [str ] = []
9492
@@ -104,9 +102,10 @@ def fake_run_cmd(cmd: str, ssh: Any | None = None) -> Any:
104102 assert expected in commands
105103
106104
107- def test_exit_if_pid_running_detects_active_process (rtm : Any , monkeypatch : pytest .MonkeyPatch ) -> None :
105+ def test_exit_if_pid_running_detects_active_process (
106+ rtm : Any , monkeypatch : pytest .MonkeyPatch ,
107+ ) -> None :
108108 """A matching process triggers an early exit."""
109-
110109 module = rtm
111110
112111 def fake_run_cmd (cmd : str , ssh : Any | None = None ) -> Any :
@@ -120,9 +119,10 @@ def fake_run_cmd(cmd: str, ssh: Any | None = None) -> Any:
120119 module .exit_if_pid_running ("4242" )
121120
122121
123- def test_exit_if_pid_running_cygwin_branch (rtm : Any , monkeypatch : pytest .MonkeyPatch ) -> None :
122+ def test_exit_if_pid_running_cygwin_branch (
123+ rtm : Any , monkeypatch : pytest .MonkeyPatch ,
124+ ) -> None :
124125 """The cygwin branch should use the normalised PID and exit when active."""
125-
126126 module = rtm
127127 commands : list [str ] = []
128128
@@ -141,9 +141,10 @@ def fake_run_cmd(cmd: str, ssh: Any | None = None) -> Any:
141141 assert expected in commands
142142
143143
144- def test_start_backup_cleans_temp_exclusion_on_failure (tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ) -> None :
144+ def test_start_backup_cleans_temp_exclusion_on_failure (
145+ tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ,
146+ ) -> None :
145147 """start_backup removes temporary exclude files even when rsync fails."""
146-
147148 module = rtm
148149 src = tmp_path / "src"
149150 dest = tmp_path / "dest"
@@ -193,9 +194,10 @@ def fake_run_cmd(cmd: str, ssh: Any | None = None) -> Any:
193194 assert not path .exists ()
194195
195196
196- def test_deal_with_no_space_left_handles_non_utf8 (tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ) -> None :
197+ def test_deal_with_no_space_left_handles_non_utf8 (
198+ tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ,
199+ ) -> None :
197200 """Non-UTF8 log content is parsed safely when space runs out."""
198-
199201 module = rtm
200202 log_file = tmp_path / "backup.log"
201203 log_file .write_bytes (b"\xff No space left on device (28)" )
@@ -222,9 +224,10 @@ def fake_expire(folder: str, ssh: Any) -> None:
222224 assert expired
223225
224226
225- def test_check_rsync_errors_handles_non_utf8_error (tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ) -> None :
227+ def test_check_rsync_errors_handles_non_utf8_error (
228+ tmp_path : Path , rtm : Any , monkeypatch : pytest .MonkeyPatch ,
229+ ) -> None :
226230 """Log parsing tolerates undecodable bytes when reporting rsync errors."""
227-
228231 module = rtm
229232 log_file = tmp_path / "rsync.log"
230233 log_file .write_bytes (b"\xff rsync error: something broke" )
@@ -236,4 +239,3 @@ def test_check_rsync_errors_handles_non_utf8_error(tmp_path: Path, rtm: Any, mon
236239 module .check_rsync_errors (str (log_file ), auto_delete_log = False )
237240
238241 assert messages and "rsync error" in messages [0 ]
239-
0 commit comments