@@ -2807,6 +2807,25 @@ def check_format(expected, format, *args):
2807
2807
check_format ('repr=abc' ,
2808
2808
b'repr=%V' , 'abc' , b'xyz' )
2809
2809
2810
+ # test %p
2811
+ # We cannot test the exact result,
2812
+ # because it returns a hex representation of a C pointer,
2813
+ # which is going to be different each time. But, we can test the format.
2814
+ p_format_regex = r'^0x[a-zA-Z0-9]{8,}$'
2815
+ p_format1 = PyUnicode_FromFormat (b'%p' , 'abc' )
2816
+ self .assertIsInstance (p_format1 , str )
2817
+ self .assertRegex (p_format1 , p_format_regex )
2818
+
2819
+ p_format2 = PyUnicode_FromFormat (b'%p %p' , '123456' , b'xyz' )
2820
+ self .assertIsInstance (p_format2 , str )
2821
+ self .assertRegex (p_format2 ,
2822
+ r'0x[a-zA-Z0-9]{8,} 0x[a-zA-Z0-9]{8,}' )
2823
+
2824
+ # Extra args are ignored:
2825
+ p_format3 = PyUnicode_FromFormat (b'%p' , '123456' , None , b'xyz' )
2826
+ self .assertIsInstance (p_format3 , str )
2827
+ self .assertRegex (p_format3 , p_format_regex )
2828
+
2810
2829
# Test string decode from parameter of %s using utf-8.
2811
2830
# b'\xe4\xba\xba\xe6\xb0\x91' is utf-8 encoded byte sequence of
2812
2831
# '\u4eba\u6c11'
0 commit comments