Mercurial > p > roundup > code
diff 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 |
line wrap: on
line diff
--- a/test/test_config.py Tue Aug 26 22:24:00 2025 -0400 +++ b/test/test_config.py Tue Aug 26 23:06:40 2025 -0400 @@ -1370,3 +1370,41 @@ "%s'\n" % (log_config_filename, access_filename)) self.assertEqual(output, target) + def test_missing_logging_config_file(self): + saved_config = self.db.config['LOGGING_CONFIG'] + + self.db.config['LOGGING_CONFIG'] = 'logging.json' + + with self.assertRaises(configuration.OptionValueError) as cm: + self.db.config.init_logging() + + self.assertEqual(cm.exception.args[1], "_test_instance/logging.json") + self.assertEqual(cm.exception.args[2], + "Unable to find logging config file.") + + self.db.config['LOGGING_CONFIG'] = 'logging.ini' + + with self.assertRaises(configuration.OptionValueError) as cm: + self.db.config.init_logging() + + self.assertEqual(cm.exception.args[1], "_test_instance/logging.ini") + self.assertEqual(cm.exception.args[2], + "Unable to find logging config file.") + + self.db.config['LOGGING_CONFIG'] = saved_config + + def test_unknown_logging_config_file_type(self): + saved_config = self.db.config['LOGGING_CONFIG'] + + self.db.config['LOGGING_CONFIG'] = 'schema.py' + + + with self.assertRaises(configuration.OptionValueError) as cm: + self.db.config.init_logging() + + self.assertEqual(cm.exception.args[1], "_test_instance/schema.py") + self.assertEqual(cm.exception.args[2], + "Unable to load logging config file. " + "File extension must be '.ini' or '.json'.\n") + + self.db.config['LOGGING_CONFIG'] = saved_config
