summaryrefslogtreecommitdiff
path: root/Lib/test/test_logging.py
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2021-04-06 11:18:41 +0900
committerGitHub <noreply@github.com>2021-04-06 11:18:41 +0900
commitfb78692f2ad5ee4747f13a73943fbf134b637669 (patch)
treebeb9f1abe584a74f281955ead6541cdeeeaa17a8 /Lib/test/test_logging.py
parentf84d5a113680c5a6aaaf9130aed7a34d611748ff (diff)
downloadcpython-git-fb78692f2ad5ee4747f13a73943fbf134b637669.tar.gz
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25189)
* Fix _sitebuiltins * Fix test_inspect * Fix test_interpreters * Fix test_io * Fix test_iter * Fix test_json * Fix test_linecache * Fix test_lltrace * Fix test_logging * Fix logging
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r--Lib/test/test_logging.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 859baa4738..452ba78523 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -553,7 +553,7 @@ class HandlerTest(BaseTest):
os.close(fd)
if not existing:
os.unlink(fn)
- h = logging.handlers.WatchedFileHandler(fn, delay=True)
+ h = logging.handlers.WatchedFileHandler(fn, encoding='utf-8', delay=True)
if existing:
dev, ino = h.dev, h.ino
self.assertEqual(dev, -1)
@@ -616,7 +616,7 @@ class HandlerTest(BaseTest):
if sys.platform in ('linux', 'darwin'):
cases += ((logging.handlers.WatchedFileHandler, (pfn, 'w')),)
for cls, args in cases:
- h = cls(*args)
+ h = cls(*args, encoding="utf-8")
self.assertTrue(os.path.exists(fn))
h.close()
os.unlink(fn)
@@ -645,7 +645,7 @@ class HandlerTest(BaseTest):
remover = threading.Thread(target=remove_loop, args=(fn, del_count))
remover.daemon = True
remover.start()
- h = logging.handlers.WatchedFileHandler(fn, delay=delay)
+ h = logging.handlers.WatchedFileHandler(fn, encoding='utf-8', delay=delay)
f = logging.Formatter('%(asctime)s: %(levelname)s: %(message)s')
h.setFormatter(f)
try:
@@ -677,7 +677,7 @@ class HandlerTest(BaseTest):
def __init__(self):
super().__init__()
self.sub_handler = logging.StreamHandler(
- stream=open('/dev/null', 'wt'))
+ stream=open('/dev/null', 'wt', encoding='utf-8'))
def emit(self, record):
self.sub_handler.acquire()
@@ -4355,7 +4355,7 @@ class ModuleLevelMiscTest(BaseTest):
# basicConfig() opens the file, but logging.shutdown() closes
# it at Python exit. When A.__del__() is called,
# FileHandler._open() must be called again to re-open the file.
- logging.basicConfig(filename={filename!r})
+ logging.basicConfig(filename={filename!r}, encoding="utf-8")
a = A()
@@ -4365,7 +4365,7 @@ class ModuleLevelMiscTest(BaseTest):
""")
assert_python_ok("-c", code)
- with open(filename) as fp:
+ with open(filename, encoding="utf-8") as fp:
self.assertEqual(fp.read().rstrip(), "ERROR:root:log in __del__")
def test_recursion_error(self):
@@ -4557,13 +4557,13 @@ class BasicConfigTest(unittest.TestCase):
h2.close()
os.remove(fn)
- logging.basicConfig(filename='test.log')
+ logging.basicConfig(filename='test.log', encoding='utf-8')
self.assertEqual(len(logging.root.handlers), 1)
handler = logging.root.handlers[0]
self.assertIsInstance(handler, logging.FileHandler)
- expected = logging.FileHandler('test.log', 'a')
+ expected = logging.FileHandler('test.log', 'a', encoding='utf-8')
self.assertEqual(handler.stream.mode, expected.stream.mode)
self.assertEqual(handler.stream.name, expected.stream.name)
self.addCleanup(cleanup, handler, expected, 'test.log')
@@ -5161,7 +5161,7 @@ class BaseFileTest(BaseTest):
class FileHandlerTest(BaseFileTest):
def test_delay(self):
os.unlink(self.fn)
- fh = logging.FileHandler(self.fn, delay=True)
+ fh = logging.FileHandler(self.fn, encoding='utf-8', delay=True)
self.assertIsNone(fh.stream)
self.assertFalse(os.path.exists(self.fn))
fh.handle(logging.makeLogRecord({}))
@@ -5176,19 +5176,20 @@ class RotatingFileHandlerTest(BaseFileTest):
def test_should_not_rollover(self):
# If maxbytes is zero rollover never occurs
- rh = logging.handlers.RotatingFileHandler(self.fn, maxBytes=0)
+ rh = logging.handlers.RotatingFileHandler(
+ self.fn, encoding="utf-8", maxBytes=0)
self.assertFalse(rh.shouldRollover(None))
rh.close()
def test_should_rollover(self):
- rh = logging.handlers.RotatingFileHandler(self.fn, maxBytes=1)
+ rh = logging.handlers.RotatingFileHandler(self.fn, encoding="utf-8", maxBytes=1)
self.assertTrue(rh.shouldRollover(self.next_rec()))
rh.close()
def test_file_created(self):
# checks that the file is created and assumes it was created
# by us
- rh = logging.handlers.RotatingFileHandler(self.fn)
+ rh = logging.handlers.RotatingFileHandler(self.fn, encoding="utf-8")
rh.emit(self.next_rec())
self.assertLogFile(self.fn)
rh.close()
@@ -5197,7 +5198,7 @@ class RotatingFileHandlerTest(BaseFileTest):
def namer(name):
return name + ".test"
rh = logging.handlers.RotatingFileHandler(
- self.fn, backupCount=2, maxBytes=1)
+ self.fn, encoding="utf-8", backupCount=2, maxBytes=1)
rh.namer = namer
rh.emit(self.next_rec())
self.assertLogFile(self.fn)
@@ -5218,7 +5219,7 @@ class RotatingFileHandlerTest(BaseFileTest):
os.rename(source, dest + ".rotated")
rh = HandlerWithNamerAndRotator(
- self.fn, backupCount=2, maxBytes=1)
+ self.fn, encoding="utf-8", backupCount=2, maxBytes=1)
self.assertEqual(rh.namer(self.fn), self.fn + ".test")
rh.emit(self.next_rec())
self.assertLogFile(self.fn)
@@ -5241,7 +5242,7 @@ class RotatingFileHandlerTest(BaseFileTest):
os.remove(source)
rh = logging.handlers.RotatingFileHandler(
- self.fn, backupCount=2, maxBytes=1)
+ self.fn, encoding="utf-8", backupCount=2, maxBytes=1)
rh.rotator = rotator
rh.namer = namer
m1 = self.next_rec()