comparison test/test_config.py @ 8434:66284037142e

refactor: also error on missing file or invalid extension Refactored the code to reuse check that logging config file is set and that the file exists. Now throws error and exits if file name does not end in .ini or .json. Now throws error if file doesn't exist. Before it would just configure default logging as though file wasn't specified. Added tests for these two cases.
author John Rouillard <rouilj@ieee.org>
date Tue, 26 Aug 2025 23:06:40 -0400
parents de1dac9abcb6
children 39a6825d10ca
comparison
equal deleted inserted replaced
8433:de1dac9abcb6 8434:66284037142e
1368 "ValueError: Unable to configure handler 'access'\n" 1368 "ValueError: Unable to configure handler 'access'\n"
1369 "[Errno 2] No such file or directory: " 1369 "[Errno 2] No such file or directory: "
1370 "%s'\n" % (log_config_filename, access_filename)) 1370 "%s'\n" % (log_config_filename, access_filename))
1371 self.assertEqual(output, target) 1371 self.assertEqual(output, target)
1372 1372
1373 def test_missing_logging_config_file(self):
1374 saved_config = self.db.config['LOGGING_CONFIG']
1375
1376 self.db.config['LOGGING_CONFIG'] = 'logging.json'
1377
1378 with self.assertRaises(configuration.OptionValueError) as cm:
1379 self.db.config.init_logging()
1380
1381 self.assertEqual(cm.exception.args[1], "_test_instance/logging.json")
1382 self.assertEqual(cm.exception.args[2],
1383 "Unable to find logging config file.")
1384
1385 self.db.config['LOGGING_CONFIG'] = 'logging.ini'
1386
1387 with self.assertRaises(configuration.OptionValueError) as cm:
1388 self.db.config.init_logging()
1389
1390 self.assertEqual(cm.exception.args[1], "_test_instance/logging.ini")
1391 self.assertEqual(cm.exception.args[2],
1392 "Unable to find logging config file.")
1393
1394 self.db.config['LOGGING_CONFIG'] = saved_config
1395
1396 def test_unknown_logging_config_file_type(self):
1397 saved_config = self.db.config['LOGGING_CONFIG']
1398
1399 self.db.config['LOGGING_CONFIG'] = 'schema.py'
1400
1401
1402 with self.assertRaises(configuration.OptionValueError) as cm:
1403 self.db.config.init_logging()
1404
1405 self.assertEqual(cm.exception.args[1], "_test_instance/schema.py")
1406 self.assertEqual(cm.exception.args[2],
1407 "Unable to load logging config file. "
1408 "File extension must be '.ini' or '.json'.\n")
1409
1410 self.db.config['LOGGING_CONFIG'] = saved_config

Roundup Issue Tracker: http://roundup-tracker.org/