comparison test/test_indexer.py @ 7070:c6b2534a58a9

Compatibility: unittest.mock vs. only mock Python3 has unittest.mock while python2 has only mock. At least on the systems tested (with installed unittest).
author Ralf Schlatterbeck <rsc@runtux.com>
date Thu, 24 Nov 2022 10:29:37 +0100
parents 9ff091537f43
children 890b8f4ff38e
comparison
equal deleted inserted replaced
7066:27c2d7295ba2 7070:c6b2534a58a9
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE. 19 # SOFTWARE.
20 20
21 import os, unittest, shutil 21 import os, sys, unittest, shutil
22 22
23 import pytest 23 import pytest
24 from roundup.backends import get_backend, have_backend 24 from roundup.backends import get_backend, have_backend
25 from roundup.backends.indexer_rdbms import Indexer 25 from roundup.backends.indexer_rdbms import Indexer
26 from roundup.backends.indexer_common import get_indexer 26 from roundup.backends.indexer_common import get_indexer
31 from .db_test_base import setupSchema, config 31 from .db_test_base import setupSchema, config
32 from .test_postgresql import postgresqlOpener, skip_postgresql 32 from .test_postgresql import postgresqlOpener, skip_postgresql
33 from .test_mysql import mysqlOpener, skip_mysql 33 from .test_mysql import mysqlOpener, skip_mysql
34 from .test_sqlite import sqliteOpener 34 from .test_sqlite import sqliteOpener
35 from .test_anydbm import anydbmOpener 35 from .test_anydbm import anydbmOpener
36
37 try:
38 from unittest import mock
39 except ImportError:
40 import mock
36 41
37 try: 42 try:
38 import xapian 43 import xapian
39 skip_xapian = lambda func, *args, **kwargs: func 44 skip_xapian = lambda func, *args, **kwargs: func
40 except ImportError: 45 except ImportError:
278 indexer = get_indexer(self.db.config, self.db) 283 indexer = get_indexer(self.db.config, self.db)
279 self.assertIn('roundup.backends.indexer_xapian.Indexer', str(indexer)) 284 self.assertIn('roundup.backends.indexer_xapian.Indexer', str(indexer))
280 285
281 @skip_whoosh 286 @skip_whoosh
282 def test_whoosh_autoselect(self): 287 def test_whoosh_autoselect(self):
283 import mock, sys
284 with mock.patch.dict('sys.modules', 288 with mock.patch.dict('sys.modules',
285 {'roundup.backends.indexer_xapian': None}): 289 {'roundup.backends.indexer_xapian': None}):
286 indexer = get_indexer(self.db.config, self.db) 290 indexer = get_indexer(self.db.config, self.db)
287 self.assertIn('roundup.backends.indexer_whoosh.Indexer', str(indexer)) 291 self.assertIn('roundup.backends.indexer_whoosh.Indexer', str(indexer))
288 292
289 def test_native_autoselect(self): 293 def test_native_autoselect(self):
290 import mock, sys
291 with mock.patch.dict('sys.modules', 294 with mock.patch.dict('sys.modules',
292 {'roundup.backends.indexer_xapian': None, 295 {'roundup.backends.indexer_xapian': None,
293 'roundup.backends.indexer_whoosh': None}): 296 'roundup.backends.indexer_whoosh': None}):
294 indexer = get_indexer(self.db.config, self.db) 297 indexer = get_indexer(self.db.config, self.db)
295 self.assertIn('roundup.backends.indexer_dbm.Indexer', str(indexer)) 298 self.assertIn('roundup.backends.indexer_dbm.Indexer', str(indexer))

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