Mercurial > hg-stable
comparison tests/test-extension.t @ 41522:b0865b5919c6
py3: account for demand import difference between Python versions
Our lazy importer for Python 3 will validate that modules are
loadable before returning a stub module object. This is different
from Python 2, which will always return a stub module object.
While we could change behavior of the Python 3 demand importer,
that seems like a problem for another day.
This commit teaches test-extension.t about that difference in
behavior.
Differential Revision: https://phab.mercurial-scm.org/D5798
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 01 Feb 2019 17:03:51 -0800 |
parents | fa471151d269 |
children | a4cd77a425a3 |
comparison
equal
deleted
inserted
replaced
41521:30248d6bc057 | 41522:b0865b5919c6 |
---|---|
608 $ cat > $TESTTMP/checkrelativity.py <<NO_CHECK_EOF | 608 $ cat > $TESTTMP/checkrelativity.py <<NO_CHECK_EOF |
609 > from mercurial import registrar | 609 > from mercurial import registrar |
610 > cmdtable = {} | 610 > cmdtable = {} |
611 > command = registrar.command(cmdtable) | 611 > command = registrar.command(cmdtable) |
612 > | 612 > |
613 > # demand import avoids failure of importing notexist here | 613 > # demand import avoids failure of importing notexist here, but only on |
614 > # Python 2. | |
614 > import extlibroot.lsub1.lsub2.notexist | 615 > import extlibroot.lsub1.lsub2.notexist |
615 > | 616 > |
616 > @command(b'checkrelativity', [], norepo=True) | 617 > @command(b'checkrelativity', [], norepo=True) |
617 > def checkrelativity(ui, *args, **opts): | 618 > def checkrelativity(ui, *args, **opts): |
618 > try: | 619 > try: |
620 > return 1 # unintentional success | 621 > return 1 # unintentional success |
621 > except ImportError: | 622 > except ImportError: |
622 > pass # intentional failure | 623 > pass # intentional failure |
623 > NO_CHECK_EOF | 624 > NO_CHECK_EOF |
624 | 625 |
625 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.checkrelativity=$TESTTMP/checkrelativity.py checkrelativity) | 626 Python 3's lazy importer verifies modules exist before returning the lazy |
627 module stub. Our custom lazy importer for Python 2 always returns a stub. | |
628 | |
629 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.checkrelativity=$TESTTMP/checkrelativity.py checkrelativity) || true | |
630 *** failed to import extension checkrelativity from $TESTTMP/checkrelativity.py: No module named 'extlibroot.lsub1.lsub2.notexist' (py3 !) | |
631 hg: unknown command 'checkrelativity' (py3 !) | |
632 (use 'hg help' for a list of commands) (py3 !) | |
626 | 633 |
627 #endif | 634 #endif |
628 | 635 |
629 (Here, module importing tests are finished. Therefore, use other than | 636 (Here, module importing tests are finished. Therefore, use other than |
630 NO_CHECK_* limit mark for heredoc python files, in order to apply | 637 NO_CHECK_* limit mark for heredoc python files, in order to apply |