Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r82049:babeead98057
Date: 2016-02-02 17:10 +0000
http://bitbucket.org/pypy/pypy/changeset/babeead98057/
Log: Make apptests more 3-friendly
diff --git a/pypy/module/_socket/test/test_sock_app.py
b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -102,7 +102,7 @@
fd = space.appexec([w_socket, space.wrap(orig_fd.fileno()),
space.wrap(socket.AF_INET), space.wrap(socket.SOCK_STREAM),
space.wrap(0)],
- """(_socket, fd, family, type, proto):
+ """(_socket, fd, family, type, proto):
return _socket.fromfd(fd, family, type, proto)""")
assert space.unwrap(space.call_method(fd, 'fileno'))
@@ -326,7 +326,7 @@
def test_ntoa_exception(self):
import _socket
- raises(_socket.error, _socket.inet_ntoa, "ab")
+ raises(_socket.error, _socket.inet_ntoa, b"ab")
def test_aton_exceptions(self):
import _socket
@@ -418,7 +418,7 @@
# it if there is no connection.
try:
s.connect(("www.python.org", 80))
- except _socket.gaierror, ex:
+ except _socket.gaierror as ex:
skip("GAIError - probably no connection: %s" % str(ex.args))
name = s.getpeername() # Will raise socket.error if not connected
assert name[1] == 80
@@ -465,7 +465,7 @@
sizes = {socket.htonl: 32, socket.ntohl: 32,
socket.htons: 16, socket.ntohs: 16}
for func, size in sizes.items():
- mask = (1L<<size) - 1
+ mask = (1 << size) - 1
for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210):
assert i & mask == func(func(i&mask)) & mask
@@ -493,7 +493,7 @@
socket.htons: 16, socket.ntohs: 16}
for func, size in sizes.items():
try:
- func(1L << size)
+ func(1 << size)
except OverflowError:
pass
else:
@@ -574,7 +574,7 @@
# connection.
try:
s.connect(("www.python.org", 80))
- except _socket.gaierror, ex:
+ except _socket.gaierror as ex:
skip("GAIError - probably no connection: %s" % str(ex.args))
exc = raises(TypeError, s.send, None)
assert str(exc.value) == "must be string or buffer, not None"
@@ -608,12 +608,12 @@
s, addr = serversock.accept()
assert not addr
- s.send('X')
+ s.send(b'X')
data = clientsock.recv(100)
- assert data == 'X'
- clientsock.send('Y')
+ assert data == b'X'
+ clientsock.send(b'Y')
data = s.recv(100)
- assert data == 'Y'
+ assert data == b'Y'
clientsock.close()
s.close()
@@ -640,12 +640,12 @@
def test_connect_to_kernel_netlink_routing_socket(self):
import _socket, os
s = _socket.socket(_socket.AF_NETLINK, _socket.SOCK_DGRAM,
_socket.NETLINK_ROUTE)
- assert s.getsockname() == (0L, 0L)
+ assert s.getsockname() == (0, 0)
s.bind((0, 0))
a, b = s.getsockname()
assert a == os.getpid()
assert b == 0
-
+
class AppTestPacket:
def setup_class(cls):
@@ -711,20 +711,20 @@
t, addr = self.serv.accept()
cli.settimeout(1.0)
# test recv() timeout
- t.send('*')
+ t.send(b'*')
buf = cli.recv(100)
- assert buf == '*'
+ assert buf == b'*'
raises(timeout, cli.recv, 100)
# test that send() works
- count = cli.send('!')
+ count = cli.send(b'!')
assert count == 1
buf = t.recv(1)
- assert buf == '!'
+ assert buf == b'!'
# test that sendall() works
- count = cli.sendall('?')
+ count = cli.sendall(b'?')
assert count is None
buf = t.recv(1)
- assert buf == '?'
+ assert buf == b'?'
# speed up filling the buffers
t.setsockopt(SOL_SOCKET, SO_RCVBUF, 4096)
cli.setsockopt(SOL_SOCKET, SO_SNDBUF, 4096)
@@ -732,14 +732,14 @@
count = 0
try:
while 1:
- count += cli.send('foobar' * 70)
+ count += cli.send(b'foobar' * 70)
except timeout:
pass
t.recv(count)
# test sendall() timeout
try:
while 1:
- cli.sendall('foobar' * 70)
+ cli.sendall(b'foobar' * 70)
except timeout:
pass
# done
@@ -749,13 +749,13 @@
def test_recv_into(self):
import socket
import array
- MSG = 'dupa was here\n'
+ MSG = b'dupa was here\n'
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cli.connect(self.serv.getsockname())
conn, addr = self.serv.accept()
buf = buffer(MSG)
conn.send(buf)
- buf = array.array('c', ' ' * 1024)
+ buf = array.array('b', b' ' * 1024)
nbytes = cli.recv_into(buf)
assert nbytes == len(MSG)
msg = buf.tostring()[:len(MSG)]
@@ -771,13 +771,13 @@
def test_recvfrom_into(self):
import socket
import array
- MSG = 'dupa was here\n'
+ MSG = b'dupa was here\n'
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cli.connect(self.serv.getsockname())
conn, addr = self.serv.accept()
buf = buffer(MSG)
conn.send(buf)
- buf = array.array('c', ' ' * 1024)
+ buf = array.array('b', b' ' * 1024)
nbytes, addr = cli.recvfrom_into(buf)
assert nbytes == len(MSG)
msg = buf.tostring()[:len(MSG)]
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit