Mercurial > p > roundup > code
changeset 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 | 3db40a355a6c |
| files | test/test_config.py |
| diffstat | 1 files changed, 29 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_config.py Tue Aug 19 22:32:46 2025 -0400 +++ b/test/test_config.py Wed Aug 20 11:17:23 2025 -0400 @@ -20,6 +20,7 @@ import logging import os import pytest +import re import shutil import sys import unittest @@ -1072,14 +1073,14 @@ "level": "INFO", "formatter": "http", "class": "logging.FileHandler", - "filename": "demo/access.log" + "filename": "_test_instance/access.log" }, # logging for roundup.* loggers "roundup": { "level": "DEBUG", "formatter": "standard", "class": "logging.FileHandler", - "filename": "demo/roundup.log" + "filename": "_test_instance/roundup.log" }, # print to stdout - fall through for other logging "default": { @@ -1241,3 +1242,29 @@ "'MANGO'\n") ) + + # broken invalid output directory + test_config = config1.replace( + ' "_test_instance/access.log"', + ' "not_a_test_instance/access.log"') + with open(log_config_filename, "w") as log_config_file: + log_config_file.write(test_config) + + # file is made relative to tracker dir. + self.db.config["LOGGING_CONFIG"] = '_test_log_config.json' + with self.assertRaises(configuration.LoggingConfigError) as cm: + config = self.db.config.init_logging() + + # error includes full path which is different on different + # CI and dev platforms. So munge the path using re.sub. + self.assertEqual( + re.sub("directory: \'/.*not_a", 'directory: not_a' , + cm.exception.args[0]), + ("Error loading logging dict from " + "_test_instance/_test_log_config.json.\n" + "ValueError: Unable to configure handler 'access'\n" + "[Errno 2] No such file or directory: " + "not_a_test_instance/access.log'\n" + ) + ) +
