From 0fe9045f541ab9e19cf2b2db4eb722e7c5aa4403 Mon Sep 17 00:00:00 2001 From: Marco D'Aleo Date: Thu, 13 Nov 2025 16:25:10 +0000 Subject: [PATCH] Black formatting --- src/mirro/main.py | 4 +++- tests/test_mirro.py | 23 ++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mirro/main.py b/src/mirro/main.py index 5ca7fce..3dc983d 100644 --- a/src/mirro/main.py +++ b/src/mirro/main.py @@ -24,7 +24,9 @@ def write_file(path: Path, content: str): path.write_text(content, encoding="utf-8") -def backup_original(original_path: Path, original_content: str, backup_dir: Path) -> Path: +def backup_original( + original_path: Path, original_content: str, backup_dir: Path +) -> Path: backup_dir.mkdir(parents=True, exist_ok=True) timestamp = time.strftime("%Y-%m-%d %H:%M:%S UTC", time.gmtime()) shortstamp = time.strftime("%Y%m%dT%H%M%S", time.gmtime()) diff --git a/tests/test_mirro.py b/tests/test_mirro.py index b4aeb37..fc53f15 100644 --- a/tests/test_mirro.py +++ b/tests/test_mirro.py @@ -13,16 +13,16 @@ import mirro.main as mirro # get_version # ============================================================ + def test_get_version_found(monkeypatch): - monkeypatch.setattr( - mirro.importlib.metadata, "version", lambda _: "1.2.3" - ) + monkeypatch.setattr(mirro.importlib.metadata, "version", lambda _: "1.2.3") assert mirro.get_version() == "1.2.3" def test_get_version_not_found(monkeypatch): def raiser(_): raise mirro.importlib.metadata.PackageNotFoundError + monkeypatch.setattr(mirro.importlib.metadata, "version", raiser) assert mirro.get_version() == "unknown" @@ -31,6 +31,7 @@ def test_get_version_not_found(monkeypatch): # read_file / write_file # ============================================================ + def test_read_file_exists(tmp_path): p = tmp_path / "x.txt" p.write_text("hello\n", encoding="utf-8") @@ -51,20 +52,23 @@ def test_write_file(tmp_path): # backup_original # ============================================================ + def test_backup_original(tmp_path, monkeypatch): original_path = tmp_path / "test.txt" original_content = "ABC" backup_dir = tmp_path / "backups" # Freeze timestamps - monkeypatch.setattr(time, "gmtime", lambda: time.struct_time((2023,1,2,3,4,5,0,0,0))) + monkeypatch.setattr( + time, "gmtime", lambda: time.struct_time((2023, 1, 2, 3, 4, 5, 0, 0, 0)) + ) monkeypatch.setattr( time, "strftime", lambda fmt, _: { "%Y-%m-%d %H:%M:%S UTC": "2023-01-02 03:04:05 UTC", "%Y%m%dT%H%M%S": "20230102T030405", - }[fmt] + }[fmt], ) backup_path = mirro.backup_original(original_path, original_content, backup_dir) @@ -80,6 +84,7 @@ def test_backup_original(tmp_path, monkeypatch): # Helper to run main() # ============================================================ + def simulate_main( monkeypatch, capsys, @@ -129,6 +134,7 @@ def simulate_main( # main: missing file argument # ============================================================ + def test_main_missing_argument(capsys): with patch("sys.argv", ["mirro"]): with pytest.raises(SystemExit): @@ -141,6 +147,7 @@ def test_main_missing_argument(capsys): # main: unchanged file (line 137) # ============================================================ + def test_main_existing_unchanged(tmp_path, monkeypatch, capsys): target = tmp_path / "file.txt" target.write_text("hello\n", encoding="utf-8") @@ -164,6 +171,7 @@ def test_main_existing_unchanged(tmp_path, monkeypatch, capsys): # main: changed file # ============================================================ + def test_main_existing_changed(tmp_path, monkeypatch, capsys): target = tmp_path / "file2.txt" @@ -184,6 +192,7 @@ def test_main_existing_changed(tmp_path, monkeypatch, capsys): # main: new file unchanged # ============================================================ + def test_main_new_file_unchanged(tmp_path, monkeypatch, capsys): new = tmp_path / "new.txt" @@ -204,6 +213,7 @@ def test_main_new_file_unchanged(tmp_path, monkeypatch, capsys): # main: new file changed # ============================================================ + def test_main_new_file_changed(tmp_path, monkeypatch, capsys): new = tmp_path / "new2.txt" @@ -224,6 +234,7 @@ def test_main_new_file_changed(tmp_path, monkeypatch, capsys): # main: permission denied for existing file (line 78) # ============================================================ + def test_main_permission_denied_existing(tmp_path, monkeypatch, capsys): target = tmp_path / "blocked.txt" target.write_text("hello", encoding="utf-8") @@ -243,6 +254,7 @@ def test_main_permission_denied_existing(tmp_path, monkeypatch, capsys): # main: permission denied creating file (line 84) # ============================================================ + def test_main_permission_denied_create(tmp_path, monkeypatch, capsys): newfile = tmp_path / "subdir" / "nofile.txt" parent = newfile.parent @@ -269,6 +281,7 @@ def test_main_permission_denied_create(tmp_path, monkeypatch, capsys): # main: non-nano editor (ordering branch) # ============================================================ + def test_main_editor_non_nano(tmp_path, monkeypatch, capsys): target = tmp_path / "vim.txt" target.write_text("old\n", encoding="utf-8")