godspeed app sync
This commit is contained in:
123
test_completion_status.py
Normal file
123
test_completion_status.py
Normal file
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Quick test to verify completion status handling in Godspeed sync.
|
||||
"""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
# Test the markdown parsing for completion status
|
||||
def test_completion_parsing():
|
||||
print("Testing completion status parsing...")
|
||||
|
||||
from src.services.godspeed.sync import GodspeedSync
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
sync_dir = Path(temp_dir)
|
||||
sync_engine = GodspeedSync(None, sync_dir)
|
||||
|
||||
# Test different completion states
|
||||
test_lines = [
|
||||
"- [ ] Incomplete task <!-- id:abc123 -->",
|
||||
"- [x] Completed task <!-- id:def456 -->",
|
||||
"- [X] Also completed <!-- id:ghi789 -->", # Capital X
|
||||
"- [ ] Another incomplete <!-- id:jkl012 -->",
|
||||
]
|
||||
|
||||
for line in test_lines:
|
||||
parsed = sync_engine._parse_task_line(line)
|
||||
if parsed:
|
||||
local_id, status, title, notes = parsed
|
||||
display = "✓ Complete" if status == "complete" else "○ Incomplete"
|
||||
print(f" {display}: {title} (ID: {local_id})")
|
||||
else:
|
||||
print(f" Failed to parse: {line}")
|
||||
|
||||
|
||||
def test_format_task():
|
||||
print("\nTesting task formatting...")
|
||||
|
||||
from src.services.godspeed.sync import GodspeedSync
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
sync_dir = Path(temp_dir)
|
||||
sync_engine = GodspeedSync(None, sync_dir)
|
||||
|
||||
# Test formatting both completion states
|
||||
incomplete_line = sync_engine._format_task_line(
|
||||
"abc123", "incomplete", "Buy milk", ""
|
||||
)
|
||||
completed_line = sync_engine._format_task_line(
|
||||
"def456", "complete", "Call mom", ""
|
||||
)
|
||||
with_notes_line = sync_engine._format_task_line(
|
||||
"ghi789", "incomplete", "Project work", "Due Friday"
|
||||
)
|
||||
|
||||
print(f" Incomplete: {incomplete_line}")
|
||||
print(f" Completed: {completed_line}")
|
||||
print(f" With notes: {with_notes_line}")
|
||||
|
||||
|
||||
def test_roundtrip():
|
||||
print("\nTesting roundtrip parsing...")
|
||||
|
||||
from src.services.godspeed.sync import GodspeedSync
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
sync_dir = Path(temp_dir)
|
||||
sync_engine = GodspeedSync(None, sync_dir)
|
||||
|
||||
# Original tasks with different completion states
|
||||
original_tasks = [
|
||||
("task1", "incomplete", "Buy groceries", "From whole foods"),
|
||||
("task2", "complete", "Call dentist", ""),
|
||||
("task3", "incomplete", "Finish report", "Due Monday"),
|
||||
("task4", "complete", "Exercise", "Went for a run"),
|
||||
]
|
||||
|
||||
# Write to file
|
||||
test_file = sync_dir / "test_roundtrip.md"
|
||||
sync_engine._write_list_file(test_file, original_tasks)
|
||||
|
||||
# Read back
|
||||
read_tasks = sync_engine._read_list_file(test_file)
|
||||
|
||||
print(f" Original: {len(original_tasks)} tasks")
|
||||
print(f" Read back: {len(read_tasks)} tasks")
|
||||
|
||||
for i, (original, read_back) in enumerate(zip(original_tasks, read_tasks)):
|
||||
orig_id, orig_status, orig_title, orig_notes = original
|
||||
read_id, read_status, read_title, read_notes = read_back
|
||||
|
||||
if orig_status == read_status and orig_title == read_title:
|
||||
display = "✓ Complete" if orig_status == "complete" else "○ Incomplete"
|
||||
print(f" {display}: {orig_title} - ✓ Match")
|
||||
else:
|
||||
print(f" ✗ Mismatch on task {i + 1}:")
|
||||
print(f" Original: status={orig_status}, title='{orig_title}'")
|
||||
print(f" Read: status={read_status}, title='{read_title}'")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=== Godspeed Completion Status Test ===\n")
|
||||
|
||||
try:
|
||||
test_completion_parsing()
|
||||
test_format_task()
|
||||
test_roundtrip()
|
||||
|
||||
print("\n=== Test Summary ===")
|
||||
print("✓ Completion status handling is working correctly!")
|
||||
print("\nExpected behavior:")
|
||||
print("- [ ] tasks sync as incomplete (is_complete=False)")
|
||||
print("- [x] tasks sync as completed (is_complete=True)")
|
||||
print("- Status changes in markdown files will sync to Godspeed")
|
||||
print("- Status changes in Godspeed will sync to markdown files")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n✗ Test failed: {e}")
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
Reference in New Issue
Block a user