@@ -1089,6 +1089,7 @@ class ConfigFileTest(BaseTest):
1089
1089
1090
1090
"""Reading logging config from a .ini-style config file."""
1091
1091
1092
+ check_no_resource_warning = support .check_no_resource_warning
1092
1093
expected_log_pat = r"^(\w+) \+\+ (\w+)$"
1093
1094
1094
1095
# config0 is a standard configuration.
@@ -1297,6 +1298,27 @@ class ConfigFileTest(BaseTest):
1297
1298
datefmt=
1298
1299
"""
1299
1300
1301
+ # config 8, check for resource warning
1302
+ config8 = r"""
1303
+ [loggers]
1304
+ keys=root
1305
+
1306
+ [handlers]
1307
+ keys=file
1308
+
1309
+ [formatters]
1310
+ keys=
1311
+
1312
+ [logger_root]
1313
+ level=DEBUG
1314
+ handlers=file
1315
+
1316
+ [handler_file]
1317
+ class=FileHandler
1318
+ level=DEBUG
1319
+ args=("{tempfile}",)
1320
+ """
1321
+
1300
1322
disable_test = """
1301
1323
[loggers]
1302
1324
keys=root
@@ -1442,6 +1464,29 @@ def test_config7_ok(self):
1442
1464
# Original logger output is empty.
1443
1465
self .assert_log_lines ([])
1444
1466
1467
+ def test_config8_ok (self ):
1468
+
1469
+ def cleanup (h1 , fn ):
1470
+ h1 .close ()
1471
+ os .remove (fn )
1472
+
1473
+ with self .check_no_resource_warning ():
1474
+ fd , fn = tempfile .mkstemp (".log" , "test_logging-X-" )
1475
+ os .close (fd )
1476
+
1477
+ # Replace single backslash with double backslash in windows
1478
+ # to avoid unicode error during string formatting
1479
+ if os .name == "nt" :
1480
+ fn = fn .replace ("\\ " , "\\ \\ " )
1481
+
1482
+ config8 = self .config8 .format (tempfile = fn )
1483
+
1484
+ self .apply_config (config8 )
1485
+ self .apply_config (config8 )
1486
+
1487
+ handler = logging .root .handlers [0 ]
1488
+ self .addCleanup (cleanup , handler , fn )
1489
+
1445
1490
def test_logger_disabling (self ):
1446
1491
self .apply_config (self .disable_test )
1447
1492
logger = logging .getLogger ('some_pristine_logger' )
@@ -2022,6 +2067,7 @@ class ConfigDictTest(BaseTest):
2022
2067
2023
2068
"""Reading logging config from a dictionary."""
2024
2069
2070
+ check_no_resource_warning = support .check_no_resource_warning
2025
2071
expected_log_pat = r"^(\w+) \+\+ (\w+)$"
2026
2072
2027
2073
# config0 is a standard configuration.
@@ -2896,6 +2942,35 @@ def test_config14_ok(self):
2896
2942
logging .warning ('Exclamation' )
2897
2943
self .assertTrue (output .getvalue ().endswith ('Exclamation!\n ' ))
2898
2944
2945
+ def test_config15_ok (self ):
2946
+
2947
+ def cleanup (h1 , fn ):
2948
+ h1 .close ()
2949
+ os .remove (fn )
2950
+
2951
+ with self .check_no_resource_warning ():
2952
+ fd , fn = tempfile .mkstemp (".log" , "test_logging-X-" )
2953
+ os .close (fd )
2954
+
2955
+ config = {
2956
+ "version" : 1 ,
2957
+ "handlers" : {
2958
+ "file" : {
2959
+ "class" : "logging.FileHandler" ,
2960
+ "filename" : fn
2961
+ }
2962
+ },
2963
+ "root" : {
2964
+ "handlers" : ["file" ]
2965
+ }
2966
+ }
2967
+
2968
+ self .apply_config (config )
2969
+ self .apply_config (config )
2970
+
2971
+ handler = logging .root .handlers [0 ]
2972
+ self .addCleanup (cleanup , handler , fn )
2973
+
2899
2974
def setup_via_listener (self , text , verify = None ):
2900
2975
text = text .encode ("utf-8" )
2901
2976
# Ask for a randomly assigned port (by using port 0)
0 commit comments