Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
21ebbb7d
Kaydet (Commit)
21ebbb7d
authored
Kas 02, 2010
tarafından
Brian Curtin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Clean up ResourceWarnings due to unclosed sockets.
üst
be647e28
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
test_socket.py
Lib/test/test_socket.py
+20
-0
No files found.
Lib/test/test_socket.py
Dosyayı görüntüle @
21ebbb7d
...
...
@@ -259,6 +259,7 @@ class GeneralModuleTests(unittest.TestCase):
def
test_repr
(
self
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
addCleanup
(
s
.
close
)
self
.
assertTrue
(
repr
(
s
)
.
startswith
(
"<socket.socket object"
))
def
test_weakref
(
self
):
...
...
@@ -532,6 +533,7 @@ class GeneralModuleTests(unittest.TestCase):
# Testing getsockname()
port
=
self
.
_get_unused_port
()
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
addCleanup
(
sock
.
close
)
sock
.
bind
((
"0.0.0.0"
,
port
))
name
=
sock
.
getsockname
()
# XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
...
...
@@ -545,12 +547,14 @@ class GeneralModuleTests(unittest.TestCase):
# Testing getsockopt()
# We know a socket should start without reuse==0
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
addCleanup
(
sock
.
close
)
reuse
=
sock
.
getsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
)
self
.
assertFalse
(
reuse
!=
0
,
"initial mode is reuse"
)
def
testSetSockOpt
(
self
):
# Testing setsockopt()
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
addCleanup
(
sock
.
close
)
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
reuse
=
sock
.
getsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
)
self
.
assertFalse
(
reuse
==
0
,
"failed to set reuse mode"
)
...
...
@@ -784,6 +788,7 @@ class BasicTCPTest(SocketConnectedTest):
# Testing fromfd()
fd
=
self
.
cli_conn
.
fileno
()
sock
=
socket
.
fromfd
(
fd
,
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
addCleanup
(
sock
.
close
)
self
.
assertIsInstance
(
sock
,
socket
.
socket
)
msg
=
sock
.
recv
(
1024
)
self
.
assertEqual
(
msg
,
MSG
)
...
...
@@ -794,6 +799,7 @@ class BasicTCPTest(SocketConnectedTest):
def
testDup
(
self
):
# Testing dup()
sock
=
self
.
cli_conn
.
dup
()
self
.
addCleanup
(
sock
.
close
)
msg
=
sock
.
recv
(
1024
)
self
.
assertEqual
(
msg
,
MSG
)
...
...
@@ -824,6 +830,7 @@ class BasicTCPTest(SocketConnectedTest):
# ...but we can create another socket using the (still open)
# file descriptor
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
fileno
=
f
)
self
.
addCleanup
(
sock
.
close
)
msg
=
sock
.
recv
(
1024
)
self
.
assertEqual
(
msg
,
MSG
)
...
...
@@ -970,6 +977,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
read
,
write
,
err
=
select
.
select
([
self
.
serv
],
[],
[])
if
self
.
serv
in
read
:
conn
,
addr
=
self
.
serv
.
accept
()
conn
.
close
()
else
:
self
.
fail
(
"Error trying to do accept after select."
)
...
...
@@ -980,6 +988,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
def
testConnect
(
self
):
# Testing non-blocking connect
conn
,
addr
=
self
.
serv
.
accept
()
conn
.
close
()
def
_testConnect
(
self
):
self
.
cli
.
settimeout
(
10
)
...
...
@@ -998,6 +1007,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
read
,
write
,
err
=
select
.
select
([
conn
],
[],
[])
if
conn
in
read
:
msg
=
conn
.
recv
(
len
(
MSG
))
conn
.
close
()
self
.
assertEqual
(
msg
,
MSG
)
else
:
self
.
fail
(
"Error during select call to non-blocking socket."
)
...
...
@@ -1441,6 +1451,7 @@ class NetworkConnectionNoServer(unittest.TestCase):
def
test_connect
(
self
):
port
=
support
.
find_unused_port
()
cli
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
addCleanup
(
cli
.
close
)
with
self
.
assertRaises
(
socket
.
error
)
as
cm
:
cli
.
connect
((
HOST
,
port
))
self
.
assertEqual
(
cm
.
exception
.
errno
,
errno
.
ECONNREFUSED
)
...
...
@@ -1478,16 +1489,19 @@ class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
def
_justAccept
(
self
):
conn
,
addr
=
self
.
serv
.
accept
()
conn
.
close
()
testFamily
=
_justAccept
def
_testFamily
(
self
):
self
.
cli
=
socket
.
create_connection
((
HOST
,
self
.
port
),
timeout
=
30
)
self
.
addCleanup
(
self
.
cli
.
close
)
self
.
assertEqual
(
self
.
cli
.
family
,
2
)
testSourceAddress
=
_justAccept
def
_testSourceAddress
(
self
):
self
.
cli
=
socket
.
create_connection
((
HOST
,
self
.
port
),
timeout
=
30
,
source_address
=
(
''
,
self
.
source_port
))
self
.
addCleanup
(
self
.
cli
.
close
)
self
.
assertEqual
(
self
.
cli
.
getsockname
()[
1
],
self
.
source_port
)
# The port number being used is sufficient to show that the bind()
# call happened.
...
...
@@ -1499,6 +1513,7 @@ class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
socket
.
setdefaulttimeout
(
42
)
try
:
self
.
cli
=
socket
.
create_connection
((
HOST
,
self
.
port
))
self
.
addCleanup
(
self
.
cli
.
close
)
finally
:
socket
.
setdefaulttimeout
(
None
)
self
.
assertEquals
(
self
.
cli
.
gettimeout
(),
42
)
...
...
@@ -1510,6 +1525,7 @@ class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
socket
.
setdefaulttimeout
(
30
)
try
:
self
.
cli
=
socket
.
create_connection
((
HOST
,
self
.
port
),
timeout
=
None
)
self
.
addCleanup
(
self
.
cli
.
close
)
finally
:
socket
.
setdefaulttimeout
(
None
)
self
.
assertEqual
(
self
.
cli
.
gettimeout
(),
None
)
...
...
@@ -1522,6 +1538,7 @@ class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
testTimeoutValueNonamed
=
_justAccept
def
_testTimeoutValueNonamed
(
self
):
self
.
cli
=
socket
.
create_connection
((
HOST
,
self
.
port
),
30
)
self
.
addCleanup
(
self
.
cli
.
close
)
self
.
assertEqual
(
self
.
cli
.
gettimeout
(),
30
)
@unittest.skipUnless
(
thread
,
'Threading required for this test.'
)
...
...
@@ -1541,6 +1558,7 @@ class NetworkConnectionBehaviourTest(SocketTCPTest, ThreadableTest):
def
testInsideTimeout
(
self
):
conn
,
addr
=
self
.
serv
.
accept
()
self
.
addCleanup
(
conn
.
close
)
time
.
sleep
(
3
)
conn
.
send
(
b
"done!"
)
testOutsideTimeout
=
testInsideTimeout
...
...
@@ -1834,6 +1852,7 @@ class ContextManagersTest(ThreadedTCPSocketTest):
def
testCreateConnectionBase
(
self
):
conn
,
addr
=
self
.
serv
.
accept
()
self
.
addCleanup
(
conn
.
close
)
data
=
conn
.
recv
(
1024
)
conn
.
sendall
(
data
)
...
...
@@ -1847,6 +1866,7 @@ class ContextManagersTest(ThreadedTCPSocketTest):
def
testCreateConnectionClose
(
self
):
conn
,
addr
=
self
.
serv
.
accept
()
self
.
addCleanup
(
conn
.
close
)
data
=
conn
.
recv
(
1024
)
conn
.
sendall
(
data
)
...
...
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