@@ -809,11 +809,8 @@ def test_utf8_2byte_sequence_complete_coverage():
809809 """
810810 import mssql_python
811811
812- print ("\n === Testing 2-byte UTF-8 Sequence Handler (lines 473-488) ===\n " )
813-
814812 # TEST 1: Lines 475-478 - Invalid continuation byte detection
815813 # Condition: (data[i + 1] & 0xC0) != 0x80
816- print ("TEST 1: Invalid continuation byte (lines 475-478)" )
817814 invalid_continuation = [
818815 (b"\xc2 \x00 " , "00000000" , "00xxxxxx - should fail" ),
819816 (b"\xc2 \x3f " , "00111111" , "00xxxxxx - should fail" ),
@@ -826,25 +823,14 @@ def test_utf8_2byte_sequence_complete_coverage():
826823 for test_bytes , binary , desc in invalid_continuation :
827824 try :
828825 result = test_bytes .decode ("utf-8" , errors = "replace" )
829- try :
830- print (f" { test_bytes .hex ()} : { binary } ({ desc } ) -> { repr (result )} " )
831- except UnicodeEncodeError :
832- print (f" { test_bytes .hex ()} : { binary } ({ desc } ) -> <decoded>" )
833826 # Check that invalid sequences are handled (may produce replacement chars or split)
834827 assert len (result ) > 0 , f"Should produce some output for { desc } "
835828 except Exception as e :
836- # Print without the exception message to avoid encoding errors
837- print (f" { test_bytes .hex ()} : { binary } ({ desc } ) -> Exception occurred" )
838829 # Any error handling is acceptable for invalid sequences
839-
840- try :
841- print (" ✓ All invalid continuation bytes handled\n " )
842- except UnicodeEncodeError :
843- print (" All invalid continuation bytes handled\n " )
830+ pass
844831
845832 # TEST 2: Lines 481-484 - Valid decoding path
846833 # Condition: cp >= 0x80 (after continuation byte validated)
847- print ("TEST 2: Valid 2-byte sequences (lines 481-484)" )
848834 valid_2byte = [
849835 (b"\xc2 \x80 " , "\u0080 " , 0x80 , "U+0080 - minimum valid 2-byte" ),
850836 (b"\xc2 \xa9 " , "©" , 0xA9 , "U+00A9 - copyright symbol" ),
@@ -855,10 +841,6 @@ def test_utf8_2byte_sequence_complete_coverage():
855841 for test_bytes , expected_char , codepoint , desc in valid_2byte :
856842 # Test decoding
857843 result = test_bytes .decode ("utf-8" )
858- try :
859- print (f" { test_bytes .hex ()} : U+{ codepoint :04X} -> { repr (result )} ({ desc } )" )
860- except UnicodeEncodeError :
861- print (f" { test_bytes .hex ()} : U+{ codepoint :04X} -> <result> ({ desc } )" )
862844 assert result == expected_char , f"Should decode to { expected_char !r} "
863845 assert "\ufffd " not in result , f"Should NOT contain U+FFFD for valid sequence"
864846
@@ -868,14 +850,8 @@ def test_utf8_2byte_sequence_complete_coverage():
868850 binary_result == test_bytes
869851 ), f"Binary({ expected_char !r} ) should encode to { test_bytes .hex ()} "
870852
871- try :
872- print (" ✓ All valid 2-byte sequences correctly decoded\n " )
873- except UnicodeEncodeError :
874- print (" All valid 2-byte sequences correctly decoded\n " )
875-
876853 # TEST 3: Lines 486-487 - Overlong encoding rejection
877854 # Condition: cp < 0x80 (overlong encoding)
878- print ("TEST 3: Overlong 2-byte encodings (lines 486-487)" )
879855 overlong_2byte = [
880856 (b"\xc0 \x80 " , 0x00 , "NULL character - security risk" ),
881857 (b"\xc0 \xaf " , 0x2F , "Forward slash / - path traversal risk" ),
@@ -886,65 +862,27 @@ def test_utf8_2byte_sequence_complete_coverage():
886862 for test_bytes , codepoint , desc in overlong_2byte :
887863 try :
888864 result = test_bytes .decode ("utf-8" , errors = "replace" )
889- try :
890- print (
891- f" { test_bytes .hex ()} : Overlong encoding of U+{ codepoint :04X} ({ desc } ) -> { repr (result )} "
892- )
893- except UnicodeEncodeError :
894- print (
895- f" { test_bytes .hex ()} : Overlong encoding of U+{ codepoint :04X} ({ desc } ) -> <decoded>"
896- )
897865 # Check that overlong sequences are handled (behavior may vary by platform)
898866 assert len (result ) > 0 , f"Should produce some output for overlong U+{ codepoint :04X} "
899867 except Exception as e :
900- print (
901- f" { test_bytes .hex ()} : Overlong encoding of U+{ codepoint :04X} ({ desc } ) -> Exception occurred"
902- )
903-
904- try :
905- print (" ✓ All overlong 2-byte encodings handled\n " )
906- except UnicodeEncodeError :
907- print (" All overlong 2-byte encodings handled\n " )
868+ pass
908869
909870 # TEST 4: Edge cases and boundaries
910- print ("TEST 4: Boundary testing" )
911-
912871 # Boundary between 1-byte and 2-byte (0x7F vs 0x80)
913872 one_byte_max = b"\x7f " # U+007F - last 1-byte character
914873 two_byte_min = b"\xc2 \x80 " # U+0080 - first 2-byte character
915874
916875 result_1 = one_byte_max .decode ("utf-8" )
917876 result_2 = two_byte_min .decode ("utf-8" )
918- try :
919- print (f" 1-byte max: { one_byte_max .hex ()} -> U+007F: { repr (result_1 )} " )
920- except UnicodeEncodeError :
921- print (f" 1-byte max: { one_byte_max .hex ()} -> U+007F: <result>" )
922- try :
923- print (f" 2-byte min: { two_byte_min .hex ()} -> U+0080: { repr (result_2 )} " )
924- except UnicodeEncodeError :
925- print (f" 2-byte min: { two_byte_min .hex ()} -> U+0080: <result>" )
926877 assert ord (result_1 ) == 0x7F
927878 assert ord (result_2 ) == 0x80
928879
929880 # Boundary between 2-byte and 3-byte (0x7FF vs 0x800)
930881 two_byte_max = b"\xdf \xbf " # U+07FF - last 2-byte character
931882 result_3 = two_byte_max .decode ("utf-8" )
932- try :
933- print (f" 2-byte max: { two_byte_max .hex ()} -> U+07FF: { repr (result_3 )} " )
934- except UnicodeEncodeError :
935- print (f" 2-byte max: { two_byte_max .hex ()} -> U+07FF: <result>" )
936883 assert ord (result_3 ) == 0x7FF
937884
938- try :
939- print (" ✓ Boundary cases handled correctly\n " )
940- except UnicodeEncodeError :
941- print (" Boundary cases handled correctly\n " )
942-
943885 # TEST 5: Bit pattern validation details
944- print ("TEST 5: Detailed bit pattern analysis" )
945- print (" Continuation byte must match pattern: 10xxxxxx (0x80-0xBF)" )
946- print (" Mask 0xC0 extracts top 2 bits, must equal 0x80" )
947-
948886 bit_patterns = [
949887 (0x00 , 0x00 , "00xxxxxx" , False ),
950888 (0x3F , 0x00 , "00xxxxxx" , False ),
@@ -957,17 +895,8 @@ def test_utf8_2byte_sequence_complete_coverage():
957895 ]
958896
959897 for byte_val , masked , pattern , valid in bit_patterns :
960- status = "VALID" if valid else "INVALID"
961- print (f" 0x{ byte_val :02X} & 0xC0 = 0x{ masked :02X} ({ pattern } ) -> { status } " )
962898 assert (byte_val & 0xC0 ) == masked , f"Bit masking incorrect for 0x{ byte_val :02X} "
963899 assert ((byte_val & 0xC0 ) == 0x80 ) == valid , f"Validation incorrect for 0x{ byte_val :02X} "
964-
965- try :
966- print (" ✓ Bit pattern validation correct\n " )
967- except UnicodeEncodeError :
968- print (" Bit pattern validation correct\n " )
969-
970- print ("=== All 2-byte UTF-8 sequence tests passed ===" )
971900 assert True , "Complete 2-byte sequence coverage validated"
972901
973902
0 commit comments