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

Skip to content

Commit 41fe615

Browse files
committed
(partially)
Merged revisions 79534,79537,79539,79558,79606 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r79534 | florent.xicluna | 2010-03-31 23:21:54 +0200 (mer, 31 mar 2010) | 2 lines Fix test for xml.etree when using a non-ascii path. And use check_warnings instead of catch_warnings. ........ r79537 | florent.xicluna | 2010-03-31 23:40:32 +0200 (mer, 31 mar 2010) | 2 lines Fix typo ........ r79539 | florent.xicluna | 2010-04-01 00:01:03 +0200 (jeu, 01 avr 2010) | 2 lines Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests. ........ r79558 | florent.xicluna | 2010-04-01 20:17:09 +0200 (jeu, 01 avr 2010) | 2 lines #7092: Fix some -3 warnings, and fix Lib/platform.py when the path contains a double-quote. ........ r79606 | florent.xicluna | 2010-04-02 19:26:42 +0200 (ven, 02 avr 2010) | 2 lines Backport some robotparser test and skip the test if the external resource is not available. ........
1 parent 1bfd0cc commit 41fe615

14 files changed

Lines changed: 60 additions & 95 deletions

Doc/whatsnew/2.7.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ changes, or look through the Subversion logs for all the details.
836836

837837
The :mod:`site` module now reports exceptions occurring
838838
when the :mod:`sitecustomize` module is imported, and will no longer
839-
catch and swallow the :exc:`KeyboardError` exception. (Fixed by
839+
catch and swallow the :exc:`KeyboardInterrupt` exception. (Fixed by
840840
Victor Stinner; :issue:`3137`.)
841841

842842
* The :mod:`socket` module's :class:`SSL` objects now support the

Lib/platform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ def _syscmd_file(target,default=''):
942942
if sys.platform in ('dos','win32','win16','os2'):
943943
# XXX Others too ?
944944
return default
945-
target = _follow_symlinks(target)
945+
target = _follow_symlinks(target).replace('"', '\\"')
946946
try:
947947
f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
948948
except (AttributeError,os.error):

Lib/test/test___all__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from test import support
33
import os
44
import sys
5-
import warnings
65

76

87
class NoAll(RuntimeError):
@@ -16,9 +15,8 @@ class AllTest(unittest.TestCase):
1615

1716
def check_all(self, modname):
1817
names = {}
19-
with warnings.catch_warnings():
20-
warnings.filterwarnings("ignore", ".* (module|package)",
21-
DeprecationWarning)
18+
with support.check_warnings((".* (module|package)",
19+
DeprecationWarning), quiet=True):
2220
try:
2321
exec("import %s" % modname, names)
2422
except:

Lib/test/test_argparse.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import textwrap
88
import tempfile
99
import unittest
10-
import warnings
1110
import argparse
1211

1312
from io import StringIO
@@ -4150,21 +4149,12 @@ def test(self):
41504149
self.assertTrue(hasattr(argparse, name))
41514150

41524151
def test_main():
4153-
with warnings.catch_warnings():
4154-
# silence warnings about version argument - these are expected
4155-
warnings.filterwarnings(
4156-
action='ignore',
4157-
message='The "version" argument to ArgumentParser is deprecated.',
4158-
category=DeprecationWarning)
4159-
warnings.filterwarnings(
4160-
action='ignore',
4161-
message='The format_version method is deprecated',
4162-
category=DeprecationWarning)
4163-
warnings.filterwarnings(
4164-
action='ignore',
4165-
message='The print_version method is deprecated',
4166-
category=DeprecationWarning)
4167-
4152+
# silence warnings about version argument - these are expected
4153+
with support.check_warnings(
4154+
('The "version" argument to ArgumentParser is deprecated.',
4155+
DeprecationWarning),
4156+
('The (format|print)_version method is deprecated',
4157+
DeprecationWarning)):
41684158
support.run_unittest(__name__)
41694159
# Remove global references to avoid looking like we have refleaks.
41704160
RFile.seen = {}

Lib/test/test_complex.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest, os
1+
import unittest
22
from test import support
33

44
from random import random
@@ -395,10 +395,7 @@ def test_file(self):
395395
finally:
396396
if (fo is not None) and (not fo.closed):
397397
fo.close()
398-
try:
399-
os.remove(support.TESTFN)
400-
except (OSError, IOError):
401-
pass
398+
support.unlink(support.TESTFN)
402399

403400
def test_getnewargs(self):
404401
self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))

Lib/test/test_contextlib.py

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"""Unit tests for contextlib.py, and other context managers."""
22

3-
4-
import os
53
import sys
64
import tempfile
75
import unittest
86
import threading
97
from contextlib import * # Tests __all__
108
from test import support
119

10+
1211
class ContextManagerTestCase(unittest.TestCase):
1312

1413
def test_contextmanager_plain(self):
@@ -33,16 +32,12 @@ def woohoo():
3332
yield 42
3433
finally:
3534
state.append(999)
36-
try:
35+
with self.assertRaises(ZeroDivisionError):
3736
with woohoo() as x:
3837
self.assertEqual(state, [1])
3938
self.assertEqual(x, 42)
4039
state.append(x)
4140
raise ZeroDivisionError()
42-
except ZeroDivisionError:
43-
pass
44-
else:
45-
self.fail("Expected ZeroDivisionError")
4641
self.assertEqual(state, [1, 42, 999])
4742

4843
def test_contextmanager_no_reraise(self):
@@ -130,14 +125,11 @@ def close(self):
130125
state.append(1)
131126
x = C()
132127
self.assertEqual(state, [])
133-
try:
128+
with self.assertRaises(ZeroDivisionError):
134129
with closing(x) as y:
135130
self.assertEqual(x, y)
136-
1/0
137-
except ZeroDivisionError:
138-
self.assertEqual(state, [1])
139-
else:
140-
self.fail("Didn't raise ZeroDivisionError")
131+
1 / 0
132+
self.assertEqual(state, [1])
141133

142134
class FileContextTestCase(unittest.TestCase):
143135

@@ -150,20 +142,14 @@ def testWithOpen(self):
150142
f.write("Booh\n")
151143
self.assertTrue(f.closed)
152144
f = None
153-
try:
145+
with self.assertRaises(ZeroDivisionError):
154146
with open(tfn, "r") as f:
155147
self.assertFalse(f.closed)
156148
self.assertEqual(f.read(), "Booh\n")
157-
1/0
158-
except ZeroDivisionError:
159-
self.assertTrue(f.closed)
160-
else:
161-
self.fail("Didn't raise ZeroDivisionError")
149+
1 / 0
150+
self.assertTrue(f.closed)
162151
finally:
163-
try:
164-
os.remove(tfn)
165-
except os.error:
166-
pass
152+
support.unlink(tfn)
167153

168154
class LockContextTestCase(unittest.TestCase):
169155

@@ -172,14 +158,11 @@ def boilerPlate(self, lock, locked):
172158
with lock:
173159
self.assertTrue(locked())
174160
self.assertFalse(locked())
175-
try:
161+
with self.assertRaises(ZeroDivisionError):
176162
with lock:
177163
self.assertTrue(locked())
178-
1/0
179-
except ZeroDivisionError:
180-
self.assertFalse(locked())
181-
else:
182-
self.fail("Didn't raise ZeroDivisionError")
164+
1 / 0
165+
self.assertFalse(locked())
183166

184167
def testWithLock(self):
185168
lock = threading.Lock()

Lib/test/test_descr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33
import types
44
import unittest
5-
import warnings
65

76
from copy import deepcopy
87
from test import support

Lib/test/test_doctest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from test import support
66
import doctest
7-
import warnings
87

98
# NOTE: There are some additional tests relating to interaction with
109
# zipimport in the test_zipimport_support test module.

Lib/test/test_global.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from test.support import run_unittest, check_syntax_error, check_warnings
44
import unittest
5-
65
import warnings
76

87

@@ -54,7 +53,9 @@ def test4(self):
5453

5554

5655
def test_main():
57-
run_unittest(GlobalTests)
56+
with warnings.catch_warnings():
57+
warnings.filterwarnings("error", module="<test string>")
58+
run_unittest(GlobalTests)
5859

5960
if __name__ == "__main__":
6061
test_main()

Lib/test/test_hmac.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,13 @@ def digest(self):
213213

214214
with warnings.catch_warnings():
215215
warnings.simplefilter('error', RuntimeWarning)
216-
try:
216+
with self.assertRaises(RuntimeWarning):
217217
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
218-
except RuntimeWarning:
219-
pass
220-
else:
221218
self.fail('Expected warning about missing block_size')
222219

223220
MockCrazyHash.block_size = 1
224-
try:
221+
with self.assertRaises(RuntimeWarning):
225222
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
226-
except RuntimeWarning:
227-
pass
228-
else:
229223
self.fail('Expected warning about small block_size')
230224

231225

0 commit comments

Comments
 (0)