@@ -453,6 +453,136 @@ def test_basic_with_return_unexpected_index_query_false_excludes_query(self):
453453 assert "unexpected_index_query" not in result ["result" ]
454454
455455
456+ class TestSummaryWithReturnUnexpectedIndexQuery :
457+ """Tests for SUMMARY format with return_unexpected_index_query."""
458+
459+ def test_summary_with_return_unexpected_index_query_includes_query (self ):
460+ """SUMMARY with return_unexpected_index_query=True should include the query."""
461+ result = _format_map_output (
462+ result_format = {
463+ "result_format" : "SUMMARY" ,
464+ "return_unexpected_index_query" : True ,
465+ "partial_unexpected_count" : 20 ,
466+ "include_unexpected_rows" : False ,
467+ },
468+ success = False ,
469+ element_count = 5 ,
470+ nonnull_count = 5 ,
471+ unexpected_count = 2 ,
472+ unexpected_list = ["d" , "e" ],
473+ unexpected_index_list = [1 , 2 ],
474+ unexpected_index_query = "SELECT * FROM table WHERE condition" ,
475+ )
476+
477+ assert result ["success" ] is False
478+ assert "result" in result
479+ assert result ["result" ]["unexpected_index_query" ] == "SELECT * FROM table WHERE condition"
480+ # SUMMARY should also have standard fields
481+ assert result ["result" ]["element_count" ] == 5
482+ assert result ["result" ]["unexpected_count" ] == 2
483+ # SUMMARY should have partial_unexpected_counts
484+ assert "partial_unexpected_counts" in result ["result" ]
485+
486+ def test_summary_with_return_unexpected_index_query_includes_column_names (self ):
487+ """SUMMARY with return_unexpected_index_query=True should include column names."""
488+ result = _format_map_output (
489+ result_format = {
490+ "result_format" : "SUMMARY" ,
491+ "return_unexpected_index_query" : True ,
492+ "partial_unexpected_count" : 20 ,
493+ "include_unexpected_rows" : False ,
494+ },
495+ success = False ,
496+ element_count = 5 ,
497+ nonnull_count = 5 ,
498+ unexpected_count = 2 ,
499+ unexpected_list = ["d" , "e" ],
500+ unexpected_index_list = [1 , 2 ],
501+ unexpected_index_query = "SELECT pk_1, pk_2 FROM table WHERE condition" ,
502+ unexpected_index_column_names = ["pk_1" , "pk_2" ],
503+ )
504+
505+ assert result ["success" ] is False
506+ assert "result" in result
507+ assert (
508+ result ["result" ]["unexpected_index_query" ]
509+ == "SELECT pk_1, pk_2 FROM table WHERE condition"
510+ )
511+ assert result ["result" ]["unexpected_index_column_names" ] == ["pk_1" , "pk_2" ]
512+
513+ def test_summary_without_return_unexpected_index_query_excludes_query (self ):
514+ """SUMMARY without return_unexpected_index_query should NOT include the query.
515+
516+ This test verifies backwards compatibility.
517+ """
518+ result = _format_map_output (
519+ result_format = {
520+ "result_format" : "SUMMARY" ,
521+ "partial_unexpected_count" : 20 ,
522+ "include_unexpected_rows" : False ,
523+ },
524+ success = False ,
525+ element_count = 5 ,
526+ nonnull_count = 5 ,
527+ unexpected_count = 2 ,
528+ unexpected_list = ["d" , "e" ],
529+ unexpected_index_list = [1 , 2 ],
530+ unexpected_index_query = "SELECT * FROM table WHERE condition" ,
531+ )
532+
533+ assert result ["success" ] is False
534+ assert "result" in result
535+ assert "unexpected_index_query" not in result ["result" ]
536+ # But should still have standard SUMMARY fields
537+ assert result ["result" ]["element_count" ] == 5
538+ assert result ["result" ]["unexpected_count" ] == 2
539+
540+ def test_summary_with_return_unexpected_index_query_false_excludes_query (self ):
541+ """SUMMARY with return_unexpected_index_query=False should NOT include the query."""
542+ result = _format_map_output (
543+ result_format = {
544+ "result_format" : "SUMMARY" ,
545+ "return_unexpected_index_query" : False ,
546+ "partial_unexpected_count" : 20 ,
547+ "include_unexpected_rows" : False ,
548+ },
549+ success = False ,
550+ element_count = 5 ,
551+ nonnull_count = 5 ,
552+ unexpected_count = 2 ,
553+ unexpected_list = ["d" , "e" ],
554+ unexpected_index_list = [1 , 2 ],
555+ unexpected_index_query = "SELECT * FROM table WHERE condition" ,
556+ )
557+
558+ assert "unexpected_index_query" not in result ["result" ]
559+
560+ def test_summary_with_return_unexpected_index_query_but_no_query (self ):
561+ """SUMMARY with return_unexpected_index_query=True but no query.
562+
563+ Should not add unexpected_index_query to the result.
564+ """
565+ result = _format_map_output (
566+ result_format = {
567+ "result_format" : "SUMMARY" ,
568+ "return_unexpected_index_query" : True ,
569+ "partial_unexpected_count" : 20 ,
570+ "include_unexpected_rows" : False ,
571+ },
572+ success = True ,
573+ element_count = 5 ,
574+ nonnull_count = 5 ,
575+ unexpected_count = 0 ,
576+ unexpected_list = [],
577+ unexpected_index_list = [],
578+ unexpected_index_query = None ,
579+ )
580+
581+ assert result ["success" ] is True
582+ assert "result" in result
583+ assert "unexpected_index_query" not in result ["result" ]
584+
585+
456586# Tests for the helper function _add_unexpected_index_query_to_result
457587class TestAddUnexpectedIndexQueryToResult :
458588 """Tests for the _add_unexpected_index_query_to_result helper function."""
0 commit comments