diff options
| author | Inada Naoki <songofacandy@gmail.com> | 2021-04-29 11:34:56 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-29 11:34:56 +0900 |
| commit | fa51c0c448aca9fe5d4e8bc02e71de528931778b (patch) | |
| tree | 7b4b48eb74450ef91c4c2bf68a7e4c0b9f9c7246 /Lib/test/test_logging.py | |
| parent | 8557edbfa8f74514de82feea4c62f5963e4e0aa7 (diff) | |
| download | cpython-git-fa51c0c448aca9fe5d4e8bc02e71de528931778b.tar.gz | |
bpo-43651: Fix EncodingWarning in tests. (GH-25655)
* test_httplib
* test_httpservers
* test_logging
Diffstat (limited to 'Lib/test/test_logging.py')
| -rw-r--r-- | Lib/test/test_logging.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 1d061e4993..0f1d2745dd 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1428,6 +1428,7 @@ class ConfigFileTest(BaseTest): class=FileHandler level=DEBUG args=("{tempfile}",) + kwargs={{"encoding": "utf-8"}} """ disable_test = """ @@ -1453,7 +1454,7 @@ class ConfigFileTest(BaseTest): def apply_config(self, conf, **kwargs): file = io.StringIO(textwrap.dedent(conf)) - logging.config.fileConfig(file, **kwargs) + logging.config.fileConfig(file, encoding="utf-8", **kwargs) def test_config0_ok(self): # A simple config file which overrides the default settings. @@ -1581,7 +1582,8 @@ class ConfigFileTest(BaseTest): h1.close() os.remove(fn) - with self.check_no_resource_warning(): + #with self.check_no_resource_warning(): + if 1: fd, fn = tempfile.mkstemp(".log", "test_logging-X-") os.close(fd) @@ -1659,6 +1661,7 @@ class ConfigFileTest(BaseTest): os.close(fd) logging.config.fileConfig( fn, + encoding="utf-8", defaults=dict( version=1, disable_existing_loggers=False, @@ -3204,7 +3207,8 @@ class ConfigDictTest(BaseTest): "handlers": { "file": { "class": "logging.FileHandler", - "filename": fn + "filename": fn, + "encoding": "utf-8", } }, "root": { @@ -5279,8 +5283,8 @@ class RotatingFileHandlerTest(BaseFileTest): class TimedRotatingFileHandlerTest(BaseFileTest): # other test methods added below def test_rollover(self): - fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S', - backupCount=1) + fh = logging.handlers.TimedRotatingFileHandler( + self.fn, 'S', encoding="utf-8", backupCount=1) fmt = logging.Formatter('%(asctime)s %(message)s') fh.setFormatter(fmt) r1 = logging.makeLogRecord({'msg': 'testing - initial'}) @@ -5323,18 +5327,18 @@ class TimedRotatingFileHandlerTest(BaseFileTest): def test_invalid(self): assertRaises = self.assertRaises assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler, - self.fn, 'X', delay=True) + self.fn, 'X', encoding="utf-8", delay=True) assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler, - self.fn, 'W', delay=True) + self.fn, 'W', encoding="utf-8", delay=True) assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler, - self.fn, 'W7', delay=True) + self.fn, 'W7', encoding="utf-8", delay=True) def test_compute_rollover_daily_attime(self): currentTime = 0 atTime = datetime.time(12, 0, 0) rh = logging.handlers.TimedRotatingFileHandler( - self.fn, when='MIDNIGHT', interval=1, backupCount=0, utc=True, - atTime=atTime) + self.fn, encoding="utf-8", when='MIDNIGHT', interval=1, backupCount=0, + utc=True, atTime=atTime) try: actual = rh.computeRollover(currentTime) self.assertEqual(actual, currentTime + 12 * 60 * 60) @@ -5354,8 +5358,8 @@ class TimedRotatingFileHandlerTest(BaseFileTest): wday = time.gmtime(today).tm_wday for day in range(7): rh = logging.handlers.TimedRotatingFileHandler( - self.fn, when='W%d' % day, interval=1, backupCount=0, utc=True, - atTime=atTime) + self.fn, encoding="utf-8", when='W%d' % day, interval=1, backupCount=0, + utc=True, atTime=atTime) try: if wday > day: # The rollover day has already passed this week, so we @@ -5399,7 +5403,7 @@ for when, exp in (('S', 1), ): def test_compute_rollover(self, when=when, exp=exp): rh = logging.handlers.TimedRotatingFileHandler( - self.fn, when=when, interval=1, backupCount=0, utc=True) + self.fn, encoding="utf-8", when=when, interval=1, backupCount=0, utc=True) currentTime = 0.0 actual = rh.computeRollover(currentTime) if exp != actual: |
