From 25969377536828e6fa29f322396058202228142a Mon Sep 17 00:00:00 2001 From: fundor333 Date: Thu, 7 May 2026 19:05:08 +0200 Subject: [PATCH] fix: current_progress_percent correct import format from hardcover --- src/hardcover_sync/sync.py | 2 +- test/test_api.py | 3 +++ test/test_sync_logic.py | 33 +++++++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/hardcover_sync/sync.py b/src/hardcover_sync/sync.py index 64ee725..ed85f72 100644 --- a/src/hardcover_sync/sync.py +++ b/src/hardcover_sync/sync.py @@ -372,7 +372,7 @@ def find_sync_from_changes( current_progress_pct = hc_book.current_progress_percent if sync_progress and progress_percent_col and current_progress_pct is not None: current = get_calibre_value(calibre_id, progress_percent_col) - new_progress_pct = round(current_progress_pct, 1) + new_progress_pct = round(current_progress_pct / 100, 3) current_rounded = round(float(current), 1) if current else None if current_rounded != new_progress_pct: changes.append( diff --git a/test/test_api.py b/test/test_api.py index 7a0039c..5206c2c 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -655,6 +655,7 @@ def test_create_user_book_read(self): finished_at="2024-01-30", progress_pages=250, edition_id=456, + progress=0.34, ) assert read.id == 100 @@ -662,6 +663,8 @@ def test_create_user_book_read(self): assert read.finished_at == "2024-01-30" assert read.progress_pages == 250 assert read.edition_id == 456 + assert read.progress == 0.34 + assert read.progress_percent == 34 def test_user_book_read_with_none_values(self): """Test UserBookRead with missing/None values.""" diff --git a/test/test_sync_logic.py b/test/test_sync_logic.py index 2d0f003..6c320b8 100644 --- a/test/test_sync_logic.py +++ b/test/test_sync_logic.py @@ -743,7 +743,7 @@ def test_progress_percent_change(self): def get_value(calibre_id, col): if col == "progress_pct_col": - return 50.0 # Current is 50%, should change to 75% + return 0.50 # Current is 50%, should change to 75% return None def get_title(calibre_id): @@ -759,8 +759,8 @@ def get_title(calibre_id): assert len(changes) == 1 assert changes[0].field == "progress_percent" - assert "50.0%" in changes[0].old_value - assert "75.0%" in changes[0].new_value + assert "0.5%" in changes[0].old_value + assert "0.75%" in changes[0].new_value def test_progress_percent_empty_to_value(self): """Test progress percent change from empty to value.""" @@ -784,7 +784,32 @@ def get_title(calibre_id): assert len(changes) == 1 assert changes[0].field == "progress_percent" assert changes[0].old_value == "(empty)" - assert "25.0%" in changes[0].new_value + assert "0.25" in changes[0].new_value + + def test_progress_percent_valid(self): + """Test detecting progress percent changes and is a valid percentage.""" + hc_books = [self.create_user_book_with_reads(100, progress=0.75)] # 75% + hc_to_calibre = {"test-book": 1} + + def get_value(calibre_id, col): + if col == "progress_pct_col": + return 50.0 # Current is 50%, should change to 75% + return None + + def get_title(calibre_id): + return "Test Book" + + prefs = { + "status_column": "", + "progress_percent_column": "progress_pct_col", + "sync_progress": True, + } + + changes = find_sync_from_changes(hc_books, hc_to_calibre, get_value, get_title, prefs) + + assert len(changes) == 1 + assert changes[0].field == "progress_percent" + assert changes[0].raw_value == str(0.75) class TestFindSyncFromChangesDates: