Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: Lib/packaging/tests/support.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/packaging/tests/__main__.py ('k') | Lib/packaging/tests/test_command_build_ext.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Support code for packaging test cases. 1 """Support code for packaging test cases.
2 2
3 A few helper classes are provided: LoggingCatcher, TempdirManager and 3 A few helper classes are provided: LoggingCatcher, TempdirManager and
4 EnvironRestorer. They are written to be used as mixins:: 4 EnvironRestorer. They are written to be used as mixins::
5 5
6 from packaging.tests import unittest 6 from packaging.tests import unittest
7 from packaging.tests.support import LoggingCatcher 7 from packaging.tests.support import LoggingCatcher
8 8
9 class SomeTestCase(LoggingCatcher, unittest.TestCase): 9 class SomeTestCase(LoggingCatcher, unittest.TestCase):
10 10
(...skipping 10 matching lines...) Expand all
21 and a skip_unless_symlink decorator. 21 and a skip_unless_symlink decorator.
22 22
23 Also provided is a DummyCommand class, useful to mock commands in the 23 Also provided is a DummyCommand class, useful to mock commands in the
24 tests of another command that needs them, a create_distribution function 24 tests of another command that needs them, a create_distribution function
25 and a skip_unless_symlink decorator. 25 and a skip_unless_symlink decorator.
26 26
27 Each class or function has a docstring to explain its purpose and usage. 27 Each class or function has a docstring to explain its purpose and usage.
28 """ 28 """
29 29
30 import os 30 import os
31 import errno
31 import shutil 32 import shutil
32 import logging 33 import logging
33 import weakref 34 import weakref
34 import tempfile 35 import tempfile
35 36
37 from packaging import logger
36 from packaging.dist import Distribution 38 from packaging.dist import Distribution
37 from packaging.tests import unittest 39 from packaging.tests import unittest
38 from test.support import requires_zlib, unlink 40 from test.support import requires_zlib, unlink
39 41
40 __all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer', 42 __all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer',
41 'DummyCommand', 'unittest', 'create_distribution', 43 'DummyCommand', 'unittest', 'create_distribution',
42 'skip_unless_symlink', 'requires_zlib'] 44 'skip_unless_symlink', 'requires_zlib']
43
44
45 logger = logging.getLogger('packaging')
46 logger2to3 = logging.getLogger('RefactoringTool')
47 45
48 46
49 class _TestHandler(logging.handlers.BufferingHandler): 47 class _TestHandler(logging.handlers.BufferingHandler):
50 # stolen and adapted from test.support 48 # stolen and adapted from test.support
51 49
52 def __init__(self): 50 def __init__(self):
53 logging.handlers.BufferingHandler.__init__(self, 0) 51 logging.handlers.BufferingHandler.__init__(self, 0)
54 self.setLevel(logging.DEBUG) 52 self.setLevel(logging.DEBUG)
55 53
56 def shouldFlush(self): 54 def shouldFlush(self):
(...skipping 12 matching lines...) Expand all
69 Use get_logs to retrieve messages and self.loghandler.flush to discard 67 Use get_logs to retrieve messages and self.loghandler.flush to discard
70 them. get_logs automatically flushes the logs; if you test code that 68 them. get_logs automatically flushes the logs; if you test code that
71 generates logging messages but don't use get_logs, you have to flush 69 generates logging messages but don't use get_logs, you have to flush
72 manually before doing other checks on logging message, otherwise you 70 manually before doing other checks on logging message, otherwise you
73 will get irrelevant results. See example in test_command_check. 71 will get irrelevant results. See example in test_command_check.
74 """ 72 """
75 73
76 def setUp(self): 74 def setUp(self):
77 super(LoggingCatcher, self).setUp() 75 super(LoggingCatcher, self).setUp()
78 self.loghandler = handler = _TestHandler() 76 self.loghandler = handler = _TestHandler()
79 self._old_levels = logger.level, logger2to3.level 77 self.old_level = logger.level
80 logger.addHandler(handler) 78 logger.addHandler(handler)
81 logger.setLevel(logging.DEBUG) # we want all messages 79 logger.setLevel(logging.DEBUG) # we want all messages
82 logger2to3.setLevel(logging.CRITICAL) # we don't want 2to3 messages
83 80
84 def tearDown(self): 81 def tearDown(self):
85 handler = self.loghandler 82 handler = self.loghandler
86 # All this is necessary to properly shut down the logging system and 83 # All this is necessary to properly shut down the logging system and
87 # avoid a regrtest complaint. Thanks to Vinay Sajip for the help. 84 # avoid a regrtest complaint. Thanks to Vinay Sajip for the help.
88 handler.close() 85 handler.close()
89 logger.removeHandler(handler) 86 logger.removeHandler(handler)
90 for ref in weakref.getweakrefs(handler): 87 for ref in weakref.getweakrefs(handler):
91 logging._removeHandlerRef(ref) 88 logging._removeHandlerRef(ref)
92 del self.loghandler 89 del self.loghandler
93 logger.setLevel(self._old_levels[0]) 90 logger.setLevel(self.old_level)
94 logger2to3.setLevel(self._old_levels[1])
95 super(LoggingCatcher, self).tearDown() 91 super(LoggingCatcher, self).tearDown()
96 92
97 def get_logs(self, *levels): 93 def get_logs(self, *levels):
98 """Return all log messages with level in *levels*. 94 """Return all log messages with level in *levels*.
99 95
100 Without explicit levels given, returns all messages. *levels* defaults 96 Without explicit levels given, returns all messages. *levels* defaults
101 to all levels. For log calls with arguments (i.e. 97 to all levels. For log calls with arguments (i.e.
102 logger.info('bla bla %r', arg)), the messages will be formatted before 98 logger.info('bla bla %r', arg)), the messages will be formatted before
103 being returned (e.g. "bla bla 'thing'"). 99 being returned (e.g. "bla bla 'thing'").
104 100
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 return func(*args, **kw) 265 return func(*args, **kw)
270 return __wrap 266 return __wrap
271 return _wrap 267 return _wrap
272 268
273 269
274 try: 270 try:
275 from test.support import skip_unless_symlink 271 from test.support import skip_unless_symlink
276 except ImportError: 272 except ImportError:
277 skip_unless_symlink = unittest.skip( 273 skip_unless_symlink = unittest.skip(
278 'requires test.support.skip_unless_symlink') 274 'requires test.support.skip_unless_symlink')
OLDNEW
« no previous file with comments | « Lib/packaging/tests/__main__.py ('k') | Lib/packaging/tests/test_command_build_ext.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+