mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
(Merge 3.4) asynchat: PEP8-ify the code
This commit is contained in:
commit
7b9328f51b
2 changed files with 68 additions and 57 deletions
|
@ -5,9 +5,12 @@ from test import support
|
|||
# If this fails, the test will be skipped.
|
||||
thread = support.import_module('_thread')
|
||||
|
||||
import asyncore, asynchat, socket, time
|
||||
import unittest
|
||||
import asynchat
|
||||
import asyncore
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
import warnings
|
||||
try:
|
||||
import threading
|
||||
|
@ -29,8 +32,8 @@ if threading:
|
|||
self.event = event
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.port = support.bind_port(self.sock)
|
||||
# This will be set if the client wants us to wait before echoing data
|
||||
# back.
|
||||
# This will be set if the client wants us to wait before echoing
|
||||
# data back.
|
||||
self.start_resend_event = None
|
||||
|
||||
def run(self):
|
||||
|
@ -53,8 +56,8 @@ if threading:
|
|||
|
||||
# re-send entire set of collected data
|
||||
try:
|
||||
# this may fail on some tests, such as test_close_when_done, since
|
||||
# the client closes the channel when it's done sending
|
||||
# this may fail on some tests, such as test_close_when_done,
|
||||
# since the client closes the channel when it's done sending
|
||||
while self.buffer:
|
||||
n = conn.send(self.buffer[:self.chunk_size])
|
||||
time.sleep(0.001)
|
||||
|
@ -97,7 +100,7 @@ if threading:
|
|||
s.start()
|
||||
event.wait()
|
||||
event.clear()
|
||||
time.sleep(0.01) # Give server time to start accepting.
|
||||
time.sleep(0.01) # Give server time to start accepting.
|
||||
return s, event
|
||||
|
||||
|
||||
|
@ -105,10 +108,10 @@ if threading:
|
|||
class TestAsynchat(unittest.TestCase):
|
||||
usepoll = False
|
||||
|
||||
def setUp (self):
|
||||
def setUp(self):
|
||||
self._threads = support.threading_setup()
|
||||
|
||||
def tearDown (self):
|
||||
def tearDown(self):
|
||||
support.threading_cleanup(*self._threads)
|
||||
|
||||
def line_terminator_check(self, term, server_chunk):
|
||||
|
@ -118,7 +121,7 @@ class TestAsynchat(unittest.TestCase):
|
|||
s.start()
|
||||
event.wait()
|
||||
event.clear()
|
||||
time.sleep(0.01) # Give server time to start accepting.
|
||||
time.sleep(0.01) # Give server time to start accepting.
|
||||
c = echo_client(term, s.port)
|
||||
c.push(b"hello ")
|
||||
c.push(b"world" + term)
|
||||
|
@ -137,17 +140,17 @@ class TestAsynchat(unittest.TestCase):
|
|||
|
||||
def test_line_terminator1(self):
|
||||
# test one-character terminator
|
||||
for l in (1,2,3):
|
||||
for l in (1, 2, 3):
|
||||
self.line_terminator_check(b'\n', l)
|
||||
|
||||
def test_line_terminator2(self):
|
||||
# test two-character terminator
|
||||
for l in (1,2,3):
|
||||
for l in (1, 2, 3):
|
||||
self.line_terminator_check(b'\r\n', l)
|
||||
|
||||
def test_line_terminator3(self):
|
||||
# test three-character terminator
|
||||
for l in (1,2,3):
|
||||
for l in (1, 2, 3):
|
||||
self.line_terminator_check(b'qqq', l)
|
||||
|
||||
def numeric_terminator_check(self, termlen):
|
||||
|
@ -270,11 +273,13 @@ class TestAsynchat(unittest.TestCase):
|
|||
class TestAsynchat_WithPoll(TestAsynchat):
|
||||
usepoll = True
|
||||
|
||||
|
||||
class TestHelperFunctions(unittest.TestCase):
|
||||
def test_find_prefix_at_end(self):
|
||||
self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1)
|
||||
self.assertEqual(asynchat.find_prefix_at_end("qwertydkjf", "\r\n"), 0)
|
||||
|
||||
|
||||
class TestFifo(unittest.TestCase):
|
||||
def test_basic(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue