Mercurial > p > roundup > code
comparison test/test_config.py @ 8426:cd0edc091b97
test: more fixes for variations among python versions.
reset logging. The loggers I installed are bleeding through to tests
in other modules.
Then handle recogniton of:
trailing comma in json reporting line with comma not following line
incorrect type value in dictConfig int where string should be
3.7 fils to detect. 3.10+ add "got 'int'" to reason.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 20 Aug 2025 12:53:14 -0400 |
| parents | 4a948ad46579 |
| children | b34c3b8338f0 |
comparison
equal
deleted
inserted
replaced
| 8425:3db40a355a6c | 8426:cd0edc091b97 |
|---|---|
| 1049 self.assertIn("nati", string_rep) | 1049 self.assertIn("nati", string_rep) |
| 1050 self.assertIn("'whoosh'", string_rep) | 1050 self.assertIn("'whoosh'", string_rep) |
| 1051 | 1051 |
| 1052 def testDictLoggerConfigViaJson(self): | 1052 def testDictLoggerConfigViaJson(self): |
| 1053 | 1053 |
| 1054 # test case broken, comment on version line misformatted | 1054 # good base test case |
| 1055 config1 = dedent(""" | 1055 config1 = dedent(""" |
| 1056 { | 1056 { |
| 1057 "version": 1, # only supported version | 1057 "version": 1, # only supported version |
| 1058 "disable_existing_loggers": false, # keep the wsgi loggers | 1058 "disable_existing_loggers": false, # keep the wsgi loggers |
| 1059 | 1059 |
| 1176 log_config_file.write(test_config) | 1176 log_config_file.write(test_config) |
| 1177 | 1177 |
| 1178 with self.assertRaises(configuration.LoggingConfigError) as cm: | 1178 with self.assertRaises(configuration.LoggingConfigError) as cm: |
| 1179 config = self.db.config.load_config_dict_from_json_file( | 1179 config = self.db.config.load_config_dict_from_json_file( |
| 1180 log_config_filename) | 1180 log_config_filename) |
| 1181 self.assertEqual( | 1181 #pre 3.12?? |
| 1182 cm.exception.args[0], | 1182 # FIXME check/remove when 3.13. is min supported version |
| 1183 ('Error parsing json logging dict ' | 1183 if "property name" in cm.exception.args[0]: |
| 1184 '(_test_instance/_test_log_config.json) near \n\n' | 1184 self.assertEqual( |
| 1185 ' }\n\nExpecting property name enclosed in double ' | 1185 cm.exception.args[0], |
| 1186 'quotes: line 37 column 6.') | 1186 ('Error parsing json logging dict ' |
| 1187 ) | 1187 '(_test_instance/_test_log_config.json) near \n\n' |
| 1188 ' }\n\nExpecting property name enclosed in double ' | |
| 1189 'quotes: line 37 column 6.') | |
| 1190 ) | |
| 1191 | |
| 1192 # 3.13+ diags FIXME | |
| 1193 print('FINDME') | |
| 1194 print(cm.exception.args[0]) | |
| 1195 _junk = ''' | |
| 1196 if "property name" not in cm.exception.args[0]: | |
| 1197 self.assertEqual( | |
| 1198 cm.exception.args[0], | |
| 1199 ('Error parsing json logging dict ' | |
| 1200 '(_test_instance/_test_log_config.json) near \n\n' | |
| 1201 ' }\n\nExpecting property name enclosed in double ' | |
| 1202 'quotes: line 37 column 6.') | |
| 1203 ) | |
| 1204 ''' | |
| 1188 | 1205 |
| 1189 # happy path for init_logging() | 1206 # happy path for init_logging() |
| 1190 | 1207 |
| 1191 # verify preconditions | 1208 # verify preconditions |
| 1192 logger = logging.getLogger("roundup") | 1209 logger = logging.getLogger("roundup") |
| 1211 with open(log_config_filename, "w") as log_config_file: | 1228 with open(log_config_filename, "w") as log_config_file: |
| 1212 log_config_file.write(test_config) | 1229 log_config_file.write(test_config) |
| 1213 | 1230 |
| 1214 # file is made relative to tracker dir. | 1231 # file is made relative to tracker dir. |
| 1215 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json' | 1232 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json' |
| 1216 with self.assertRaises(configuration.LoggingConfigError) as cm: | 1233 |
| 1217 config = self.db.config.init_logging() | 1234 |
| 1218 self.assertEqual( | 1235 # different versions of python have different errors |
| 1219 cm.exception.args[0], | 1236 # (or no error for this case in 3.7) |
| 1220 ('Error loading logging dict from ' | 1237 # FIXME remove version check post 3.7 as minimum version |
| 1221 '_test_instance/_test_log_config.json.\n' | 1238 if sys.version_info > (3,7): |
| 1222 "ValueError: Unable to configure formatter 'http'\n" | 1239 with self.assertRaises(configuration.LoggingConfigError) as cm: |
| 1223 'expected string or bytes-like object\n') | 1240 config = self.db.config.init_logging() |
| 1224 ) | 1241 |
| 1242 # mangle args[0] to add got 'int' | |
| 1243 # FIXME: remove mangle after 3.12 min version | |
| 1244 self.assertEqual( | |
| 1245 cm.exception.args[0].replace( | |
| 1246 "object\n", "object, got 'int'\n"), | |
| 1247 ('Error loading logging dict from ' | |
| 1248 '_test_instance/_test_log_config.json.\n' | |
| 1249 "ValueError: Unable to configure formatter 'http'\n" | |
| 1250 "expected string or bytes-like object, got 'int'\n") | |
| 1251 ) | |
| 1225 | 1252 |
| 1226 # broken invalid level MANGO | 1253 # broken invalid level MANGO |
| 1227 test_config = config1.replace( | 1254 test_config = config1.replace( |
| 1228 ': "INFO", # can', | 1255 ': "INFO", # can', |
| 1229 ': "MANGO", # can') | 1256 ': "MANGO", # can') |
| 1266 "[Errno 2] No such file or directory: " | 1293 "[Errno 2] No such file or directory: " |
| 1267 "not_a_test_instance/access.log'\n" | 1294 "not_a_test_instance/access.log'\n" |
| 1268 ) | 1295 ) |
| 1269 ) | 1296 ) |
| 1270 | 1297 |
| 1298 # rip down all the loggers leaving the root logger reporting to stdout. | |
| 1299 # otherwise logger config is leaking to other tests | |
| 1300 | |
| 1301 from importlib import reload | |
| 1302 logging.shutdown() | |
| 1303 reload(logging) | |
| 1304 |
