@@ -1428,6 +1428,7 @@ class ConfigFileTest(BaseTest):
1428
1428
class=FileHandler
1429
1429
level=DEBUG
1430
1430
args=("{tempfile}",)
1431
+ kwargs={{"encoding": "utf-8"}}
1431
1432
"""
1432
1433
1433
1434
disable_test = """
@@ -1453,7 +1454,7 @@ class ConfigFileTest(BaseTest):
1453
1454
1454
1455
def apply_config (self , conf , ** kwargs ):
1455
1456
file = io .StringIO (textwrap .dedent (conf ))
1456
- logging .config .fileConfig (file , ** kwargs )
1457
+ logging .config .fileConfig (file , encoding = "utf-8" , ** kwargs )
1457
1458
1458
1459
def test_config0_ok (self ):
1459
1460
# A simple config file which overrides the default settings.
@@ -1581,7 +1582,8 @@ def cleanup(h1, fn):
1581
1582
h1 .close ()
1582
1583
os .remove (fn )
1583
1584
1584
- with self .check_no_resource_warning ():
1585
+ #with self.check_no_resource_warning():
1586
+ if 1 :
1585
1587
fd , fn = tempfile .mkstemp (".log" , "test_logging-X-" )
1586
1588
os .close (fd )
1587
1589
@@ -1659,6 +1661,7 @@ def test_defaults_do_no_interpolation(self):
1659
1661
os .close (fd )
1660
1662
logging .config .fileConfig (
1661
1663
fn ,
1664
+ encoding = "utf-8" ,
1662
1665
defaults = dict (
1663
1666
version = 1 ,
1664
1667
disable_existing_loggers = False ,
@@ -3204,7 +3207,8 @@ def cleanup(h1, fn):
3204
3207
"handlers" : {
3205
3208
"file" : {
3206
3209
"class" : "logging.FileHandler" ,
3207
- "filename" : fn
3210
+ "filename" : fn ,
3211
+ "encoding" : "utf-8" ,
3208
3212
}
3209
3213
},
3210
3214
"root" : {
@@ -5279,8 +5283,8 @@ def rotator(source, dest):
5279
5283
class TimedRotatingFileHandlerTest (BaseFileTest ):
5280
5284
# other test methods added below
5281
5285
def test_rollover (self ):
5282
- fh = logging .handlers .TimedRotatingFileHandler (self . fn , 'S' ,
5283
- backupCount = 1 )
5286
+ fh = logging .handlers .TimedRotatingFileHandler (
5287
+ self . fn , 'S' , encoding = "utf-8" , backupCount = 1 )
5284
5288
fmt = logging .Formatter ('%(asctime)s %(message)s' )
5285
5289
fh .setFormatter (fmt )
5286
5290
r1 = logging .makeLogRecord ({'msg' : 'testing - initial' })
@@ -5323,18 +5327,18 @@ def test_rollover(self):
5323
5327
def test_invalid (self ):
5324
5328
assertRaises = self .assertRaises
5325
5329
assertRaises (ValueError , logging .handlers .TimedRotatingFileHandler ,
5326
- self .fn , 'X' , delay = True )
5330
+ self .fn , 'X' , encoding = "utf-8" , delay = True )
5327
5331
assertRaises (ValueError , logging .handlers .TimedRotatingFileHandler ,
5328
- self .fn , 'W' , delay = True )
5332
+ self .fn , 'W' , encoding = "utf-8" , delay = True )
5329
5333
assertRaises (ValueError , logging .handlers .TimedRotatingFileHandler ,
5330
- self .fn , 'W7' , delay = True )
5334
+ self .fn , 'W7' , encoding = "utf-8" , delay = True )
5331
5335
5332
5336
def test_compute_rollover_daily_attime (self ):
5333
5337
currentTime = 0
5334
5338
atTime = datetime .time (12 , 0 , 0 )
5335
5339
rh = logging .handlers .TimedRotatingFileHandler (
5336
- self .fn , when = 'MIDNIGHT' , interval = 1 , backupCount = 0 , utc = True ,
5337
- atTime = atTime )
5340
+ self .fn , encoding = "utf-8" , when = 'MIDNIGHT' , interval = 1 , backupCount = 0 ,
5341
+ utc = True , atTime = atTime )
5338
5342
try :
5339
5343
actual = rh .computeRollover (currentTime )
5340
5344
self .assertEqual (actual , currentTime + 12 * 60 * 60 )
@@ -5354,8 +5358,8 @@ def test_compute_rollover_weekly_attime(self):
5354
5358
wday = time .gmtime (today ).tm_wday
5355
5359
for day in range (7 ):
5356
5360
rh = logging .handlers .TimedRotatingFileHandler (
5357
- self .fn , when = 'W%d' % day , interval = 1 , backupCount = 0 , utc = True ,
5358
- atTime = atTime )
5361
+ self .fn , encoding = "utf-8" , when = 'W%d' % day , interval = 1 , backupCount = 0 ,
5362
+ utc = True , atTime = atTime )
5359
5363
try :
5360
5364
if wday > day :
5361
5365
# The rollover day has already passed this week, so we
@@ -5399,7 +5403,7 @@ def secs(**kw):
5399
5403
):
5400
5404
def test_compute_rollover (self , when = when , exp = exp ):
5401
5405
rh = logging .handlers .TimedRotatingFileHandler (
5402
- self .fn , when = when , interval = 1 , backupCount = 0 , utc = True )
5406
+ self .fn , encoding = "utf-8" , when = when , interval = 1 , backupCount = 0 , utc = True )
5403
5407
currentTime = 0.0
5404
5408
actual = rh .computeRollover (currentTime )
5405
5409
if exp != actual :
0 commit comments