Mercurial > p > roundup > code
comparison test/test_config.py @ 6368:e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
Test case for xapian not installed. Same test as
testInvalidIndexerLanguage_xapian_missing except without magling
sys.modules.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 31 Mar 2021 09:19:03 -0400 |
| parents | 8a7de159d1a6 |
| children | 5c1db5d4baed |
comparison
equal
deleted
inserted
replaced
| 6367:8a7de159d1a6 | 6368:e3ed3ad9e795 |
|---|---|
| 25 from roundup import configuration | 25 from roundup import configuration |
| 26 | 26 |
| 27 try: | 27 try: |
| 28 import xapian | 28 import xapian |
| 29 skip_xapian = lambda func, *args, **kwargs: func | 29 skip_xapian = lambda func, *args, **kwargs: func |
| 30 from .pytest_patcher import mark_class | |
| 31 include_no_xapian = mark_class(pytest.mark.skip( | |
| 32 "Skipping missing Xapian indexer tests: 'xapian' is installed")) | |
| 30 except ImportError: | 33 except ImportError: |
| 31 # FIX: workaround for a bug in pytest.mark.skip(): | 34 # FIX: workaround for a bug in pytest.mark.skip(): |
| 32 # https://github.com/pytest-dev/pytest/issues/568 | 35 # https://github.com/pytest-dev/pytest/issues/568 |
| 33 from .pytest_patcher import mark_class | 36 from .pytest_patcher import mark_class |
| 34 skip_xapian = mark_class(pytest.mark.skip( | 37 skip_xapian = mark_class(pytest.mark.skip( |
| 35 "Skipping Xapian indexer tests: 'xapian' not installed")) | 38 "Skipping Xapian indexer tests: 'xapian' not installed")) |
| 39 include_no_xapian = lambda func, *args, **kwargs: func | |
| 40 | |
| 36 | 41 |
| 37 config = configuration.CoreConfig() | 42 config = configuration.CoreConfig() |
| 38 config.DATABASE = "db" | 43 config.DATABASE = "db" |
| 39 config.RDBMS_NAME = "rounduptest" | 44 config.RDBMS_NAME = "rounduptest" |
| 40 config.RDBMS_HOST = "localhost" | 45 config.RDBMS_HOST = "localhost" |
| 404 # look for failing language | 409 # look for failing language |
| 405 self.assertIn("NO_LANG", cm.exception.args[1]) | 410 self.assertIn("NO_LANG", cm.exception.args[1]) |
| 406 # look for supported language | 411 # look for supported language |
| 407 self.assertIn("english", cm.exception.args[2]) | 412 self.assertIn("english", cm.exception.args[2]) |
| 408 | 413 |
| 414 @include_no_xapian | |
| 415 def testInvalidIndexerLanguage_w_empty_no_xapian(self): | |
| 416 """ Test case for empty indexer if xapian really isn't installed | |
| 417 | |
| 418 This should behave like testInvalidIndexerLanguage_xapian_missing | |
| 419 but without all the sys.modules mangling. | |
| 420 """ | |
| 421 print("Testing when xapian is not installed") | |
| 422 | |
| 423 # SETUP: set indexer_language value to an invalid value. | |
| 424 self.munge_configini(mods=[ ("indexer = ", ""), | |
| 425 ("indexer_language = ", "NO_LANG") ]) | |
| 426 | |
| 427 config = configuration.CoreConfig() | |
| 428 | |
| 429 config.load(self.dirname) | |
| 430 | |
| 431 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG') | |
| 432 | |
| 409 def testInvalidIndexerLanguage_xapian_missing(self): | 433 def testInvalidIndexerLanguage_xapian_missing(self): |
| 410 """Using default path for indexers, make import of xapian | 434 """Using default path for indexers, make import of xapian |
| 411 fail and prevent exception from happening even though | 435 fail and prevent exception from happening even though |
| 412 the indexer_language would be invalid for xapian. | 436 the indexer_language would be invalid for xapian. |
| 413 """ | 437 """ |
