1 # PyOS_ascii_formatd is deprecated and not called from anywhere in
2 # Python itself. So this module is the only place it gets tested.
3 # Test that it works, and test that it's deprecated.
6 from test
.test_support
import check_warnings
, run_unittest
, import_module
8 # Skip tests if _ctypes module does not exist
9 import_module('_ctypes')
11 from ctypes
import pythonapi
, create_string_buffer
, sizeof
, byref
, c_double
12 PyOS_ascii_formatd
= pythonapi
.PyOS_ascii_formatd
15 class FormatDeprecationTests(unittest
.TestCase
):
17 def test_format_deprecation(self
):
18 buf
= create_string_buffer(' ' * 100)
20 with
check_warnings(('PyOS_ascii_formatd is deprecated',
22 PyOS_ascii_formatd(byref(buf
), sizeof(buf
), '%+.10f',
24 self
.assertEqual(buf
.value
, '+10.0000000000')
27 class FormatTests(unittest
.TestCase
):
28 # ensure that, for the restricted set of format codes,
29 # %-formatting returns the same values os PyOS_ascii_formatd
30 def test_format(self
):
31 buf
= create_string_buffer(' ' * 100)
39 ('%#.2g', 1.234567e200
),
46 with
check_warnings(('PyOS_ascii_formatd is deprecated',
48 for format
, val
in tests
:
49 PyOS_ascii_formatd(byref(buf
), sizeof(buf
), format
,
51 self
.assertEqual(buf
.value
, format
% val
)
55 run_unittest(FormatDeprecationTests
, FormatTests
)
57 if __name__
== '__main__':