Mercurial > p > roundup > code
comparison test/test_config.py @ 8424:4a948ad46579
test: fix testDictLoggerConfigViaJson
The path to the log file in the config did not exist. Change to use
the tracker home.
Also add a test where the log file directory does not exist. This
reports the full path, so have to edit the full path in the error
message before comparison.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 20 Aug 2025 11:17:23 -0400 |
| parents | 94eed885e958 |
| children | cd0edc091b97 |
comparison
equal
deleted
inserted
replaced
| 8423:94eed885e958 | 8424:4a948ad46579 |
|---|---|
| 18 import errno | 18 import errno |
| 19 import fileinput | 19 import fileinput |
| 20 import logging | 20 import logging |
| 21 import os | 21 import os |
| 22 import pytest | 22 import pytest |
| 23 import re | |
| 23 import shutil | 24 import shutil |
| 24 import sys | 25 import sys |
| 25 import unittest | 26 import unittest |
| 26 | 27 |
| 27 from os.path import normpath | 28 from os.path import normpath |
| 1070 # create an access.log style http log file | 1071 # create an access.log style http log file |
| 1071 "access": { | 1072 "access": { |
| 1072 "level": "INFO", | 1073 "level": "INFO", |
| 1073 "formatter": "http", | 1074 "formatter": "http", |
| 1074 "class": "logging.FileHandler", | 1075 "class": "logging.FileHandler", |
| 1075 "filename": "demo/access.log" | 1076 "filename": "_test_instance/access.log" |
| 1076 }, | 1077 }, |
| 1077 # logging for roundup.* loggers | 1078 # logging for roundup.* loggers |
| 1078 "roundup": { | 1079 "roundup": { |
| 1079 "level": "DEBUG", | 1080 "level": "DEBUG", |
| 1080 "formatter": "standard", | 1081 "formatter": "standard", |
| 1081 "class": "logging.FileHandler", | 1082 "class": "logging.FileHandler", |
| 1082 "filename": "demo/roundup.log" | 1083 "filename": "_test_instance/roundup.log" |
| 1083 }, | 1084 }, |
| 1084 # print to stdout - fall through for other logging | 1085 # print to stdout - fall through for other logging |
| 1085 "default": { | 1086 "default": { |
| 1086 "level": "DEBUG", | 1087 "level": "DEBUG", |
| 1087 "formatter": "standard", | 1088 "formatter": "standard", |
| 1239 "_test_instance/_test_log_config.json.\nValueError: " | 1240 "_test_instance/_test_log_config.json.\nValueError: " |
| 1240 "Unable to configure logger 'roundup.hyperdb'\nUnknown level: " | 1241 "Unable to configure logger 'roundup.hyperdb'\nUnknown level: " |
| 1241 "'MANGO'\n") | 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 |
