1111
1212logger = logging .getLogger (__name__ )
1313
14+ # Test tolerance constants for better maintainability
15+ COORDINATE_TOLERANCE = 2
16+ PERCENTAGE_TOLERANCE = 0.05
17+ PAGE_HEIGHT_TOLERANCE = 5
18+ OCR_SIMILARITY_THRESHOLD = 0.90
19+
1420
1521def test_get_usage_info (client_v2 : LLMWhispererClientV2 ) -> None :
1622 usage_info = client_v2 .get_usage_info ()
@@ -28,6 +34,7 @@ def test_get_usage_info(client_v2: LLMWhispererClientV2) -> None:
2834 "overage_page_count" ,
2935 "subscription_plan" ,
3036 "today_page_count" ,
37+ "current_page_count_table" ,
3138 ]
3239 assert set (usage_info .keys ()) == set (expected_keys ), f"usage_info { usage_info } does not contain the expected keys"
3340
@@ -103,12 +110,12 @@ def test_highlight(client_v2: LLMWhispererClientV2, data_dir: str, input_file: s
103110
104111 # Assert line 2 data
105112 line2 = highlight_data ["2" ]
106- assert line2 ["base_y" ] == 155
107- assert line2 ["base_y_percent" ] == pytest .approx (4.8927 ) # Using approx for float comparison
108- assert line2 ["height" ] == 51
109- assert line2 ["height_percent" ] == pytest .approx (1.6098 ) # Using approx for float comparison
113+ assert line2 ["base_y" ] == pytest . approx ( 155 , abs = COORDINATE_TOLERANCE )
114+ assert line2 ["base_y_percent" ] == pytest .approx (4.8927 , abs = PERCENTAGE_TOLERANCE )
115+ assert line2 ["height" ] == pytest . approx ( 51 , abs = COORDINATE_TOLERANCE )
116+ assert line2 ["height_percent" ] == pytest .approx (1.6098 , abs = PERCENTAGE_TOLERANCE )
110117 assert line2 ["page" ] == 0
111- assert line2 ["page_height" ] == 3168
118+ assert line2 ["page_height" ] == pytest . approx ( 3168 , abs = PAGE_HEIGHT_TOLERANCE )
112119
113120
114121@pytest .mark .parametrize (
@@ -170,7 +177,7 @@ def test_whisper_v2_url_in_post(
170177 "url,token,webhook_name" ,
171178 [
172179 (
173- " https://webhook.site/0990fff9-ce95-4d11-95e1-be9ad38c40d6" , # need to find a clean solution
180+ os . getenv ( "WEBHOOK_TEST_URL" , " https://httpbin.org/post" ) , # configurable via env var, defaults to httpbin.org
174181 "" ,
175182 "client_v2_test" ,
176183 ),
@@ -237,13 +244,13 @@ def assert_extracted_text(file_path: str, whisper_result: dict, mode: str, outpu
237244 assert whisper_result ["status_code" ] == 200
238245
239246 # For OCR based processing
240- threshold = 0.94
247+ threshold = OCR_SIMILARITY_THRESHOLD
241248
242249 # For text based processing
243250 if mode == "native_text" and output_mode == "text" :
244251 threshold = 0.99
245252 elif mode == "low_cost" :
246- threshold = 0.90
253+ threshold = OCR_SIMILARITY_THRESHOLD
247254 extracted_text = whisper_result ["extraction" ]["result_text" ]
248255 similarity = SequenceMatcher (None , extracted_text , exp ).ratio ()
249256
0 commit comments