Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ded31c4

Browse files
committed
Merged revisions 70656,70668-70669,70671,70701,70703,70706 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r70656 | georg.brandl | 2009-03-28 14:33:33 -0500 (Sat, 28 Mar 2009) | 2 lines Add a script to fixup rst files if the pre-commit hook rejects them. ........ r70668 | benjamin.peterson | 2009-03-28 22:16:57 -0500 (Sat, 28 Mar 2009) | 1 line a more realistic example ........ r70669 | benjamin.peterson | 2009-03-28 22:31:40 -0500 (Sat, 28 Mar 2009) | 1 line stop the versionchanged directive from hiding the docs ........ r70671 | benjamin.peterson | 2009-03-28 22:39:58 -0500 (Sat, 28 Mar 2009) | 1 line fix consistency ........ r70701 | benjamin.peterson | 2009-03-29 17:27:26 -0500 (Sun, 29 Mar 2009) | 1 line add missing import ........ r70703 | benjamin.peterson | 2009-03-29 21:14:21 -0500 (Sun, 29 Mar 2009) | 1 line fix import ........ r70706 | benjamin.peterson | 2009-03-30 09:42:23 -0500 (Mon, 30 Mar 2009) | 1 line add missing import ........
1 parent 5879d41 commit ded31c4

4 files changed

Lines changed: 54 additions & 8 deletions

File tree

Doc/library/unittest.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,26 @@ Basic skipping looks like this: ::
446446
def test_nothing(self):
447447
self.fail("shouldn't happen")
448448

449+
@unittest.skipIf(mylib.__version__ < (1, 3), "not supported in this library version")
450+
def test_format(self):
451+
# Tests that work for only a certain version of the library.
452+
pass
453+
454+
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
455+
def test_windows_support(self):
456+
# windows specific testing code
457+
pass
458+
449459
This is the output of running the example above in verbose mode: ::
450460

461+
test_format (__main__.MyTestCase) ... skipped 'not supported in this library version'
451462
test_nothing (__main__.MyTestCase) ... skipped 'demonstrating skipping'
463+
test_windows_support (__main__.MyTestCase) ... skipped 'requires Windows'
452464

453465
----------------------------------------------------------------------
454-
Ran 1 test in 0.072s
466+
Ran 3 tests in 0.005s
467+
468+
OK (skipped=3)
455469

456470
Classes can be skipped just like methods: ::
457471

@@ -657,13 +671,15 @@ Test cases
657671
To catch any of a group of exceptions, a tuple containing the exception
658672
classes may be passed as *exception*.
659673

660-
.. versionchanged:: 3.1
674+
If *callable* is omitted or None, returns a context manager so that the
675+
code under test can be written inline rather than as a function::
661676

662-
If *callable* is omitted or None, returns a context manager so that the
663-
code under test can be written inline rather than as a function::
677+
with self.failUnlessRaises(some_error_class):
678+
do_something()
679+
680+
.. versionchanged:: 3.1
681+
Added the ability to use :meth:`assertRaises` as a context manager.
664682

665-
with self.failUnlessRaises(some_error_class):
666-
do_something()
667683

668684
.. method:: failIf(expr[, msg])
669685
assertFalse(expr[, msg])

Lib/email/test/test_email_codecs_renamed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# email package unit tests for (optional) Asian codecs
44

55
import unittest
6-
from test.support import TestSkipped, run_unittest
6+
from test.support import run_unittest
77

88
from email.test.test_email import TestEmailBase
99
from email.charset import Charset
@@ -15,7 +15,7 @@
1515
try:
1616
str('foo', 'euc-jp')
1717
except LookupError:
18-
raise TestSkipped
18+
raise unittest.SkipTest
1919

2020

2121

Lib/test/test_fork1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import time
6+
import unittest
67
from test.fork_wait import ForkWait
78
from test.support import run_unittest, reap_children
89

Tools/scripts/reindent-rst.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
3+
# Make a reST file compliant to our pre-commit hook.
4+
# Currently just remove trailing whitespace.
5+
6+
from __future__ import with_statement
7+
import sys, re, shutil
8+
9+
ws_re = re.compile(r'\s+(\r?\n)$')
10+
11+
def main(argv=sys.argv):
12+
rv = 0
13+
for filename in argv[1:]:
14+
try:
15+
with open(filename, 'rb') as f:
16+
lines = f.readlines()
17+
new_lines = [ws_re.sub(r'\1', line) for line in lines]
18+
if new_lines != lines:
19+
print 'Fixing %s...' % filename
20+
shutil.copyfile(filename, filename + '.bak')
21+
with open(filename, 'wb') as f:
22+
f.writelines(new_lines)
23+
except Exception, err:
24+
print 'Cannot fix %s: %s' % (filename, err)
25+
rv = 1
26+
return rv
27+
28+
if __name__ == '__main__':
29+
sys.exit(main())

0 commit comments

Comments
 (0)