comparison test/test_config.py @ 6367:8a7de159d1a6

issue2551125 Make indexer_lang test work if xapian not installed. Reported by Ralf in https://issues.roundup-tracker.org/issue2551125.
author John Rouillard <rouilj@ieee.org>
date Wed, 31 Mar 2021 08:43:03 -0400
parents 08e209a7f22b
children e3ed3ad9e795
comparison
equal deleted inserted replaced
6364:e8361bce72de 6367:8a7de159d1a6
21 21
22 import os, shutil, errno 22 import os, shutil, errno
23 23
24 import pytest 24 import pytest
25 from roundup import configuration 25 from roundup import configuration
26
27 try:
28 import xapian
29 skip_xapian = lambda func, *args, **kwargs: func
30 except ImportError:
31 # FIX: workaround for a bug in pytest.mark.skip():
32 # https://github.com/pytest-dev/pytest/issues/568
33 from .pytest_patcher import mark_class
34 skip_xapian = mark_class(pytest.mark.skip(
35 "Skipping Xapian indexer tests: 'xapian' not installed"))
26 36
27 config = configuration.CoreConfig() 37 config = configuration.CoreConfig()
28 config.DATABASE = "db" 38 config.DATABASE = "db"
29 config.RDBMS_NAME = "rounduptest" 39 config.RDBMS_NAME = "rounduptest"
30 config.RDBMS_HOST = "localhost" 40 config.RDBMS_HOST = "localhost"
370 instance.open(self.dirname) 380 instance.open(self.dirname)
371 381
372 self.assertEqual("RDBMS_BACKEND is not set" 382 self.assertEqual("RDBMS_BACKEND is not set"
373 " and has no default", cm.exception.__str__()) 383 " and has no default", cm.exception.__str__())
374 384
385 @skip_xapian
375 def testInvalidIndexerLanguage_w_empty(self): 386 def testInvalidIndexerLanguage_w_empty(self):
376 """ make sure we have a reasonable error message if 387 """ make sure we have a reasonable error message if
377 invalid indexer language is specified. This uses 388 invalid indexer language is specified. This uses
378 default search path for indexers. 389 default search path for indexers.
379 """ 390 """
412 sys.modules['xapian'] = None 423 sys.modules['xapian'] = None
413 config.load(self.dirname) 424 config.load(self.dirname)
414 425
415 # need to delete both to make python2 not error finding _xapian 426 # need to delete both to make python2 not error finding _xapian
416 del(sys.modules['xapian']) 427 del(sys.modules['xapian'])
417 del(sys.modules['xapian._xapian']) 428 if xapian._xapian in sys.modules:
429 del(sys.modules['xapian._xapian'])
418 430
419 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG') 431 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
420 432
421 # do a reset here to test reset rather than wasting cycles 433 # do a reset here to test reset rather than wasting cycles
422 # to do setup in a different test 434 # to do setup in a different test
436 config.load(self.dirname) 448 config.load(self.dirname)
437 449
438 self.assertEqual(config['HTML_VERSION'], 'html4') 450 self.assertEqual(config['HTML_VERSION'], 'html4')
439 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG') 451 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
440 452
453 @skip_xapian
441 def testInvalidIndexerLanguage_w_xapian(self): 454 def testInvalidIndexerLanguage_w_xapian(self):
442 """ Use explicit xapian indexer. Verify exception is 455 """ Use explicit xapian indexer. Verify exception is
443 generated. 456 generated.
444 """ 457 """
445 458

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