Skip to content

Commit ab9a37b

Browse files
committed
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.
1 parent 28b5642 commit ab9a37b

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

test/test_config.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121
import os
2222
import pytest
23+
import re
2324
import shutil
2425
import sys
2526
import unittest
@@ -1072,14 +1073,14 @@ def testDictLoggerConfigViaJson(self):
10721073
"level": "INFO",
10731074
"formatter": "http",
10741075
"class": "logging.FileHandler",
1075-
"filename": "demo/access.log"
1076+
"filename": "_test_instance/access.log"
10761077
},
10771078
# logging for roundup.* loggers
10781079
"roundup": {
10791080
"level": "DEBUG",
10801081
"formatter": "standard",
10811082
"class": "logging.FileHandler",
1082-
"filename": "demo/roundup.log"
1083+
"filename": "_test_instance/roundup.log"
10831084
},
10841085
# print to stdout - fall through for other logging
10851086
"default": {
@@ -1241,3 +1242,29 @@ def testDictLoggerConfigViaJson(self):
12411242
"'MANGO'\n")
12421243

12431244
)
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

Comments
 (0)