@@ -55,15 +55,15 @@ def setUp(self):
55
55
# Process opens a UNIX socket to /var/log/run.
56
56
return
57
57
cons = thisproc .connections (kind = 'all' )
58
- assert not cons , cons
58
+ self . assertEqual ( cons , [])
59
59
60
60
def tearDown (self ):
61
61
# Make sure we closed all resources.
62
62
# Some BSDs open a UNIX socket to /var/log/run.
63
63
if NETBSD or FREEBSD or (MACOS and not PY3 ):
64
64
return
65
65
cons = thisproc .connections (kind = 'all' )
66
- assert not cons , cons
66
+ self . assertEqual ( cons , [])
67
67
68
68
def compare_procsys_connections (self , pid , proc_cons , kind = 'all' ):
69
69
"""Given a process PID and its list of connections compare
@@ -156,46 +156,46 @@ def test_tcp_v4(self):
156
156
addr = ("127.0.0.1" , 0 )
157
157
with closing (bind_socket (AF_INET , SOCK_STREAM , addr = addr )) as sock :
158
158
conn = self .check_socket (sock )
159
- assert not conn .raddr
159
+ self . assertEqual ( conn .raddr , ())
160
160
self .assertEqual (conn .status , psutil .CONN_LISTEN )
161
161
162
162
@unittest .skipIf (not supports_ipv6 (), "IPv6 not supported" )
163
163
def test_tcp_v6 (self ):
164
164
addr = ("::1" , 0 )
165
165
with closing (bind_socket (AF_INET6 , SOCK_STREAM , addr = addr )) as sock :
166
166
conn = self .check_socket (sock )
167
- assert not conn .raddr
167
+ self . assertEqual ( conn .raddr , ())
168
168
self .assertEqual (conn .status , psutil .CONN_LISTEN )
169
169
170
170
def test_udp_v4 (self ):
171
171
addr = ("127.0.0.1" , 0 )
172
172
with closing (bind_socket (AF_INET , SOCK_DGRAM , addr = addr )) as sock :
173
173
conn = self .check_socket (sock )
174
- assert not conn .raddr
174
+ self . assertEqual ( conn .raddr , ())
175
175
self .assertEqual (conn .status , psutil .CONN_NONE )
176
176
177
177
@unittest .skipIf (not supports_ipv6 (), "IPv6 not supported" )
178
178
def test_udp_v6 (self ):
179
179
addr = ("::1" , 0 )
180
180
with closing (bind_socket (AF_INET6 , SOCK_DGRAM , addr = addr )) as sock :
181
181
conn = self .check_socket (sock )
182
- assert not conn .raddr
182
+ self . assertEqual ( conn .raddr , ())
183
183
self .assertEqual (conn .status , psutil .CONN_NONE )
184
184
185
185
@unittest .skipIf (not POSIX , 'POSIX only' )
186
186
def test_unix_tcp (self ):
187
187
testfn = self .get_testfn ()
188
188
with closing (bind_unix_socket (testfn , type = SOCK_STREAM )) as sock :
189
189
conn = self .check_socket (sock )
190
- assert not conn .raddr
190
+ self . assertEqual ( conn .raddr , "" )
191
191
self .assertEqual (conn .status , psutil .CONN_NONE )
192
192
193
193
@unittest .skipIf (not POSIX , 'POSIX only' )
194
194
def test_unix_udp (self ):
195
195
testfn = self .get_testfn ()
196
196
with closing (bind_unix_socket (testfn , type = SOCK_STREAM )) as sock :
197
197
conn = self .check_socket (sock )
198
- assert not conn .raddr
198
+ self . assertEqual ( conn .raddr , "" )
199
199
self .assertEqual (conn .status , psutil .CONN_NONE )
200
200
201
201
@@ -210,7 +210,7 @@ class TestConnectedSocket(ConnectionTestCase):
210
210
@unittest .skipIf (SUNOS , "unreliable on SUONS" )
211
211
def test_tcp (self ):
212
212
addr = ("127.0.0.1" , 0 )
213
- assert not thisproc .connections (kind = 'tcp4' )
213
+ self . assertEqual ( thisproc .connections (kind = 'tcp4' ), [] )
214
214
server , client = tcp_socketpair (AF_INET , addr = addr )
215
215
try :
216
216
cons = thisproc .connections (kind = 'tcp4' )
@@ -233,8 +233,8 @@ def test_unix(self):
233
233
server , client = unix_socketpair (testfn )
234
234
try :
235
235
cons = thisproc .connections (kind = 'unix' )
236
- assert not (cons [0 ].laddr and cons [0 ].raddr )
237
- assert not (cons [1 ].laddr and cons [1 ].raddr )
236
+ assert not (cons [0 ].laddr and cons [0 ].raddr ), cons
237
+ assert not (cons [1 ].laddr and cons [1 ].raddr ), cons
238
238
if NETBSD or FREEBSD :
239
239
# On NetBSD creating a UNIX socket will cause
240
240
# a UNIX connection to /var/run/log.
@@ -313,9 +313,9 @@ def check_conn(proc, conn, family, type, laddr, raddr, status, kinds):
313
313
for kind in all_kinds :
314
314
cons = proc .connections (kind = kind )
315
315
if kind in kinds :
316
- assert cons
316
+ self . assertNotEqual ( cons , [])
317
317
else :
318
- assert not cons , cons
318
+ self . assertEqual ( cons , [])
319
319
# compare against system-wide connections
320
320
# XXX Solaris can't retrieve system-wide UNIX
321
321
# sockets.
0 commit comments