Mercurial > hg
comparison tests/test-imports-checker.t @ 34038:bc2535238de2
import-checker: allow relative import a module being checked
This would make the checker more friendly for 3rd-party code. For example,
In remotefilelog/x.py, it may have:
from . import shallowutils
That could trigger "relative import of stdlib module" if
"remotefilelog" was installed in the system. If the module being checked
conflicts with the system module, it makes sense to not treat that module as
system module. This patch makes it so.
Differential Revision: https://phab.mercurial-scm.org/D552
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 28 Aug 2017 13:43:25 -0700 |
parents | 8e6f4939a69a |
children | 5abc47d4ca6b |
comparison
equal
deleted
inserted
replaced
34037:65ae54582713 | 34038:bc2535238de2 |
---|---|
123 > from __future__ import absolute_import | 123 > from __future__ import absolute_import |
124 > from testpackage import unsorted | 124 > from testpackage import unsorted |
125 > from mercurial.node import hex | 125 > from mercurial.node import hex |
126 > EOF | 126 > EOF |
127 | 127 |
128 $ $PYTHON "$import_checker" testpackage*/*.py testpackage/subpackage/*.py | 128 # Shadowing a stdlib module to test "relative import of stdlib module" is |
129 # allowed if the module is also being checked | |
130 | |
131 $ mkdir email | |
132 $ touch email/__init__.py | |
133 $ touch email/errors.py | |
134 $ cat > email/utils.py << EOF | |
135 > from __future__ import absolute_import | |
136 > from . import errors | |
137 > EOF | |
138 | |
139 $ $PYTHON "$import_checker" testpackage*/*.py testpackage/subpackage/*.py \ | |
140 > email/*.py | |
129 testpackage/importalias.py:2: ui module must be "as" aliased to uimod | 141 testpackage/importalias.py:2: ui module must be "as" aliased to uimod |
130 testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod | 142 testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod |
131 testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted | 143 testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted |
132 testpackage/importfromrelative.py:2: direct symbol import foo from testpackage.unsorted | 144 testpackage/importfromrelative.py:2: direct symbol import foo from testpackage.unsorted |
133 testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage | 145 testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage |