Commit 0d4c06e0 authored by Neal Norwitz's avatar Neal Norwitz

Whitespace normalization. Ugh, we really need to do this more often.

You might want to review this change as it's my first time.  Be gentle. :-)
parent e47c5088
......@@ -234,7 +234,7 @@ c_voidp = c_void_p # backwards compatibility (to a bug)
_check_size(c_void_p)
class c_bool(_SimpleCData):
_type_ = "t"
_type_ = "t"
# This cache maps types to pointers to them.
_pointer_type_cache = {}
......
......@@ -69,7 +69,7 @@ class NumberTestCase(unittest.TestCase):
for t, (l, h) in zip(signed_types, signed_ranges):
self.failUnlessEqual(t(l).value, l)
self.failUnlessEqual(t(h).value, h)
def test_bool_values(self):
from operator import truth
for t, v in zip(bool_types, bool_values):
......@@ -178,7 +178,7 @@ class NumberTestCase(unittest.TestCase):
a[0] = '?'
self.failUnlessEqual(v.value, a[0])
# array does not support c_bool / 't'
# def test_bool_from_address(self):
# from ctypes import c_bool
......
......@@ -2631,7 +2631,7 @@ class Context(object):
1) before use.
If the increased precision needed for the intermediate calculations
exceeds the capabilities of the implementation then an Invalid
exceeds the capabilities of the implementation then an Invalid
operation condition is raised.
If, when raising to a negative power, an underflow occurs during the
......@@ -2725,7 +2725,7 @@ class Context(object):
The result is the residue of the dividend after the operation of
calculating integer division as described for divide-integer, rounded
to precision digits if necessary. The sign of the result, if
to precision digits if necessary. The sign of the result, if
non-zero, is the same as that of the original dividend.
This operation will fail under the same conditions as integer division
......@@ -2929,7 +2929,7 @@ def _normalize(op1, op2, shouldround = 0, prec = 0):
if numdigits > (other_len + prec + 1 - tmp_len):
# If the difference in adjusted exps is > prec+1, we know
# other is insignificant, so might as well put a 1 after the
# precision (since this is only for addition). Also stops
# precision (since this is only for addition). Also stops
# use of massive longs.
extend = prec + 2 - tmp_len
......@@ -3098,7 +3098,7 @@ del re
def _string2exact(s):
"""Return sign, n, p s.t.
Float string value == -1**sign * n * 10**p exactly
"""
m = _parser(s)
......
......@@ -84,7 +84,7 @@ class FTP:
meaning that no timeout will be set on any ftp socket(s)
If a timeout is passed, then this is now the default timeout for all ftp
socket operations for this instance.
Then use self.connect() with optional host and port argument.
To download a file, use ftp.retrlines('RETR ' + filename),
......@@ -112,7 +112,7 @@ class FTP:
self.timeout = timeout
if host:
self.connect(host)
if user:
if user:
self.login(user, passwd, acct)
def connect(self, host='', port=0, timeout=None):
......
......@@ -1149,7 +1149,7 @@ see no sign that the breakpoint was reached.
def _runscript(self, filename):
# The script has to run in __main__ namespace (or imports from
# __main__ will break).
#
#
# So we clear up the __main__ and set several special variables
# (this gets rid of pdb's globals and cleans old variables on restarts).
import __main__
......@@ -1158,7 +1158,7 @@ see no sign that the breakpoint was reached.
"__file__" : filename,
"__builtins__": __builtins__,
})
# When bdb sets tracing, a number of call and line events happens
# BEFORE debugger even reaches user's code (and the exact sequence of
# events depends on python version). So we take special measures to
......@@ -1168,7 +1168,7 @@ see no sign that the breakpoint was reached.
self.mainpyfile = self.canonic(filename)
self._user_requested_quit = 0
statement = 'execfile( "%s")' % filename
self.run(statement)
self.run(statement)
# Simplified interface
......
......@@ -388,10 +388,10 @@ def relpath(path, start=curdir):
if not path:
raise ValueError("no path specified")
start_list = abspath(start).split(sep)
path_list = abspath(path).split(sep)
# Work out how much of the filepath is shared by start and path.
i = len(commonprefix([start_list, path_list]))
......
......@@ -24,7 +24,7 @@ inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
ssl() -- secure socket layer support (only available if configured)
socket.getdefaulttimeout() -- get the default timeout value
socket.setdefaulttimeout() -- set the default timeout value
create_connection() -- connects to an address, with an optional timeout
create_connection() -- connects to an address, with an optional timeout
[*] not available on all platforms!
......@@ -418,12 +418,12 @@ class _fileobject(object):
def create_connection(address, timeout=None):
"""Connect to address (host, port) with an optional timeout.
Provides access to socketobject timeout for higher-level
protocols. Passing a timeout will set the timeout on the
Provides access to socketobject timeout for higher-level
protocols. Passing a timeout will set the timeout on the
socket instance (if not present, or passed as None, the
default global timeout setting will be used).
"""
msg = "getaddrinfo returns an empty list"
host, port = address
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
......@@ -435,7 +435,7 @@ def create_connection(address, timeout=None):
sock.settimeout(timeout)
sock.connect(sa)
return sock
except error, msg:
if sock is not None:
sock.close()
......
......@@ -38,9 +38,9 @@ if _os.name == 'mac':
import Carbon.Folders as _Folders
try:
from cStringIO import StringIO as _StringIO
from cStringIO import StringIO as _StringIO
except:
from StringIO import StringIO as _StringIO
from StringIO import StringIO as _StringIO
try:
import fcntl as _fcntl
......@@ -510,7 +510,7 @@ class SpooledTemporaryFile:
newfile.seek(file.tell(), 0)
self._rolled = True
# file protocol
def __iter__(self):
return self._file.__iter__()
......
......@@ -44,7 +44,7 @@ class TestDifflibLongestMatch(unittest.TestCase):
self.assertEquals(i, l)
self.assertEquals(aptr, 1)
self.assertEquals(bptr, 0)
def test_main():
test_support.run_unittest(TestDifflibLongestMatch)
......
......@@ -1096,9 +1096,9 @@ class MixinStrStringUserStringTest:
self.checkequal('Abc', 'abc', 'translate', table)
self.checkequal('xyz', 'xyz', 'translate', table)
self.checkequal('yz', 'xyz', 'translate', table, 'x')
self.checkequal('yx', 'zyzzx', 'translate', None, 'z')
self.checkequal('yx', 'zyzzx', 'translate', None, 'z')
self.checkequal('zyzzx', 'zyzzx', 'translate', None, '')
self.checkequal('zyzzx', 'zyzzx', 'translate', None)
self.checkequal('zyzzx', 'zyzzx', 'translate', None)
self.checkraises(ValueError, 'xyz', 'translate', 'too short', 'strip')
self.checkraises(ValueError, 'xyz', 'translate', 'too short')
......
......@@ -1248,7 +1248,7 @@ def slots():
c.abc = 5
vereq(c.abc, 5)
# _unicode_to_string used to modify slots in certain circumstances
# _unicode_to_string used to modify slots in certain circumstances
slots = (unicode("foo"), unicode("bar"))
class C(object):
__slots__ = slots
......@@ -1263,7 +1263,7 @@ def slots():
except (TypeError, UnicodeEncodeError):
pass
else:
raise TestFailed, "[unichr(128)] slots not caught"
raise TestFailed, "[unichr(128)] slots not caught"
# Test leaks
class Counted(object):
......
......@@ -27,7 +27,7 @@ def writeTmp(i, lines, mode='w'): # opening in text mode is the default
def remove_tempfiles(*names):
for name in names:
safe_unlink(name)
class BufferSizesTests(unittest.TestCase):
def test_buffer_sizes(self):
# First, run the tests with default and teeny buffer size.
......@@ -40,10 +40,10 @@ class BufferSizesTests(unittest.TestCase):
self.buffer_size_test(t1, t2, t3, t4, bs, round)
finally:
remove_tempfiles(t1, t2, t3, t4)
def buffer_size_test(self, t1, t2, t3, t4, bs=0, round=0):
pat = re.compile(r'LINE (\d+) OF FILE (\d+)')
start = 1 + round*6
if verbose:
print '%s. Simple iteration (bs=%s)' % (start+0, bs)
......@@ -117,7 +117,7 @@ class BufferSizesTests(unittest.TestCase):
self.assertNotEqual(m, None)
self.assertEqual(int(m.group(1)), fi.filelineno())
fi.close()
class FileInputTests(unittest.TestCase):
def test_zero_byte_files(self):
try:
......@@ -126,13 +126,13 @@ class FileInputTests(unittest.TestCase):
t3 = writeTmp(3, ["The only line there is.\n"])
t4 = writeTmp(4, [""])
fi = FileInput(files=(t1, t2, t3, t4))
line = fi.readline()
self.assertEqual(line, 'The only line there is.\n')
self.assertEqual(fi.lineno(), 1)
self.assertEqual(fi.filelineno(), 1)
self.assertEqual(fi.filename(), t3)
line = fi.readline()
self.failIf(line)
self.assertEqual(fi.lineno(), 1)
......@@ -220,6 +220,6 @@ class FileInputTests(unittest.TestCase):
def test_main():
run_unittest(BufferSizesTests, FileInputTests)
if __name__ == "__main__":
test_main()
......@@ -24,7 +24,7 @@ def server(evt):
evt.set()
class GeneralTests(TestCase):
def setUp(self):
ftplib.FTP.port = 9091
self.evt = threading.Event()
......@@ -41,13 +41,13 @@ class GeneralTests(TestCase):
# connects
ftp = ftplib.FTP("localhost")
ftp.sock.close()
def testTimeoutDefault(self):
# default
ftp = ftplib.FTP("localhost")
self.assertTrue(ftp.sock.gettimeout() is None)
ftp.sock.close()
def testTimeoutValue(self):
# a value
ftp = ftplib.FTP("localhost", timeout=30)
......
......@@ -6,7 +6,7 @@ import weakref
### Support code
###############################################################################
# Bug 1055820 has several tests of longstanding bugs involving weakrefs and
# cyclic gc.
......@@ -32,9 +32,9 @@ class GC_Detector(object):
self.wr = weakref.ref(C1055820(666), it_happened)
### Tests
### Tests
###############################################################################
class GCTests(unittest.TestCase):
def test_list(self):
l = []
......@@ -259,7 +259,7 @@ class GCTests(unittest.TestCase):
Ouch.n = Ouch.n + 1
if Ouch.n % 17 == 0:
gc.collect()
# "trashcan" is a hack to prevent stack overflow when deallocating
# very deeply nested tuples etc. It works in part by abusing the
# type pointer and refcount fields, and that can yield horrible
......@@ -292,7 +292,7 @@ class GCTests(unittest.TestCase):
def __getattr__(self, someattribute):
del self.attr
raise AttributeError
a = Boom()
b = Boom()
a.attr = b
......@@ -321,7 +321,7 @@ class GCTests(unittest.TestCase):
if self.x > 1:
del self.attr
raise AttributeError
a = Boom2()
b = Boom2()
a.attr = b
......@@ -346,7 +346,7 @@ class GCTests(unittest.TestCase):
def __getattr__(self, someattribute):
del self.attr
raise AttributeError
a = Boom_New()
b = Boom_New()
a.attr = b
......@@ -368,7 +368,7 @@ class GCTests(unittest.TestCase):
if self.x > 1:
del self.attr
raise AttributeError
a = Boom2_New()
b = Boom2_New()
a.attr = b
......@@ -430,10 +430,10 @@ class GCTests(unittest.TestCase):
class GCTogglingTests(unittest.TestCase):
def setUp(self):
gc.enable()
def tearDown(self):
gc.disable()
def test_bug1055820c(self):
# Corresponds to temp2c.py in the bug report. This is pretty
# elaborate.
......@@ -591,6 +591,6 @@ def test_main():
assert gc.isenabled()
if not enabled:
gc.disable()
if __name__ == "__main__":
test_main()
......@@ -15,15 +15,15 @@ class GetoptTests(unittest.TestCase):
if self.old_posixly_correct is not sentinel:
del os.environ["POSIXLY_CORRECT"]
def tearDown(self):
def tearDown(self):
if self.old_posixly_correct is sentinel:
os.environ.pop("POSIXLY_CORRECT", None)
else:
os.environ["POSIXLY_CORRECT"] = self.old_posixly_correct
def assertError(self, *args, **kwargs):
self.assertRaises(getopt.GetoptError, *args, **kwargs)
def test_short_has_arg(self):
self.failUnless(getopt.short_has_arg('a', 'a:'))
self.failIf(getopt.short_has_arg('a', 'a'))
......@@ -33,15 +33,15 @@ class GetoptTests(unittest.TestCase):
has_arg, option = getopt.long_has_args('abc', ['abc='])
self.failUnless(has_arg)
self.assertEqual(option, 'abc')
has_arg, option = getopt.long_has_args('abc', ['abc'])
self.failIf(has_arg)
self.assertEqual(option, 'abc')
has_arg, option = getopt.long_has_args('abc', ['abcd'])
self.failIf(has_arg)
self.assertEqual(option, 'abcd')
self.assertError(getopt.long_has_args, 'abc', ['def'])
self.assertError(getopt.long_has_args, 'abc', [])
self.assertError(getopt.long_has_args, 'abc', ['abcd','abcde'])
......@@ -50,23 +50,23 @@ class GetoptTests(unittest.TestCase):
opts, args = getopt.do_shorts([], 'a', 'a', [])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, [])
opts, args = getopt.do_shorts([], 'a1', 'a:', [])
self.assertEqual(opts, [('-a', '1')])
self.assertEqual(args, [])
#opts, args = getopt.do_shorts([], 'a=1', 'a:', [])
#self.assertEqual(opts, [('-a', '1')])
#self.assertEqual(args, [])
opts, args = getopt.do_shorts([], 'a', 'a:', ['1'])
self.assertEqual(opts, [('-a', '1')])
self.assertEqual(args, [])
opts, args = getopt.do_shorts([], 'a', 'a:', ['1', '2'])
self.assertEqual(opts, [('-a', '1')])
self.assertEqual(args, ['2'])
self.assertError(getopt.do_shorts, [], 'a1', 'a', [])
self.assertError(getopt.do_shorts, [], 'a', 'a:', [])
......@@ -74,26 +74,26 @@ class GetoptTests(unittest.TestCase):
opts, args = getopt.do_longs([], 'abc', ['abc'], [])
self.assertEqual(opts, [('--abc', '')])
self.assertEqual(args, [])
opts, args = getopt.do_longs([], 'abc=1', ['abc='], [])
self.assertEqual(opts, [('--abc', '1')])
self.assertEqual(args, [])
opts, args = getopt.do_longs([], 'abc=1', ['abcd='], [])
self.assertEqual(opts, [('--abcd', '1')])
self.assertEqual(args, [])
opts, args = getopt.do_longs([], 'abc', ['ab', 'abc', 'abcd'], [])
self.assertEqual(opts, [('--abc', '')])
self.assertEqual(args, [])
# Much like the preceding, except with a non-alpha character ("-") in
# option name that precedes "="; failed in
# http://python.org/sf/126863
opts, args = getopt.do_longs([], 'foo=42', ['foo-bar', 'foo=',], [])
self.assertEqual(opts, [('--foo', '42')])
self.assertEqual(args, [])
self.assertError(getopt.do_longs, [], 'abc=1', ['abc'], [])
self.assertError(getopt.do_longs, [], 'abc', ['abc='], [])
......@@ -117,18 +117,18 @@ class GetoptTests(unittest.TestCase):
def test_gnu_getopt(self):
# Test handling of GNU style scanning mode.
cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
# GNU style
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg1'])
self.assertEqual(opts, [('-a', ''), ('-b', '1'),
('--alpha', ''), ('--beta', '2')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
# Posix style via POSIXLY_CORRECT
os.environ["POSIXLY_CORRECT"] = "1"
opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
......@@ -166,7 +166,7 @@ class GetoptTests(unittest.TestCase):
>>> args
['a1', 'a2']
"""
import new
m = new.module("libreftest", s)
run_doctest(m, verbose)
......@@ -174,6 +174,6 @@ class GetoptTests(unittest.TestCase):
def test_main():
run_unittest(GetoptTests)
if __name__ == "__main__":
test_main()
......@@ -154,7 +154,7 @@ PORT = 50003
HOST = "localhost"
class TimeoutTest(TestCase):
def setUp(self):
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
......@@ -175,7 +175,7 @@ class TimeoutTest(TestCase):
httpConn.connect()
self.assertTrue(httpConn.sock.gettimeout() is None)
httpConn.close()
# a value
httpConn = httplib.HTTPConnection(HOST, PORT, timeout=30)
httpConn.connect()
......
......@@ -50,6 +50,6 @@ class TrueDivisionTests(unittest.TestCase):
def test_main():
run_unittest(TrueDivisionTests)
if __name__ == "__main__":
test_main()
This diff is collapsed.
......@@ -56,6 +56,6 @@ class ModuleTests(unittest.TestCase):
def test_main():
run_unittest(ModuleTests)
if __name__ == '__main__':
test_main()
......@@ -29,7 +29,7 @@ def unistr(data):
if x > sys.maxunicode:
raise RangeError
return u"".join([unichr(x) for x in data])
class NormalizationTest(unittest.TestCase):
def test_main(self):
part1_data = {}
......
......@@ -281,7 +281,7 @@ class WalkTests(unittest.TestCase):
from os.path import join
# Build:
# TESTFN/
# TESTFN/
# TEST1/ a file kid and two directory kids
# tmp1
# SUB1/ a file kid and a directory kid
......
......@@ -45,7 +45,7 @@ class Popen2Test(unittest.TestCase):
inst.wait()
popen2._cleanup()
self.assertFalse(popen2._active, "_active not empty")
reap_children()
reap_children()
def validate_output(self, teststr, expected_out, r, w, e=None):
w.write(teststr)
......@@ -57,7 +57,7 @@ class Popen2Test(unittest.TestCase):
if e is not None:
got = e.read()
self.assertFalse(got, "unexpected %r on stderr" % got)
def test_popen2(self):
r, w = popen2.popen2(self.cmd)
self.validate_output(self.teststr, self.expected, r, w)
......@@ -84,7 +84,7 @@ class Popen2Test(unittest.TestCase):
w, r, e = os.popen3(self.cmd)
self.validate_output(self.teststr, self.expected, r, w, e)
def test_main():
run_unittest(Popen2Test)
......
......@@ -25,7 +25,7 @@ def server(evt):
evt.set()
class GeneralTests(TestCase):
def setUp(self):
self.evt = threading.Event()
threading.Thread(target=server, args=(self.evt,)).start()
......@@ -38,13 +38,13 @@ class GeneralTests(TestCase):
# connects
pop = poplib.POP3("localhost", 9091)
pop.sock.close()
def testTimeoutDefault(self):
# default
pop = poplib.POP3("localhost", 9091)
self.assertTrue(pop.sock.gettimeout() is None)
pop.sock.close()
def testTimeoutValue(self):
# a value
pop = poplib.POP3("localhost", 9091, timeout=30)
......
......@@ -19,12 +19,12 @@ class SetAttributeTest(unittest.TestCase):
[2, 1],
[0, 0],
]
def test_returns_unicode(self):
for x, y in self.set_get_pairs:
self.parser.returns_unicode = x
self.assertEquals(self.parser.returns_unicode, y)
def test_ordered_attributes(self):
for x, y in self.set_get_pairs:
self.parser.ordered_attributes = x
......@@ -64,57 +64,57 @@ class ParseTest(unittest.TestCase):
class Outputter:
def __init__(self):
self.out = []
def StartElementHandler(self, name, attrs):
self.out.append('Start element: ' + repr(name) + ' ' +
self.out.append('Start element: ' + repr(name) + ' ' +
sortdict(attrs))
def EndElementHandler(self, name):
self.out.append('End element: ' + repr(name))
def CharacterDataHandler(self, data):
data = data.strip()
if data:
self.out.append('Character data: ' + repr(data))
def ProcessingInstructionHandler(self, target, data):
self.out.append('PI: ' + repr(target) + ' ' + repr(data))
def StartNamespaceDeclHandler(self, prefix, uri):
self.out.append('NS decl: ' + repr(prefix) + ' ' + repr(uri))
def EndNamespaceDeclHandler(self, prefix):
self.out.append('End of NS decl: ' + repr(prefix))
def StartCdataSectionHandler(self):
self.out.append('Start of CDATA section')
def EndCdataSectionHandler(self):
self.out.append('End of CDATA section')
def CommentHandler(self, text):
self.out.append('Comment: ' + repr(text))
def NotationDeclHandler(self, *args):
name, base, sysid, pubid = args
self.out.append('Notation declared: %s' %(args,))
def UnparsedEntityDeclHandler(self, *args):
entityName, base, systemId, publicId, notationName = args
self.out.append('Unparsed entity decl: %s' %(args,))
def NotStandaloneHandler(self, userData):
self.out.append('Not standalone')
return 1
def ExternalEntityRefHandler(self, *args):
context, base, sysId, pubId = args
self.out.append('External entity ref: %s' %(args[1:],))
return 1
def DefaultHandler(self, userData):
pass
def DefaultHandlerExpand(self, userData):
pass
......@@ -129,7 +129,7 @@ class ParseTest(unittest.TestCase):
#'NotStandaloneHandler',
'ExternalEntityRefHandler'
]
def test_utf8(self):
out = self.Outputter()
......@@ -138,7 +138,7 @@ class ParseTest(unittest.TestCase):
setattr(parser, name, getattr(out, name))
parser.returns_unicode = 0
parser.Parse(data, 1)
# Verify output
op = out.out
self.assertEquals(op[0], 'PI: \'xml-stylesheet\' \'href="stylesheet.css"\'')
......@@ -166,7 +166,7 @@ class ParseTest(unittest.TestCase):
parser.returns_unicode = 1
for name in self.handler_names:
setattr(parser, name, getattr(out, name))
parser.Parse(data, 1)
op = out.out
......@@ -196,7 +196,7 @@ class ParseTest(unittest.TestCase):
for name in self.handler_names:
setattr(parser, name, getattr(out, name))
file = StringIO.StringIO(data)
parser.ParseFile(file)
op = out.out
......@@ -226,15 +226,15 @@ class NamespaceSeparatorTest(unittest.TestCase):
expat.ParserCreate()
expat.ParserCreate(namespace_separator=None)
expat.ParserCreate(namespace_separator=' ')
def test_illegal(self):
try:
expat.ParserCreate(namespace_separator=42)
self.fail()
except TypeError, e:
self.assertEquals(str(e),
self.assertEquals(str(e),
'ParserCreate() argument 2 must be string or None, not int')
try:
expat.ParserCreate(namespace_separator='too long')
self.fail()
......@@ -277,7 +277,7 @@ class BufferTextTest(unittest.TestCase):
self.parser = expat.ParserCreate()
self.parser.buffer_text = 1
self.parser.CharacterDataHandler = self.CharacterDataHandler
def check(self, expected, label):
self.assertEquals(self.stuff, expected,
"%s\nstuff = %r\nexpected = %r"
......@@ -307,12 +307,12 @@ class BufferTextTest(unittest.TestCase):
def test_default_to_disabled(self):
parser = expat.ParserCreate()
self.assertFalse(parser.buffer_text)
def test_buffering_enabled(self):
# Make sure buffering is turned on
self.assertTrue(self.parser.buffer_text)
self.parser.Parse("<a>1<b/>2<c/>3</a>", 1)
self.assertEquals(self.stuff, ['123'],
self.assertEquals(self.stuff, ['123'],
"buffered text not properly collapsed")
def test1(self):
......@@ -320,10 +320,10 @@ class BufferTextTest(unittest.TestCase):
# XXX like, but it tests what we need to concisely.
self.setHandlers(["StartElementHandler"])
self.parser.Parse("<a>1<b buffer-text='no'/>2\n3<c buffer-text='yes'/>4\n5</a>", 1)
self.assertEquals(self.stuff,
self.assertEquals(self.stuff,
["<a>", "1", "<b>", "2", "\n", "3", "<c>", "4\n5"],
"buffering control not reacting as expected")
def test2(self):
self.parser.Parse("<a>1<b/>&lt;2&gt;<c/>&#32;\n&#x20;3</a>", 1)
self.assertEquals(self.stuff, ["1<2> \n 3"],
......@@ -339,7 +339,7 @@ class BufferTextTest(unittest.TestCase):
self.setHandlers(["StartElementHandler", "EndElementHandler"])
self.parser.CharacterDataHandler = None
self.parser.Parse("<a>1<b/>2<c/>3</a>", 1)
self.assertEquals(self.stuff,
self.assertEquals(self.stuff,
["<a>", "<b>", "</b>", "<c>", "</c>", "</a>"])
def test5(self):
......@@ -349,11 +349,11 @@ class BufferTextTest(unittest.TestCase):
["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "3", "</a>"])
def test6(self):
self.setHandlers(["CommentHandler", "EndElementHandler",
self.setHandlers(["CommentHandler", "EndElementHandler",
"StartElementHandler"])
self.parser.Parse("<a>1<b/>2<c></c>345</a> ", 1)
self.assertEquals(self.stuff,
["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "345", "</a>"],
self.assertEquals(self.stuff,
["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "345", "</a>"],
"buffered text not properly split")
def test7(self):
......@@ -399,7 +399,7 @@ class PositionTest(unittest.TestCase):
self.assertTrue(self.upto < len(self.expected_list),
'too many parser events')
expected = self.expected_list[self.upto]
self.assertEquals(pos, expected,
self.assertEquals(pos, expected,
'Expected position %s, got position %s' %(pos, expected))
self.upto += 1
......@@ -422,16 +422,16 @@ class sf1296433Test(unittest.TestCase):
xml = "<?xml version='1.0' encoding='iso8859'?><s>%s</s>" % ('a' * 1025)
# this one doesn't crash
#xml = "<?xml version='1.0'?><s>%s</s>" % ('a' * 10000)
class SpecificException(Exception):
pass
def handler(text):
raise SpecificException
parser = expat.ParserCreate()
parser.CharacterDataHandler = handler
self.assertRaises(Exception, parser.Parse, xml)
......
......@@ -607,7 +607,7 @@ class ReTests(unittest.TestCase):
for typecode in 'cbBuhHiIlLfd':
a = array.array(typecode)
self.assertEqual(re.compile("bla").match(a), None)
self.assertEqual(re.compile("").match(a).groups(), ())
self.assertEqual(re.compile("").match(a).groups(), ())
def run_re_tests():
from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
......
This diff is collapsed.
......@@ -288,7 +288,7 @@ class TestJointOps(unittest.TestCase):
self.assertEqual(sum(elem.hash_count for elem in d), n)
if hasattr(s, 'symmetric_difference_update'):
s.symmetric_difference_update(d)
self.assertEqual(sum(elem.hash_count for elem in d), n)
self.assertEqual(sum(elem.hash_count for elem in d), n)
d2 = dict.fromkeys(set(d))
self.assertEqual(sum(elem.hash_count for elem in d), n)
d3 = dict.fromkeys(frozenset(d))
......
......@@ -25,7 +25,7 @@ def server(evt):
evt.set()
class GeneralTests(TestCase):
def setUp(self):
self.evt = threading.Event()
threading.Thread(target=server, args=(self.evt,)).start()
......@@ -38,13 +38,13 @@ class GeneralTests(TestCase):
# connects
smtp = smtplib.SMTP("localhost", 9091)
smtp.sock.close()
def testTimeoutDefault(self):
# default
smtp = smtplib.SMTP("localhost", 9091)
self.assertTrue(smtp.sock.gettimeout() is None)
smtp.sock.close()
def testTimeoutValue(self):
# a value
smtp = smtplib.SMTP("localhost", 9091, timeout=30)
......
......@@ -822,7 +822,7 @@ class NetworkConnectionTest(object):
def clientSetUp(self):
self.cli = socket.create_connection((HOST, PORT))
self.serv_conn = self.cli
class BasicTCPTest2(NetworkConnectionTest, BasicTCPTest):
"""Tests that NetworkConnection does not break existing TCP functionality.
"""
......@@ -853,22 +853,22 @@ class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
self.cli = socket.create_connection((HOST, PORT), timeout=30)
self.assertEqual(self.cli.family, 2)
testTimeoutDefault = _justAccept
testTimeoutDefault = _justAccept
def _testTimeoutDefault(self):
self.cli = socket.create_connection((HOST, PORT))
self.assertTrue(self.cli.gettimeout() is None)
testTimeoutValueNamed = _justAccept
testTimeoutValueNamed = _justAccept
def _testTimeoutValueNamed(self):
self.cli = socket.create_connection((HOST, PORT), timeout=30)
self.assertEqual(self.cli.gettimeout(), 30)
testTimeoutValueNonamed = _justAccept
testTimeoutValueNonamed = _justAccept
def _testTimeoutValueNonamed(self):
self.cli = socket.create_connection((HOST, PORT), 30)
self.assertEqual(self.cli.gettimeout(), 30)
testTimeoutNone = _justAccept
testTimeoutNone = _justAccept
def _testTimeoutNone(self):
previous = socket.getdefaulttimeout()
socket.setdefaulttimeout(30)
......
......@@ -25,12 +25,12 @@ class ConnectedTests(unittest.TestCase):
else:
print "didn't raise TypeError"
socket.RAND_add("this is a random string", 75.0)
with test_support.transient_internet():
f = urllib.urlopen('https://sf.net')
buf = f.read()
f.close()
def testTimeout(self):
def error_msg(extra_msg):
print >> sys.stderr, """\
......@@ -38,14 +38,14 @@ class ConnectedTests(unittest.TestCase):
test_timeout. That may be legitimate, but is not the outcome we
hoped for. If this message is seen often, test_timeout should be
changed to use a more reliable address.""" % (ADDR, extra_msg)
# A service which issues a welcome banner (without need to write
# anything).
# XXX ("gmail.org", 995) has been unreliable so far, from time to
# XXX time non-responsive for hours on end (& across all buildbot
# XXX time non-responsive for hours on end (& across all buildbot
# XXX slaves, so that's not just a local thing).
ADDR = "gmail.org", 995
s = socket.socket()
s.settimeout(30.0)
try:
......@@ -59,7 +59,7 @@ class ConnectedTests(unittest.TestCase):
return
else:
raise
ss = socket.ssl(s)
# Read part of return welcome banner twice.
ss.read(1)
......@@ -71,11 +71,11 @@ class BasicTests(unittest.TestCase):
def testRudeShutdown(self):
# Some random port to connect to.
PORT = [9934]
listener_ready = threading.Event()
listener_gone = threading.Event()
# `listener` runs in a thread. It opens a socket listening on
# `listener` runs in a thread. It opens a socket listening on
# PORT, and sits in an accept() until the main thread connects.
# Then it rudely closes the socket, and sets Event `listener_gone`
# to let the main thread know the socket is gone.
......@@ -87,7 +87,7 @@ class BasicTests(unittest.TestCase):
s.accept()
s = None # reclaim the socket object, which also closes it
listener_gone.set()
def connector():
listener_ready.wait()
s = socket.socket()
......@@ -100,7 +100,7 @@ class BasicTests(unittest.TestCase):
else:
raise test_support.TestFailed(
'connecting to closed SSL socket should have failed')
t = threading.Thread(target=listener)
t.start()
connector()
......@@ -153,8 +153,8 @@ class OpenSSLServer(threading.Thread):
try:
cmd = "openssl s_server -cert %s -key %s -quiet" % (cert_file, key_file)
self.s = subprocess.Popen(cmd.split(), stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
self.s = subprocess.Popen(cmd.split(), stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
time.sleep(1)
except:
......@@ -171,7 +171,7 @@ class OpenSSLServer(threading.Thread):
self.haveServer = False
else:
self.haveServer = True
def run(self):
while self.keepServing:
time.sleep(.5)
......@@ -186,7 +186,7 @@ class OpenSSLServer(threading.Thread):
subprocess.TerminateProcess(int(self.s._handle), -1)
else:
os.kill(self.s.pid, 15)
def test_main():
if not hasattr(socket, "ssl"):
raise test_support.TestSkipped("socket module has no ssl support")
......
......@@ -15,9 +15,9 @@ class SoftspaceTests(unittest.TestCase):
print >> f, 'f', 'g'
# In 2.2 & earlier, this printed ' a\nbc d\te\nf g\n'
self.assertEqual(f.getvalue(), 'a\nb c d\te\nf g\n')
def test_main():
run_unittest(SoftspaceTests)
if __name__ == '__main__':
test_main()
......@@ -91,6 +91,6 @@ class StringprepTests(unittest.TestCase):
def test_main():
test_support.run_unittest(StringprepTests)
if __name__ == '__main__':
test_main()
......@@ -376,7 +376,7 @@ leading to spurious errors.
... elif 1:
... pass
Traceback (most recent call last):
...
...
SyntaxError: can't assign to function call (<doctest test.test_syntax[44]>, line 2)
>>> if 1:
......@@ -384,7 +384,7 @@ leading to spurious errors.
... elif 1:
... x() = 1
Traceback (most recent call last):
...
...
SyntaxError: can't assign to function call (<doctest test.test_syntax[45]>, line 4)
>>> if 1:
......@@ -394,7 +394,7 @@ leading to spurious errors.
... else:
... pass
Traceback (most recent call last):
...
...
SyntaxError: can't assign to function call (<doctest test.test_syntax[46]>, line 2)
>>> if 1:
......@@ -404,7 +404,7 @@ leading to spurious errors.
... else:
... pass
Traceback (most recent call last):
...
...
SyntaxError: can't assign to function call (<doctest test.test_syntax[47]>, line 4)
>>> if 1:
......@@ -414,7 +414,7 @@ leading to spurious errors.
... else:
... x() = 1
Traceback (most recent call last):
...
...
SyntaxError: can't assign to function call (<doctest test.test_syntax[48]>, line 6)
"""
......
......@@ -987,4 +987,3 @@ def test_main():
if __name__ == "__main__":
test_main()
......@@ -22,7 +22,7 @@ def server(evt):
evt.set()
class GeneralTests(TestCase):
def setUp(self):
self.evt = threading.Event()
threading.Thread(target=server, args=(self.evt,)).start()
......@@ -35,13 +35,13 @@ class GeneralTests(TestCase):
# connects
telnet = telnetlib.Telnet("localhost", 9091)
telnet.sock.close()
def testTimeoutDefault(self):
# default
telnet = telnetlib.Telnet("localhost", 9091)
self.assertTrue(telnet.sock.gettimeout() is None)
telnet.sock.close()
def testTimeoutValue(self):
# a value
telnet = telnetlib.Telnet("localhost", 9091, timeout=30)
......
......@@ -514,7 +514,7 @@ class OtherTests(unittest.TestCase):
# version of .testzip would swallow this exception (and any other)
# and report that the first file in the archive was corrupt.
self.assertRaises(RuntimeError, zipf.testzip)
def tearDown(self):
support.unlink(TESTFN)
support.unlink(TESTFN2)
......@@ -568,7 +568,7 @@ class TestsWithRandomBinaryFiles(unittest.TestCase):
fp = open(TESTFN, "wb")
fp.write(self.data)
fp.close()
def tearDown(self):
support.unlink(TESTFN)
support.unlink(TESTFN2)
......
......@@ -223,13 +223,13 @@ class Timer:
def timeit(stmt="pass", setup="pass", timer=default_timer,
number=default_number):
"""Convenience function to create Timer object and call timeit method."""
return Timer(stmt, setup, timer).timeit(number)
"""Convenience function to create Timer object and call timeit method."""
return Timer(stmt, setup, timer).timeit(number)
def repeat(stmt="pass", setup="pass", timer=default_timer,
repeat=default_repeat, number=default_number):
"""Convenience function to create Timer object and call repeat method."""
return Timer(stmt, setup, timer).repeat(repeat, number)
"""Convenience function to create Timer object and call repeat method."""
return Timer(stmt, setup, timer).repeat(repeat, number)
def main(args=None):
"""Main program, used when run as a script.
......
......@@ -490,7 +490,7 @@ class HTTPErrorProcessor(BaseHandler):
def http_response(self, request, response):
code, msg, hdrs = response.code, response.msg, response.info()
# According to RFC 2616, "2xx" code indicates that the client's
# According to RFC 2616, "2xx" code indicates that the client's
# request was successfully received, understood, and accepted.
if not (200 <= code < 300):
response = self.parent.error(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment