refactor(ui): cull unused UI helpers and redundant modules
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import pytest
|
||||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
from pathlib import Path
|
||||
from src.diff_viewer import (
|
||||
parse_diff, DiffFile, DiffHunk, parse_hunk_header,
|
||||
get_line_color, render_diff_text_immediate,
|
||||
create_backup, apply_patch_to_file, restore_from_backup, cleanup_backup
|
||||
get_line_color, apply_patch_to_file
|
||||
)
|
||||
|
||||
def test_parse_diff_empty() -> None:
|
||||
@@ -95,35 +94,6 @@ def test_get_line_color() -> None:
|
||||
assert get_line_color("@@ -1,3 +1,4 @@") == "cyan"
|
||||
assert get_line_color(" context") == None
|
||||
|
||||
def test_render_diff_text_immediate() -> None:
|
||||
diff_text = """--- a/test.py
|
||||
+++ b/test.py
|
||||
@@ -1 +1 @@
|
||||
-old
|
||||
+new"""
|
||||
diff_files = parse_diff(diff_text)
|
||||
output = render_diff_text_immediate(diff_files)
|
||||
|
||||
assert len(output) > 0
|
||||
assert ("File: test.py", "white") in output
|
||||
assert ("@@ -1 +1 @@", "cyan") in output
|
||||
assert ("-old", "red") in output
|
||||
assert ("+new", "green") in output
|
||||
|
||||
def test_create_backup() -> None:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
test_file = Path(tmpdir) / "test.py"
|
||||
test_file.write_text("original content\n")
|
||||
|
||||
backup_path = create_backup(str(test_file))
|
||||
assert backup_path is not None
|
||||
assert Path(backup_path).exists()
|
||||
assert Path(backup_path).read_text() == "original content\n"
|
||||
|
||||
def test_create_backup_nonexistent() -> None:
|
||||
result = create_backup("/nonexistent/file.py")
|
||||
assert result is None
|
||||
|
||||
def test_apply_patch_simple() -> None:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
test_file = Path(tmpdir) / "test.py"
|
||||
@@ -158,24 +128,3 @@ def test_apply_patch_with_context() -> None:
|
||||
content = test_file.read_text()
|
||||
assert "line one" in content
|
||||
assert "line two" in content
|
||||
|
||||
def test_restore_from_backup() -> None:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
test_file = Path(tmpdir) / "test.py"
|
||||
test_file.write_text("modified\n")
|
||||
backup_file = test_file.with_suffix(".py.backup")
|
||||
backup_file.write_text("original\n")
|
||||
|
||||
success = restore_from_backup(str(test_file))
|
||||
assert success
|
||||
assert test_file.read_text() == "original\n"
|
||||
|
||||
def test_cleanup_backup() -> None:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
test_file = Path(tmpdir) / "test.py"
|
||||
test_file.write_text("content\n")
|
||||
backup_file = test_file.with_suffix(".py.backup")
|
||||
backup_file.write_text("backup\n")
|
||||
|
||||
cleanup_backup(str(test_file))
|
||||
assert not backup_file.exists()
|
||||
Reference in New Issue
Block a user