diff options
-rw-r--r-- | Doc/library/unittest.rst | 28 | ||||
-rw-r--r-- | Lib/email/test/test_email_codecs_renamed.py | 4 | ||||
-rw-r--r-- | Lib/test/test_fork1.py | 1 | ||||
-rwxr-xr-x | Tools/scripts/reindent-rst.py | 29 |
4 files changed, 54 insertions, 8 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index 3a1e63a..c9dc6b6 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -446,12 +446,26 @@ Basic skipping looks like this: :: def test_nothing(self): self.fail("shouldn't happen") + @unittest.skipIf(mylib.__version__ < (1, 3), "not supported in this library version") + def test_format(self): + # Tests that work for only a certain version of the library. + pass + + @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") + def test_windows_support(self): + # windows specific testing code + pass + This is the output of running the example above in verbose mode: :: + test_format (__main__.MyTestCase) ... skipped 'not supported in this library version' test_nothing (__main__.MyTestCase) ... skipped 'demonstrating skipping' + test_windows_support (__main__.MyTestCase) ... skipped 'requires Windows' ---------------------------------------------------------------------- - Ran 1 test in 0.072s + Ran 3 tests in 0.005s + + OK (skipped=3) Classes can be skipped just like methods: :: @@ -657,13 +671,15 @@ Test cases To catch any of a group of exceptions, a tuple containing the exception classes may be passed as *exception*. - .. versionchanged:: 3.1 + If *callable* is omitted or None, returns a context manager so that the + code under test can be written inline rather than as a function:: - If *callable* is omitted or None, returns a context manager so that the - code under test can be written inline rather than as a function:: + with self.failUnlessRaises(some_error_class): + do_something() + + .. versionchanged:: 3.1 + Added the ability to use :meth:`assertRaises` as a context manager. - with self.failUnlessRaises(some_error_class): - do_something() .. method:: failIf(expr[, msg]) assertFalse(expr[, msg]) diff --git a/Lib/email/test/test_email_codecs_renamed.py b/Lib/email/test/test_email_codecs_renamed.py index 7122212..acc19c3 100644 --- a/Lib/email/test/test_email_codecs_renamed.py +++ b/Lib/email/test/test_email_codecs_renamed.py @@ -3,7 +3,7 @@ # email package unit tests for (optional) Asian codecs import unittest -from test.support import TestSkipped, run_unittest +from test.support import run_unittest from email.test.test_email import TestEmailBase from email.charset import Charset @@ -15,7 +15,7 @@ from email.message import Message try: str('foo', 'euc-jp') except LookupError: - raise TestSkipped + raise unittest.SkipTest diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py index 057c589..c9f18d9 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -3,6 +3,7 @@ import os import time +import unittest from test.fork_wait import ForkWait from test.support import run_unittest, reap_children diff --git a/Tools/scripts/reindent-rst.py b/Tools/scripts/reindent-rst.py new file mode 100755 index 0000000..bf431d9 --- /dev/null +++ b/Tools/scripts/reindent-rst.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +# Make a reST file compliant to our pre-commit hook. +# Currently just remove trailing whitespace. + +from __future__ import with_statement +import sys, re, shutil + +ws_re = re.compile(r'\s+(\r?\n)$') + +def main(argv=sys.argv): + rv = 0 + for filename in argv[1:]: + try: + with open(filename, 'rb') as f: + lines = f.readlines() + new_lines = [ws_re.sub(r'\1', line) for line in lines] + if new_lines != lines: + print 'Fixing %s...' % filename + shutil.copyfile(filename, filename + '.bak') + with open(filename, 'wb') as f: + f.writelines(new_lines) + except Exception, err: + print 'Cannot fix %s: %s' % (filename, err) + rv = 1 + return rv + +if __name__ == '__main__': + sys.exit(main()) |