Skip to content

Commit

Permalink
upgrade pypy tests to 2.7.8
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Nov 4, 2014
1 parent 1b06377 commit 7195a76
Show file tree
Hide file tree
Showing 24 changed files with 1,368 additions and 405 deletions.
11 changes: 10 additions & 1 deletion greentest/2.7pypy/subprocessdata/sigchild_ignore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import signal, subprocess, sys
import signal, subprocess, sys, time
# On Linux this causes os.waitpid to fail with OSError as the OS has already
# reaped our child process. The wait() passing the OSError on to the caller
# and causing us to exit with an error is what we are testing against.
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
subprocess.Popen([sys.executable, '-c', 'print("albatross")']).wait()
# Also ensure poll() handles an errno.ECHILD appropriately.
p = subprocess.Popen([sys.executable, '-c', 'print("albatross")'])
num_polls = 0
while p.poll() is None:
# Waiting for the process to finish.
time.sleep(0.01) # Avoid being a CPU busy loop.
num_polls += 1
if num_polls > 3000:
raise RuntimeError('poll should have returned 0 within 30 seconds')
30 changes: 26 additions & 4 deletions greentest/2.7pypy/test_asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import time
import warnings
import errno
import struct

from test import test_support
from test.test_support import TESTFN, run_unittest, unlink
from test.test_support import TESTFN, run_unittest, unlink, HOST
from StringIO import StringIO

try:
import threading
except ImportError:
threading = None

HOST = test_support.HOST

class dummysocket:
def __init__(self):
Expand Down Expand Up @@ -483,8 +483,9 @@ def address(self):
return self.socket.getsockname()[:2]

def handle_accept(self):
sock, addr = self.accept()
self.handler(sock)
pair = self.accept()
if pair is not None:
self.handler(pair[0])

def handle_error(self):
raise
Expand Down Expand Up @@ -703,6 +704,27 @@ def test_set_reuse_addr(self):
finally:
sock.close()

@unittest.skipUnless(threading, 'Threading required for this test.')
@test_support.reap_threads
def test_quick_connect(self):
# see: http://bugs.python.org/issue10340
server = TCPServer()
t = threading.Thread(target=lambda: asyncore.loop(timeout=0.1, count=500))
t.start()
self.addCleanup(t.join)

for x in xrange(20):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(.2)
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack('ii', 1, 0))
try:
s.connect(server.address)
except socket.error:
pass
finally:
s.close()


class TestAPI_UseSelect(BaseTestAPI):
use_poll = False
Expand Down
70 changes: 50 additions & 20 deletions greentest/2.7pypy/test_ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
except ImportError:
ssl = None

from unittest import TestCase
from unittest import TestCase, SkipTest, skipUnless
from test import test_support
from test.test_support import HOST
from test.test_support import HOST, HOSTv6
threading = test_support.import_module('threading')


Expand Down Expand Up @@ -65,6 +65,7 @@ def __init__(self, conn):
self.last_received_data = ''
self.next_response = ''
self.rest = None
self.next_retr_data = RETR_DATA
self.push('220 welcome')

def collect_incoming_data(self, data):
Expand Down Expand Up @@ -189,7 +190,7 @@ def cmd_retr(self, arg):
offset = int(self.rest)
else:
offset = 0
self.dtp.push(RETR_DATA[offset:])
self.dtp.push(self.next_retr_data[offset:])
self.dtp.close_when_done()
self.rest = None

Expand All @@ -203,6 +204,11 @@ def cmd_nlst(self, arg):
self.dtp.push(NLST_DATA)
self.dtp.close_when_done()

def cmd_setlongretr(self, arg):
# For testing. Next RETR will return long line.
self.next_retr_data = 'x' * int(arg)
self.push('125 setlongretr ok')


class DummyFTPServer(asyncore.dispatcher, threading.Thread):

Expand Down Expand Up @@ -474,6 +480,14 @@ def test_mkd(self):
def test_rmd(self):
self.client.rmd('foo')

def test_cwd(self):
dir = self.client.cwd('/foo')
self.assertEqual(dir, '250 cwd ok')

def test_mkd(self):
dir = self.client.mkd('/foo')
self.assertEqual(dir, '/foo')

def test_pwd(self):
dir = self.client.pwd()
self.assertEqual(dir, 'pwd ok')
Expand Down Expand Up @@ -550,11 +564,33 @@ def test_makepasv(self):
# IPv4 is in use, just make sure send_epsv has not been used
self.assertEqual(self.server.handler.last_received_cmd, 'pasv')

def test_line_too_long(self):
self.assertRaises(ftplib.Error, self.client.sendcmd,
'x' * self.client.maxline * 2)

def test_retrlines_too_long(self):
self.client.sendcmd('SETLONGRETR %d' % (self.client.maxline * 2))
received = []
self.assertRaises(ftplib.Error,
self.client.retrlines, 'retr', received.append)

def test_storlines_too_long(self):
f = StringIO.StringIO('x' * self.client.maxline * 2)
self.assertRaises(ftplib.Error, self.client.storlines, 'stor', f)


@skipUnless(socket.has_ipv6, "IPv6 not enabled")
class TestIPv6Environment(TestCase):

@classmethod
def setUpClass(cls):
try:
DummyFTPServer((HOST, 0), af=socket.AF_INET6)
except socket.error:
raise SkipTest("IPv6 not enabled")

def setUp(self):
self.server = DummyFTPServer((HOST, 0), af=socket.AF_INET6)
self.server = DummyFTPServer((HOSTv6, 0), af=socket.AF_INET6)
self.server.start()
self.client = ftplib.FTP()
self.client.connect(self.server.host, self.server.port)
Expand Down Expand Up @@ -587,6 +623,7 @@ def retr():
retr()


@skipUnless(ssl, "SSL not available")
class TestTLS_FTPClassMixin(TestFTPClass):
"""Repeat TestFTPClass tests starting the TLS layer for both control
and data connections first.
Expand All @@ -602,6 +639,7 @@ def setUp(self):
self.client.prot_p()


@skipUnless(ssl, "SSL not available")
class TestTLS_FTPClass(TestCase):
"""Specific TLS_FTP class tests."""

Expand Down Expand Up @@ -702,10 +740,10 @@ def server(self, evt, serv):

def testTimeoutDefault(self):
# default -- use global socket timeout
self.assertTrue(socket.getdefaulttimeout() is None)
self.assertIsNone(socket.getdefaulttimeout())
socket.setdefaulttimeout(30)
try:
ftp = ftplib.FTP("localhost")
ftp = ftplib.FTP(HOST)
finally:
socket.setdefaulttimeout(None)
self.assertEqual(ftp.sock.gettimeout(), 30)
Expand All @@ -714,13 +752,13 @@ def testTimeoutDefault(self):

def testTimeoutNone(self):
# no timeout -- do not use global socket timeout
self.assertTrue(socket.getdefaulttimeout() is None)
self.assertIsNone(socket.getdefaulttimeout())
socket.setdefaulttimeout(30)
try:
ftp = ftplib.FTP("localhost", timeout=None)
ftp = ftplib.FTP(HOST, timeout=None)
finally:
socket.setdefaulttimeout(None)
self.assertTrue(ftp.sock.gettimeout() is None)
self.assertIsNone(ftp.sock.gettimeout())
self.evt.wait()
ftp.close()

Expand Down Expand Up @@ -755,17 +793,9 @@ def testTimeoutDirectAccess(self):


def test_main():
tests = [TestFTPClass, TestTimeouts]
if socket.has_ipv6:
try:
DummyFTPServer((HOST, 0), af=socket.AF_INET6)
except socket.error:
pass
else:
tests.append(TestIPv6Environment)

if ssl is not None:
tests.extend([TestTLS_FTPClassMixin, TestTLS_FTPClass])
tests = [TestFTPClass, TestTimeouts,
TestIPv6Environment,
TestTLS_FTPClassMixin, TestTLS_FTPClass]

thread_info = test_support.threading_setup()
try:
Expand Down
Loading

0 comments on commit 7195a76

Please sign in to comment.