@@ -1076,6 +1076,7 @@ class ConfigFileTest(BaseTest):
1076
1076
1077
1077
"""Reading logging config from a .ini-style config file."""
1078
1078
1079
+ check_no_resource_warning = support .check_no_resource_warning
1079
1080
expected_log_pat = r"^(\w+) \+\+ (\w+)$"
1080
1081
1081
1082
# config0 is a standard configuration.
@@ -1284,6 +1285,27 @@ class ConfigFileTest(BaseTest):
1284
1285
datefmt=
1285
1286
"""
1286
1287
1288
+ # config 8, check for resource warning
1289
+ config8 = r"""
1290
+ [loggers]
1291
+ keys=root
1292
+
1293
+ [handlers]
1294
+ keys=file
1295
+
1296
+ [formatters]
1297
+ keys=
1298
+
1299
+ [logger_root]
1300
+ level=DEBUG
1301
+ handlers=file
1302
+
1303
+ [handler_file]
1304
+ class=FileHandler
1305
+ level=DEBUG
1306
+ args=("{tempfile}",)
1307
+ """
1308
+
1287
1309
disable_test = """
1288
1310
[loggers]
1289
1311
keys=root
@@ -1429,6 +1451,29 @@ def test_config7_ok(self):
1429
1451
# Original logger output is empty.
1430
1452
self .assert_log_lines ([])
1431
1453
1454
+ def test_config8_ok (self ):
1455
+
1456
+ def cleanup (h1 , fn ):
1457
+ h1 .close ()
1458
+ os .remove (fn )
1459
+
1460
+ with self .check_no_resource_warning ():
1461
+ fd , fn = tempfile .mkstemp (".log" , "test_logging-X-" )
1462
+ os .close (fd )
1463
+
1464
+ # Replace single backslash with double backslash in windows
1465
+ # to avoid unicode error during string formatting
1466
+ if os .name == "nt" :
1467
+ fn = fn .replace ("\\ " , "\\ \\ " )
1468
+
1469
+ config8 = self .config8 .format (tempfile = fn )
1470
+
1471
+ self .apply_config (config8 )
1472
+ self .apply_config (config8 )
1473
+
1474
+ handler = logging .root .handlers [0 ]
1475
+ self .addCleanup (cleanup , handler , fn )
1476
+
1432
1477
def test_logger_disabling (self ):
1433
1478
self .apply_config (self .disable_test )
1434
1479
logger = logging .getLogger ('some_pristine_logger' )
@@ -1977,6 +2022,7 @@ class ConfigDictTest(BaseTest):
1977
2022
1978
2023
"""Reading logging config from a dictionary."""
1979
2024
2025
+ check_no_resource_warning = support .check_no_resource_warning
1980
2026
expected_log_pat = r"^(\w+) \+\+ (\w+)$"
1981
2027
1982
2028
# config0 is a standard configuration.
@@ -2851,6 +2897,35 @@ def test_config14_ok(self):
2851
2897
logging .warning ('Exclamation' )
2852
2898
self .assertTrue (output .getvalue ().endswith ('Exclamation!\n ' ))
2853
2899
2900
+ def test_config15_ok (self ):
2901
+
2902
+ def cleanup (h1 , fn ):
2903
+ h1 .close ()
2904
+ os .remove (fn )
2905
+
2906
+ with self .check_no_resource_warning ():
2907
+ fd , fn = tempfile .mkstemp (".log" , "test_logging-X-" )
2908
+ os .close (fd )
2909
+
2910
+ config = {
2911
+ "version" : 1 ,
2912
+ "handlers" : {
2913
+ "file" : {
2914
+ "class" : "logging.FileHandler" ,
2915
+ "filename" : fn
2916
+ }
2917
+ },
2918
+ "root" : {
2919
+ "handlers" : ["file" ]
2920
+ }
2921
+ }
2922
+
2923
+ self .apply_config (config )
2924
+ self .apply_config (config )
2925
+
2926
+ handler = logging .root .handlers [0 ]
2927
+ self .addCleanup (cleanup , handler , fn )
2928
+
2854
2929
@unittest .skipUnless (threading , 'listen() needs threading to work' )
2855
2930
def setup_via_listener (self , text , verify = None ):
2856
2931
text = text .encode ("utf-8" )
0 commit comments