@@ -2759,6 +2759,25 @@ def check_format(expected, format, *args):
2759
2759
check_format ('repr=abc' ,
2760
2760
b'repr=%V' , 'abc' , b'xyz' )
2761
2761
2762
+ # test %p
2763
+ # We cannot test the exact result,
2764
+ # because it returns a hex representation of a C pointer,
2765
+ # which is going to be different each time. But, we can test the format.
2766
+ p_format_regex = r'^0x[a-zA-Z0-9]{3,}$'
2767
+ p_format1 = PyUnicode_FromFormat (b'%p' , 'abc' )
2768
+ self .assertIsInstance (p_format1 , str )
2769
+ self .assertRegex (p_format1 , p_format_regex )
2770
+
2771
+ p_format2 = PyUnicode_FromFormat (b'%p %p' , '123456' , b'xyz' )
2772
+ self .assertIsInstance (p_format2 , str )
2773
+ self .assertRegex (p_format2 ,
2774
+ r'0x[a-zA-Z0-9]{3,} 0x[a-zA-Z0-9]{3,}' )
2775
+
2776
+ # Extra args are ignored:
2777
+ p_format3 = PyUnicode_FromFormat (b'%p' , '123456' , None , b'xyz' )
2778
+ self .assertIsInstance (p_format3 , str )
2779
+ self .assertRegex (p_format3 , p_format_regex )
2780
+
2762
2781
# Test string decode from parameter of %s using utf-8.
2763
2782
# b'\xe4\xba\xba\xe6\xb0\x91' is utf-8 encoded byte sequence of
2764
2783
# '\u4eba\u6c11'
0 commit comments