|
20 | 20 | import logging
|
21 | 21 | import os
|
22 | 22 | import pytest
|
| 23 | +import re |
23 | 24 | import shutil
|
24 | 25 | import sys
|
25 | 26 | import unittest
|
@@ -1072,14 +1073,14 @@ def testDictLoggerConfigViaJson(self):
|
1072 | 1073 | "level": "INFO",
|
1073 | 1074 | "formatter": "http",
|
1074 | 1075 | "class": "logging.FileHandler",
|
1075 |
| - "filename": "demo/access.log" |
| 1076 | + "filename": "_test_instance/access.log" |
1076 | 1077 | },
|
1077 | 1078 | # logging for roundup.* loggers
|
1078 | 1079 | "roundup": {
|
1079 | 1080 | "level": "DEBUG",
|
1080 | 1081 | "formatter": "standard",
|
1081 | 1082 | "class": "logging.FileHandler",
|
1082 |
| - "filename": "demo/roundup.log" |
| 1083 | + "filename": "_test_instance/roundup.log" |
1083 | 1084 | },
|
1084 | 1085 | # print to stdout - fall through for other logging
|
1085 | 1086 | "default": {
|
@@ -1241,3 +1242,29 @@ def testDictLoggerConfigViaJson(self):
|
1241 | 1242 | "'MANGO'\n")
|
1242 | 1243 |
|
1243 | 1244 | )
|
| 1245 | + |
| 1246 | + # broken invalid output directory |
| 1247 | + test_config = config1.replace( |
| 1248 | + ' "_test_instance/access.log"', |
| 1249 | + ' "not_a_test_instance/access.log"') |
| 1250 | + with open(log_config_filename, "w") as log_config_file: |
| 1251 | + log_config_file.write(test_config) |
| 1252 | + |
| 1253 | + # file is made relative to tracker dir. |
| 1254 | + self.db.config["LOGGING_CONFIG"] = '_test_log_config.json' |
| 1255 | + with self.assertRaises(configuration.LoggingConfigError) as cm: |
| 1256 | + config = self.db.config.init_logging() |
| 1257 | + |
| 1258 | + # error includes full path which is different on different |
| 1259 | + # CI and dev platforms. So munge the path using re.sub. |
| 1260 | + self.assertEqual( |
| 1261 | + re.sub("directory: \'/.*not_a", 'directory: not_a' , |
| 1262 | + cm.exception.args[0]), |
| 1263 | + ("Error loading logging dict from " |
| 1264 | + "_test_instance/_test_log_config.json.\n" |
| 1265 | + "ValueError: Unable to configure handler 'access'\n" |
| 1266 | + "[Errno 2] No such file or directory: " |
| 1267 | + "not_a_test_instance/access.log'\n" |
| 1268 | + ) |
| 1269 | + ) |
| 1270 | + |
0 commit comments