Mercurial > p > roundup > code
comparison test/test_config.py @ 6356:c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
Was validated in backends/indexer_xapian.py which would throw
an error on access rather than on start.
Added validator function to CoreConfig class that runs after
config.ini is read. At this time we have access to the indexer setting
so can determine if xapian is actually going to be used.
Moved test into test/test_config.py and pulled validation code from
indexer_xapian.py and test/test_indexer.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 29 Mar 2021 22:47:54 -0400 |
| parents | c547e05d7a54 |
| children | c985ed52ca2d |
comparison
equal
deleted
inserted
replaced
| 6355:ac5a6ffa377b | 6356:c26b9ce33ae3 |
|---|---|
| 282 # this should fail as backend isn't defined. | 282 # this should fail as backend isn't defined. |
| 283 self.assertRaises(configuration.OptionUnsetError, instance.open, | 283 self.assertRaises(configuration.OptionUnsetError, instance.open, |
| 284 self.dirname) | 284 self.dirname) |
| 285 | 285 |
| 286 | 286 |
| 287 def testInvalidIndexer_language(self): | |
| 288 """ make sure we have a reasonable error message if | |
| 289 invalid language is specified """ | |
| 290 | |
| 291 # change the indexer_language value to an invalid value. | |
| 292 import fileinput | |
| 293 for line in fileinput.input(os.path.join(self.dirname, "config.ini"), | |
| 294 inplace=True): | |
| 295 if line.startswith("indexer_language = "): | |
| 296 print("indexer_language = NO_LANG") | |
| 297 continue | |
| 298 print(line[:-1]) # remove trailing \n | |
| 299 | |
| 300 config = configuration.CoreConfig() | |
| 301 | |
| 302 # Note this should raise OptionValueError, but | |
| 303 # the test fot this error occurs too late to have | |
| 304 # a valid option still available. So raise ValueError. | |
| 305 with self.assertRaises(ValueError) as cm: | |
| 306 config.load(self.dirname) | |
| 307 | |
| 308 print(cm.exception) | |
| 309 self.assertIn("ValueError", repr(cm.exception)) | |
| 310 # look for failing language | |
| 311 self.assertIn("NO_LANG", cm.exception.args[0]) | |
| 312 # look for supported language | |
| 313 self.assertIn("english", cm.exception.args[0]) | |
| 314 | |
| 315 def testLoadConfig(self): | |
| 316 """ run load to validate config """ | |
| 317 | |
| 318 config = configuration.CoreConfig() | |
| 319 | |
| 320 config.load(self.dirname) | |
| 321 | |
| 322 with self.assertRaises(configuration.InvalidOptionError) as cm: | |
| 323 c = config['indexer_language'] | |
| 324 print(cm.exception) | |
| 325 self.assertIn("indexer_language", repr(cm.exception)) | |
| 326 | |
| 327 self.assertEqual(config['HTML_VERSION'], 'html4') | |
| 328 self.assertEqual(config[('main', 'html_version')], 'html4') | |
| 329 | |
| 330 self.assertEqual(config['WEB_COOKIE_TAKES_PRECEDENCE'], 0) | |
| 331 self.assertEqual(config[('web','cookie_takes_precedence')], 0) | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 |
