will be *msg* if given, otherwise it will be :const:`None`.
.. deprecated:: 3.1
- :meth:`failUnless`.
+ :meth:`failUnless`; use one of the ``assert`` variants.
:meth:`assert_`; use :meth:`assertTrue`.
function for comparing strings.
.. deprecated:: 3.1
- :meth:`failUnlessEqual`.
+ :meth:`failUnlessEqual`; use :meth:`assertEqual`.
.. method:: assertNotEqual(first, second, msg=None)
*first* and *second*.
.. deprecated:: 3.1
- :meth:`failIfEqual`.
+ :meth:`failIfEqual`; use :meth:`assertNotEqual`.
.. method:: assertAlmostEqual(first, second, *, places=7, msg=None)
Objects that compare equal are automatically almost equal.
.. deprecated:: 3.1
- :meth:`failUnlessAlmostEqual`.
+ :meth:`failUnlessAlmostEqual`; use :meth:`assertAlmostEqual`.
.. method:: assertNotAlmostEqual(first, second, *, places=7, msg=None)
Objects that compare equal automatically fail.
.. deprecated:: 3.1
- :meth:`failIfAlmostEqual`.
+ :meth:`failIfAlmostEqual`; use :meth:`assertNotAlmostEqual`.
.. method:: assertGreater(first, second, msg=None)
Added the :attr:`exception` attribute.
.. deprecated:: 3.1
- :meth:`failUnlessRaises`.
+ :meth:`failUnlessRaises`; use :meth:`assertRaises`.
.. method:: assertRaisesRegexp(exception, regexp[, callable, ...])
for the error message.
.. deprecated:: 3.1
- :meth:`failIf`.
+ :meth:`failIf`; use :meth:`assertFalse`.
.. method:: fail(msg=None)
import tempfile
import shutil
+from test.support import run_unittest
+
from distutils.core import Distribution
from distutils.command.bdist import bdist
from distutils.tests import support
return unittest.makeSuite(BuildTestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
except ImportError:
zlib = None
+from test.support import run_unittest
+
from distutils.core import Distribution
from distutils.command.bdist_dumb import bdist_dumb
from distutils.tests import support
return unittest.makeSuite(BuildDumbTestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
import unittest
import sys
+from test.support import run_unittest
+
from distutils.tests import support
@unittest.skipUnless(sys.platform=="win32", "These tests are only for win32")
return unittest.makeSuite(BDistMSITestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
import tempfile
import shutil
+from test.support import run_unittest
+
from distutils.core import Distribution
from distutils.command.bdist_rpm import bdist_rpm
from distutils.tests import support
return unittest.makeSuite(BuildRpmTestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
"""Tests for distutils.command.bdist_wininst."""
import unittest
+from test.support import run_unittest
+
from distutils.command.bdist_wininst import bdist_wininst
from distutils.tests import support
return unittest.makeSuite(BuildWinInstTestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
"""Tests for distutils.cmd."""
import unittest
import os
-from test.support import captured_stdout
+from test.support import captured_stdout, run_unittest
from distutils.cmd import Command
from distutils.dist import Distribution
return unittest.makeSuite(CommandTestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
import warnings
import sysconfig
-from test.support import check_warnings
+from test.support import check_warnings, run_unittest
from test.support import captured_stdout
from distutils import cygwinccompiler
return unittest.makeSuite(CygwinCCompilerTestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
import os
import warnings
-from test.support import check_warnings
+from test.support import check_warnings, run_unittest
from test.support import captured_stdout
from distutils.emxccompiler import get_versions
return unittest.makeSuite(EmxCCompilerTestCase)
if __name__ == '__main__':
- test_support.run_unittest(test_suite())
+ run_unittest(test_suite())
import os
import test
import unittest
+import shutil
from distutils import sysconfig
from distutils.tests import support
from types import ListType
from email.test.test_email import TestEmailBase
-from test.support import TestSkipped
+from test.support import TestSkipped, run_unittest
import email
from email import __file__ as testfile
def test_main():
for testclass in _testclasses():
- support.run_unittest(testclass)
+ run_unittest(testclass)
\f
def exists(path):
"""Test whether a path exists. Returns False for broken symbolic links"""
try:
- st = os.stat(path)
+ os.stat(path)
except os.error:
return False
return True
if __name__ == '__main__':
- import sys
import getopt
USAGE = """\
def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
- st = os.lstat(path)
+ os.lstat(path)
except os.error:
return False
return True
"""Wait for child process to terminate. Returns returncode
attribute."""
if self.returncode is None:
- obj = WaitForSingleObject(self._handle, INFINITE)
+ WaitForSingleObject(self._handle, INFINITE)
self.returncode = GetExitCodeProcess(self._handle)
return self.returncode
def test_null(self):
self.writerAssertEqual([], '')
- def test_single(self):
+ def test_single_writer(self):
self.writerAssertEqual([['abc']], 'abc\r\n')
- def test_simple(self):
+ def test_simple_writer(self):
self.writerAssertEqual([[1, 2, 'abc', 3, 4]], '1,2,abc,3,4\r\n')
def test_quotes(self):
from test import support
import threading
import time
+import socket
import unittest
PORT = None
self.assertRaises(TypeError, fnmatchcase, 'test', b'*')
self.assertRaises(TypeError, fnmatchcase, b'test', '*')
+ def test_fnmatchcase(self):
+ check = self.check_match
+ check('AbC', 'abc', 0)
+ check('abc', 'AbC', 0)
+
def test_bytes(self):
self.check_match(b'test', b'te*')
self.check_match(b'test\xff', b'te*\xff')
# attributes should not be writable
if not isinstance(self.thetype, type):
return
- self.assertRaises(TypeError, setattr, p, 'func', map)
- self.assertRaises(TypeError, setattr, p, 'args', (1, 2))
- self.assertRaises(TypeError, setattr, p, 'keywords', dict(a=1, b=2))
+ self.assertRaises(AttributeError, setattr, p, 'func', map)
+ self.assertRaises(AttributeError, setattr, p, 'args', (1, 2))
+ self.assertRaises(AttributeError, setattr, p, 'keywords', dict(a=1, b=2))
+
+ p = self.thetype(hex)
+ try:
+ del p.__dict__
+ except TypeError:
+ pass
+ else:
+ self.fail('partial object allowed __dict__ to be deleted')
def test_argument_checking(self):
self.assertRaises(TypeError, self.thetype) # need at least a func arg
self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0)
self.assertRaises(ZeroDivisionError, self.thetype(f, y=0), 1)
- def test_attributes(self):
- p = self.thetype(hex)
- try:
- del p.__dict__
- except TypeError:
- pass
- else:
- self.fail('partial object allowed __dict__ to be deleted')
-
def test_weakref(self):
f = self.thetype(int, base=16)
p = proxy(f)
self.d = d
assert float(n) / float(d) == value
else:
- raise TypeError("can't deal with %r" % val)
+ raise TypeError("can't deal with %r" % value)
def _cmp__(self, other):
if not isinstance(other, Rat):
self.confirm(len(n1.entities) == len(n2.entities)
and len(n1.notations) == len(n2.notations))
for i in range(len(n1.notations)):
+ # XXX this loop body doesn't seem to be executed?
no1 = n1.notations.item(i)
no2 = n1.notations.item(i)
self.confirm(no1.name == no2.name
and no1.publicId == no2.publicId
and no1.systemId == no2.systemId)
- statck.append((no1, no2))
+ stack.append((no1, no2))
for i in range(len(n1.entities)):
e1 = n1.entities.item(i)
e2 = n2.entities.item(i)
return
x = Value('i', 7, lock=lock)
- y = Value(ctypes.c_double, 1.0/3.0, lock=lock)
+ y = Value(c_double, 1.0/3.0, lock=lock)
foo = Value(_Foo, 3, 2, lock=lock)
- arr = Array('d', list(range(10)), lock=lock)
- string = Array('c', 20, lock=lock)
+ arr = self.Array('d', list(range(10)), lock=lock)
+ string = self.Array('c', 20, lock=lock)
string.value = 'hello'
p = self.Process(target=self._double, args=(x, y, foo, arr, string))
return int(value)
else:
return int(value[:-1]) * _time_units[value[-1]]
- except ValueError as IndexError:
+ except (ValueError, IndexError):
raise OptionValueError(
'option %s: invalid duration: %r' % (opt, value))
s = Template('$who likes $100')
raises(ValueError, s.substitute, dict(who='tim'))
- def test_delimiter_override(self):
- class PieDelims(Template):
- delimiter = '@'
- s = PieDelims('@who likes to eat a bag of @{what} worth $100')
- self.assertEqual(s.substitute(dict(who='tim', what='ham')),
- 'tim likes to eat a bag of ham worth $100')
-
def test_idpattern_override(self):
class PathPattern(Template):
idpattern = r'[_a-z][._a-z0-9]*'
raises(ValueError, s.substitute, dict(gift='bud', who='you'))
eq(s.safe_substitute(), 'this &gift is for &{who} &')
+ class PieDelims(Template):
+ delimiter = '@'
+ s = PieDelims('@who likes to eat a bag of @{what} worth $100')
+ self.assertEqual(s.substitute(dict(who='tim', what='ham')),
+ 'tim likes to eat a bag of ham worth $100')
+
def test_main():
from test import support
if os.path.isdir(sys.executable) and \
os.path.exists(sys.executable+'.exe'):
# Cygwin horror
- executable = executable + '.exe'
- res = platform.libc_ver(sys.executable)
+ executable = sys.executable + '.exe'
+ else:
+ executable = sys.executable
+ res = platform.libc_ver(executable)
def test_parse_release_file(self):
from test import support, test_genericpath
import posixpath, os
-from posixpath import realpath, abspath, join, dirname, basename, relpath
+from posixpath import realpath, abspath, dirname, basename
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
# being an absolute path, so we need this.
def test_misbehavin(self):
class Misb:
- def __lt__(self, other): return 0
- def __gt__(self, other): return 0
- def __eq__(self, other): return 0
- def __le__(self, other): raise TestFailed("This shouldn't happen")
- def __ge__(self, other): raise TestFailed("This shouldn't happen")
- def __ne__(self, other): raise TestFailed("This shouldn't happen")
+ def __lt__(self_, other): return 0
+ def __gt__(self_, other): return 0
+ def __eq__(self_, other): return 0
+ def __le__(self_, other): self.fail("This shouldn't happen")
+ def __ge__(self_, other): self.fail("This shouldn't happen")
+ def __ne__(self_, other): self.fail("This shouldn't happen")
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
ssl_version=ssl.PROTOCOL_TLSv1)
s.connect((HOST, server.port))
except ssl.SSLError as x:
- raise support.TestFailed("Unexpected SSL error: " + str(x))
+ self.fail("Unexpected SSL error: " + str(x))
except Exception as x:
- raise support.TestFailed("Unexpected exception: " + str(x))
+ self.fail("Unexpected exception: " + str(x))
else:
# helper methods for standardising recv* method signatures
def _recv_into():
outdata = s.read()
outdata = str(outdata, 'ASCII', 'strict')
if outdata != indata.lower():
- raise support.TestFailed(
+ self.fail(
"While sending with <<{name:s}>> bad data "
"<<{outdata:s}>> ({nout:d}) received; "
"expected <<{indata:s}>> ({nin:d})\n".format(
)
except ValueError as e:
if expect_success:
- raise support.TestFailed(
+ self.fail(
"Failed to send with method <<{name:s}>>; "
"expected to succeed.\n".format(name=meth_name)
)
if not str(e).startswith(meth_name):
- raise support.TestFailed(
+ self.fail(
"Method <<{name:s}>> failed with unexpected "
"exception message: {exp:s}\n".format(
name=meth_name, exp=e
outdata = recv_meth(*args)
outdata = str(outdata, 'ASCII', 'strict')
if outdata != indata.lower():
- raise support.TestFailed(
+ self.fail(
"While receiving with <<{name:s}>> bad data "
"<<{outdata:s}>> ({nout:d}) received; "
"expected <<{indata:s}>> ({nin:d})\n".format(
)
except ValueError as e:
if expect_success:
- raise support.TestFailed(
+ self.fail(
"Failed to receive with method <<{name:s}>>; "
"expected to succeed.\n".format(name=meth_name)
)
if not str(e).startswith(meth_name):
- raise support.TestFailed(
+ self.fail(
"Method <<{name:s}>> failed with unexpected "
"exception message: {exp:s}\n".format(
name=meth_name, exp=e
import test
import os
import subprocess
+import shutil
from copy import copy, deepcopy
from test.support import run_unittest, TESTFN, unlink, get_attribute
if i == 20:
break
except:
- failOnException("iteration")
+ self.failOnException("iteration")
test_classes.append(test__RandomNameSequence)
# randrange, and then Python hangs.
import _thread as thread
+import unittest
from test.support import verbose, TestFailed
critical_section = thread.allocate_lock()
mod_path = packdir2 + TESTMOD
mod_name = module_path_to_dotted_name(mod_path)
- pkg = __import__(mod_name)
+ __import__(mod_name)
mod = sys.modules[mod_name]
self.assertEquals(zi.get_source(TESTPACK), None)
self.assertEquals(zi.get_source(mod_path), None)
mod_path = TESTPACK2 + os.sep + TESTMOD
mod_name = module_path_to_dotted_name(mod_path)
- pkg = __import__(mod_name)
+ __import__(mod_name)
mod = sys.modules[mod_name]
self.assertEquals(zi.get_source(TESTPACK2), None)
self.assertEquals(zi.get_source(mod_path), None)
self.obj_name = str(callable_obj)
else:
self.obj_name = None
- self.expected_regex = expected_regexp
+ self.expected_regexp = expected_regexp
def __enter__(self):
return self
return False
# store exception, without traceback, for later retrieval
self.exception = exc_value.with_traceback(None)
- if self.expected_regex is None:
+ if self.expected_regexp is None:
return True
- expected_regexp = self.expected_regex
+ expected_regexp = self.expected_regexp
if isinstance(expected_regexp, (bytes, str)):
expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(str(exc_value)):
with context:
callable_obj(*args, **kwargs)
- def assertRegexpMatches(self, text, expected_regex, msg=None):
- if isinstance(expected_regex, (str, bytes)):
- expected_regex = re.compile(expected_regex)
- if not expected_regex.search(text):
+ def assertRegexpMatches(self, text, expected_regexp, msg=None):
+ if isinstance(expected_regexp, (str, bytes)):
+ expected_regexp = re.compile(expected_regexp)
+ if not expected_regexp.search(text):
msg = msg or "Regexp didn't match"
- msg = '%s: %r not found in %r' % (msg, expected_regex.pattern, text)
+ msg = '%s: %r not found in %r' % (msg, expected_regexp.pattern, text)
raise self.failureException(msg)