@@ -329,8 +329,13 @@ def process_request(class_type: type[HordeRequest]) -> None:
329329 if request_api_model_name is not None :
330330 expected_request_docstring += v2_api_model_template .format (api_model = request_api_model_name )
331331
332- if not class_type .__doc__ or not class_type .__doc__ .rstrip ().endswith (expected_request_docstring ):
333- non_conforming_requests [class_type ] = (class_type .__doc__ , expected_request_docstring )
332+ expected_request_docstring = expected_request_docstring .replace ("\n \n " , "\n \n " )
333+
334+ original_request_docstring = class_type .__doc__ .rstrip () if class_type .__doc__ else ""
335+ original_request_docstring = original_request_docstring .replace ("\n \n " , "\n \n " )
336+
337+ if not class_type .__doc__ or not original_request_docstring .endswith (expected_request_docstring ):
338+ non_conforming_requests [class_type ] = (original_request_docstring , expected_request_docstring )
334339
335340 for response_status_code , response_type in sorted (class_type .get_success_status_response_pairs ().items ()):
336341 if not issubclass (response_type , HordeResponse ):
@@ -365,47 +370,54 @@ def process_response(response_request_infos: list[FoundResponseInfo]) -> None:
365370 http_status_code = response_request_info .http_status_code ,
366371 )
367372
368- expected_response_docstring = response_docstring_template_single .format (
373+ original_expected_response_docstring = response_docstring_template_single .format (
369374 endpoint = response_request_info .endpoint ,
370375 http_status_code = response_request_info .http_status_code ,
371376 )
372377
373378 if response_request_info .api_model_name :
374- expected_response_docstring += v2_api_model_template .format (
379+ original_expected_response_docstring += v2_api_model_template .format (
375380 api_model = response_request_info .api_model_name ,
376381 )
377382
378383 found_response_type = response_request_info .response
379384
380385 response_doc_string = found_response_type .__doc__ .rstrip () if found_response_type .__doc__ else ""
386+ response_doc_string = response_doc_string .replace ("\n \n " , "\n \n " )
387+ response_doc_string = response_doc_string .replace ("\n \n " , "\n \n " )
381388
382389 # If the expected docstring contains any runs of text which are greater than 119 characters...
383390
384391 expected_exceeds_119 = False
385392
386- for line in expected_response_docstring .split ("\n " ):
393+ for line in original_expected_response_docstring .split ("\n " ):
387394 if len (line ) > 119 :
388395 expected_exceeds_119 = True
389396 break
390397
398+ matching_response_docstring = original_expected_response_docstring
391399 # Due to the 119 ruff-enforced line limit in source files,
392400 # we need to account for the fact that the expected docstring may require an
393401 # unspecified (in the format string) line break.
394402 if expected_exceeds_119 :
395- response_doc_string = response_doc_string .replace ("\n " , " " )
396- expected_response_docstring = expected_response_docstring .replace ("\n " , " " )
403+ matching_response_docstring = matching_response_docstring .replace ("\n " , "" )
404+ matching_response_docstring = matching_response_docstring .replace (" " , "" )
405+ response_doc_string = response_doc_string .replace ("\n " , "" )
406+ response_doc_string = response_doc_string .replace (" " , "" )
397407 logger .warning (
398408 f"Docstring for { found_response_type } exceeds 119 characters in places. "
399409 "Please manually verify the whitespace formatting as the testing script may not "
400410 "accurately reflect the expected docstring formatting." ,
401411 )
402412
413+ matching_response_docstring = matching_response_docstring .replace ("\n \n " , "\n \n " )
414+
403415 if not found_response_type .__doc__ or not response_doc_string .endswith (
404- expected_response_docstring ,
416+ matching_response_docstring ,
405417 ):
406418 non_conforming_responses [found_response_type ] = (
407- found_response_type . __doc__ ,
408- expected_response_docstring ,
419+ response_doc_string ,
420+ matching_response_docstring ,
409421 )
410422
411423 else :
@@ -428,29 +440,34 @@ def process_response(response_request_infos: list[FoundResponseInfo]) -> None:
428440 http_status_code = response_request_info .http_status_code ,
429441 )
430442
431- expected_response_docstring = response_docstring_template_multiple .format (
443+ original_expected_response_docstring = response_docstring_template_multiple .format (
432444 endpoint_status_codes_pairs = endpoint_status_codes_pairs ,
433445 )
434446
435447 if response_request_info .api_model_name :
436- expected_response_docstring = expected_response_docstring .rstrip ()
437- expected_response_docstring += v2_api_model_template .format (
448+ original_expected_response_docstring = original_expected_response_docstring .rstrip ()
449+ original_expected_response_docstring += v2_api_model_template .format (
438450 api_model = response_request_info .api_model_name ,
439451 )
440452
441453 for response_request_info in response_request_infos :
442454 found_response_type = response_request_info .response
443455
444456 response_doc_string = found_response_type .__doc__ .rstrip () if found_response_type .__doc__ else ""
445- response_doc_string .replace ("\n " , " " )
446- response_doc_string .replace ("\n " , " " )
447- response_doc_string .replace ("\n " , " " )
448- response_doc_string .replace ("\n " , " " )
457+ response_doc_string = response_doc_string .replace (" " , " " )
458+ response_doc_string = response_doc_string .replace (" " , " " )
459+ response_doc_string = response_doc_string .replace ("\n \n " , "\n \n " )
460+ response_doc_string = response_doc_string .replace ("\n \n " , "\n \n " )
449461
450- if not found_response_type .__doc__ or not response_doc_string .endswith (expected_response_docstring ):
462+ matching_response_docstring = original_expected_response_docstring .replace ("\n \n " , "\n \n " )
463+ matching_response_docstring = matching_response_docstring .replace (" " , " " )
464+ matching_response_docstring = matching_response_docstring .replace (" " , " " )
465+ matching_response_docstring = matching_response_docstring .replace (" " , " " )
466+
467+ if not found_response_type .__doc__ or not response_doc_string .endswith (matching_response_docstring ):
451468 non_conforming_responses [found_response_type ] = (
452- found_response_type . __doc__ ,
453- expected_response_docstring ,
469+ response_doc_string ,
470+ matching_response_docstring ,
454471 )
455472
456473 def process_other (class_type : type [HordeAPIObject ]) -> None :
@@ -461,7 +478,11 @@ def process_other(class_type: type[HordeAPIObject]) -> None:
461478 if not class_type .__doc__ :
462479 return
463480
464- if not class_type .__doc__ .rstrip ().endswith (expected_other_docstring ):
481+ original_other_docstring = class_type .__doc__ .rstrip ()
482+ original_other_docstring = original_other_docstring .replace ("\n \n " , "\n \n " )
483+
484+ expected_other_docstring = expected_other_docstring .replace ("\n \n " , "\n \n " )
485+ if not original_other_docstring .endswith (expected_other_docstring ):
465486 non_conforming_other [class_type ] = (class_type .__doc__ , expected_other_docstring )
466487
467488 _sorted_all_classes = sorted (all_classes , key = lambda x : x .__name__ )
0 commit comments