Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
df9d4d6c
Commit
df9d4d6c
authored
Apr 29, 2009
by
Eric Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test that didn't make it in an svnmerge.
parent
8162382c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
Lib/test/test_ascii_formatd.py
Lib/test/test_ascii_formatd.py
+62
-0
No files found.
Lib/test/test_ascii_formatd.py
0 → 100644
View file @
df9d4d6c
# PyOS_ascii_formatd is deprecated and not called from anywhere in
# Python itself. So this module is the only place it gets tested.
# Test that it works, and test that it's deprecated.
import
unittest
from
test.support
import
check_warnings
,
run_unittest
,
cpython_only
class
FormatDeprecationTests
(
unittest
.
TestCase
):
@
cpython_only
def
testFormatDeprecation
(
self
):
# delay importing ctypes until we know we're in CPython
from
ctypes
import
(
pythonapi
,
create_string_buffer
,
sizeof
,
byref
,
c_double
)
PyOS_ascii_formatd
=
pythonapi
.
PyOS_ascii_formatd
buf
=
create_string_buffer
(
100
)
with
check_warnings
()
as
w
:
PyOS_ascii_formatd
(
byref
(
buf
),
sizeof
(
buf
),
b'%+.10f'
,
c_double
(
10.0
))
self
.
assertEqual
(
buf
.
value
,
b'+10.0000000000'
)
self
.
assertEqual
(
str
(
w
.
message
),
'PyOS_ascii_formatd is deprecated, '
'use PyOS_double_to_string instead'
)
class
FormatTests
(
unittest
.
TestCase
):
# ensure that, for the restricted set of format codes,
# %-formatting returns the same values os PyOS_ascii_formatd
@
cpython_only
def
testFormat
(
self
):
# delay importing ctypes until we know we're in CPython
from
ctypes
import
(
pythonapi
,
create_string_buffer
,
sizeof
,
byref
,
c_double
)
PyOS_ascii_formatd
=
pythonapi
.
PyOS_ascii_formatd
buf
=
create_string_buffer
(
100
)
tests
=
[
(
'%f'
,
100.0
),
(
'%g'
,
100.0
),
(
'%#g'
,
100.0
),
(
'%#.2g'
,
100.0
),
(
'%#.2g'
,
123.4567
),
(
'%#.2g'
,
1.234567e200
),
(
'%e'
,
1.234567e200
),
(
'%e'
,
1.234
),
(
'%+e'
,
1.234
),
(
'%-e'
,
1.234
),
]
with
check_warnings
():
for
format
,
val
in
tests
:
PyOS_ascii_formatd
(
byref
(
buf
),
sizeof
(
buf
),
bytes
(
format
,
'ascii'
),
c_double
(
val
))
self
.
assertEqual
(
buf
.
value
,
bytes
(
format
%
val
,
'ascii'
))
def
test_main
():
run_unittest
(
FormatDeprecationTests
,
FormatTests
)
if
__name__
==
'__main__'
:
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment