mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #10774: test_logging now removes temp files created during tests.
This commit is contained in:
parent
ad4ccfdeb2
commit
60b4df15d6
2 changed files with 12 additions and 7 deletions
|
@ -907,7 +907,8 @@ class EncodingTest(BaseTest):
|
||||||
def test_encoding_plain_file(self):
|
def test_encoding_plain_file(self):
|
||||||
# In Python 2.x, a plain file object is treated as having no encoding.
|
# In Python 2.x, a plain file object is treated as having no encoding.
|
||||||
log = logging.getLogger("test")
|
log = logging.getLogger("test")
|
||||||
fn = tempfile.mktemp(".log", "test_logging-1-")
|
fd, fn = tempfile.mkstemp(".log", "test_logging-1-")
|
||||||
|
os.close(fd)
|
||||||
# the non-ascii data we write to the log.
|
# the non-ascii data we write to the log.
|
||||||
data = "foo\x80"
|
data = "foo\x80"
|
||||||
try:
|
try:
|
||||||
|
@ -1885,7 +1886,7 @@ class FormatterTest(unittest.TestCase):
|
||||||
return logging.makeLogRecord(result)
|
return logging.makeLogRecord(result)
|
||||||
|
|
||||||
def test_percent(self):
|
def test_percent(self):
|
||||||
"Test %-formatting"
|
# Test %-formatting
|
||||||
r = self.get_record()
|
r = self.get_record()
|
||||||
f = logging.Formatter('${%(message)s}')
|
f = logging.Formatter('${%(message)s}')
|
||||||
self.assertEqual(f.format(r), '${Message with 2 placeholders}')
|
self.assertEqual(f.format(r), '${Message with 2 placeholders}')
|
||||||
|
@ -1898,7 +1899,7 @@ class FormatterTest(unittest.TestCase):
|
||||||
self.assertFalse(f.usesTime())
|
self.assertFalse(f.usesTime())
|
||||||
|
|
||||||
def test_braces(self):
|
def test_braces(self):
|
||||||
"Test {}-formatting"
|
# Test {}-formatting
|
||||||
r = self.get_record()
|
r = self.get_record()
|
||||||
f = logging.Formatter('$%{message}%$', style='{')
|
f = logging.Formatter('$%{message}%$', style='{')
|
||||||
self.assertEqual(f.format(r), '$%Message with 2 placeholders%$')
|
self.assertEqual(f.format(r), '$%Message with 2 placeholders%$')
|
||||||
|
@ -1911,7 +1912,7 @@ class FormatterTest(unittest.TestCase):
|
||||||
self.assertFalse(f.usesTime())
|
self.assertFalse(f.usesTime())
|
||||||
|
|
||||||
def test_dollars(self):
|
def test_dollars(self):
|
||||||
"Test $-formatting"
|
# Test $-formatting
|
||||||
r = self.get_record()
|
r = self.get_record()
|
||||||
f = logging.Formatter('$message', style='$')
|
f = logging.Formatter('$message', style='$')
|
||||||
self.assertEqual(f.format(r), 'Message with 2 placeholders')
|
self.assertEqual(f.format(r), 'Message with 2 placeholders')
|
||||||
|
@ -1929,7 +1930,7 @@ class FormatterTest(unittest.TestCase):
|
||||||
|
|
||||||
class LastResortTest(BaseTest):
|
class LastResortTest(BaseTest):
|
||||||
def test_last_resort(self):
|
def test_last_resort(self):
|
||||||
"Test the last resort handler"
|
# Test the last resort handler
|
||||||
root = self.root_logger
|
root = self.root_logger
|
||||||
root.removeHandler(self.root_hdlr)
|
root.removeHandler(self.root_hdlr)
|
||||||
old_stderr = sys.stderr
|
old_stderr = sys.stderr
|
||||||
|
@ -1966,12 +1967,15 @@ class BaseFileTest(BaseTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
BaseTest.setUp(self)
|
BaseTest.setUp(self)
|
||||||
self.fn = tempfile.mktemp(".log", "test_logging-2-")
|
fd, self.fn = tempfile.mkstemp(".log", "test_logging-2-")
|
||||||
|
os.close(fd)
|
||||||
self.rmfiles = []
|
self.rmfiles = []
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for fn in self.rmfiles:
|
for fn in self.rmfiles:
|
||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
|
if os.path.exists(self.fn):
|
||||||
|
os.unlink(self.fn)
|
||||||
BaseTest.tearDown(self)
|
BaseTest.tearDown(self)
|
||||||
|
|
||||||
def assertLogFile(self, filename):
|
def assertLogFile(self, filename):
|
||||||
|
@ -2000,7 +2004,6 @@ class RotatingFileHandlerTest(BaseFileTest):
|
||||||
def test_file_created(self):
|
def test_file_created(self):
|
||||||
# checks that the file is created and assumes it was created
|
# checks that the file is created and assumes it was created
|
||||||
# by us
|
# by us
|
||||||
self.assertFalse(os.path.exists(self.fn))
|
|
||||||
rh = logging.handlers.RotatingFileHandler(self.fn)
|
rh = logging.handlers.RotatingFileHandler(self.fn)
|
||||||
rh.emit(self.next_rec())
|
rh.emit(self.next_rec())
|
||||||
self.assertLogFile(self.fn)
|
self.assertLogFile(self.fn)
|
||||||
|
|
|
@ -55,6 +55,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #10774: test_logging now removes temp files created during tests.
|
||||||
|
|
||||||
- Issue #3243: Support iterable bodies in httplib. Patch Contributions by
|
- Issue #3243: Support iterable bodies in httplib. Patch Contributions by
|
||||||
Xuanji Li and Chris AtLee.
|
Xuanji Li and Chris AtLee.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue