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
419f704d
Commit
419f704d
authored
Aug 14, 2010
by
Giampaolo Rodolà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix issue #8857: provide a test case for socket.getaddrinfo
parent
ab6190f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
Lib/test/test_socket.py
Lib/test/test_socket.py
+51
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_socket.py
View file @
419f704d
...
@@ -16,8 +16,21 @@ import array
...
@@ -16,8 +16,21 @@ import array
from
weakref
import
proxy
from
weakref
import
proxy
import
signal
import
signal
def
try_address
(
host
,
port
=
0
,
family
=
socket
.
AF_INET
):
"""Try to bind a socket on the given host:port and return True
if that has been possible."""
try
:
sock
=
socket
.
socket
(
family
,
socket
.
SOCK_STREAM
)
sock
.
bind
((
host
,
port
))
except
(
socket
.
error
,
socket
.
gaierror
):
return
False
else
:
sock
.
close
()
return
True
HOST
=
support
.
HOST
HOST
=
support
.
HOST
MSG
=
b'Michael Gilfix was here
\
n
'
MSG
=
b'Michael Gilfix was here
\
n
'
SUPPORTS_IPV6
=
socket
.
has_ipv6
and
try_address
(
'::1'
,
family
=
socket
.
AF_INET6
)
try
:
try
:
import
_thread
as
thread
import
_thread
as
thread
...
@@ -564,6 +577,44 @@ class GeneralModuleTests(unittest.TestCase):
...
@@ -564,6 +577,44 @@ class GeneralModuleTests(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
s
.
ioctl
,
-
1
,
None
)
self
.
assertRaises
(
ValueError
,
s
.
ioctl
,
-
1
,
None
)
s
.
ioctl
(
socket
.
SIO_KEEPALIVE_VALS
,
(
1
,
100
,
100
))
s
.
ioctl
(
socket
.
SIO_KEEPALIVE_VALS
,
(
1
,
100
,
100
))
def
testGetaddrinfo
(
self
):
try
:
socket
.
getaddrinfo
(
'localhost'
,
80
)
except
socket
.
gaierror
as
err
:
if
err
.
errno
==
socket
.
EAI_SERVICE
:
# see http://bugs.python.org/issue1282647
self
.
skipTest
(
"buggy libc version"
)
raise
# len of every sequence is supposed to be == 5
for
info
in
socket
.
getaddrinfo
(
HOST
,
None
):
self
.
assertEqual
(
len
(
info
),
5
)
# host can be a domain name, a string representation of an
# IPv4/v6 address or None
socket
.
getaddrinfo
(
'localhost'
,
80
)
socket
.
getaddrinfo
(
'127.0.0.1'
,
80
)
socket
.
getaddrinfo
(
None
,
80
)
if
SUPPORTS_IPV6
:
socket
.
getaddrinfo
(
'::1'
,
80
)
# port can be a string service name such as "http", a numeric
# port number or None
socket
.
getaddrinfo
(
HOST
,
"http"
)
socket
.
getaddrinfo
(
HOST
,
80
)
socket
.
getaddrinfo
(
HOST
,
None
)
# test family and socktype filters
infos
=
socket
.
getaddrinfo
(
HOST
,
None
,
socket
.
AF_INET
)
for
family
,
_
,
_
,
_
,
_
in
infos
:
self
.
assertEqual
(
family
,
socket
.
AF_INET
)
infos
=
socket
.
getaddrinfo
(
HOST
,
None
,
0
,
socket
.
SOCK_STREAM
)
for
_
,
socktype
,
_
,
_
,
_
in
infos
:
self
.
assertEqual
(
socktype
,
socket
.
SOCK_STREAM
)
# test proto and flags arguments
socket
.
getaddrinfo
(
HOST
,
None
,
0
,
0
,
socket
.
AI_CANONNAME
)
socket
.
getaddrinfo
(
HOST
,
None
,
0
,
0
,
0
,
socket
.
AI_PASSIVE
)
# a server willing to support both IPv4 and IPv6 will
# usually do this
socket
.
getaddrinfo
(
None
,
0
,
socket
.
AF_UNSPEC
,
socket
.
SOCK_STREAM
,
0
,
socket
.
AI_PASSIVE
)
@
unittest
.
skipUnless
(
thread
,
'Threading required for this test.'
)
@
unittest
.
skipUnless
(
thread
,
'Threading required for this test.'
)
class
BasicTCPTest
(
SocketConnectedTest
):
class
BasicTCPTest
(
SocketConnectedTest
):
...
...
Misc/NEWS
View file @
419f704d
...
@@ -194,6 +194,8 @@ Tools/Demos
...
@@ -194,6 +194,8 @@ Tools/Demos
Tests
Tests
-----
-----
- Issue #8857: Provide a test case for socket.getaddrinfo.
- Issue #7564: Skip test_ioctl if another process is attached to /dev/tty.
- Issue #7564: Skip test_ioctl if another process is attached to /dev/tty.
- Issue #8433: Fix test_curses failure with newer versions of ncurses.
- Issue #8433: Fix test_curses failure with newer versions of ncurses.
...
...
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