Mercurial > hg
comparison tests/test-module-imports.t @ 27272:69308357ecd1
import-checker: allow absolute imports of sub modules from local packages
Before this patch, import-checker.py didn't know if a name in ImportFrom
statement are module or not. Therefore, it complained the following example
did "direct symbol import from mercurial".
# hgext/foo.py
from mercurial import hg
This patch reuses the dict of local modules to filter out sub-module names.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 06 Dec 2015 14:18:19 +0900 |
parents | 1fa66d3ad28d |
children | 5d5b98346fc2 |
comparison
equal
deleted
inserted
replaced
27271:2a31433a59ba | 27272:69308357ecd1 |
---|---|
83 > # but other errors should be detected | 83 > # but other errors should be detected |
84 > from .. import more | 84 > from .. import more |
85 > import testpackage.subpackage.levelpriority | 85 > import testpackage.subpackage.levelpriority |
86 > EOF | 86 > EOF |
87 | 87 |
88 $ cat > testpackage/importmodulefromsub.py << EOF | |
89 > from __future__ import absolute_import | |
90 > from .subpackage import foo # not a "direct symbol import" | |
91 > EOF | |
92 | |
93 $ cat > testpackage/importsymbolfromsub.py << EOF | |
94 > from __future__ import absolute_import | |
95 > from .subpackage import foo, nonmodule | |
96 > EOF | |
97 | |
88 $ cat > testpackage/sortedentries.py << EOF | 98 $ cat > testpackage/sortedentries.py << EOF |
89 > from __future__ import absolute_import | 99 > from __future__ import absolute_import |
90 > from . import ( | 100 > from . import ( |
91 > foo, | 101 > foo, |
92 > bar, | 102 > bar, |
106 $ python "$import_checker" testpackage/*.py testpackage/subpackage/*.py | 116 $ python "$import_checker" testpackage/*.py testpackage/subpackage/*.py |
107 testpackage/importalias.py:2: ui module must be "as" aliased to uimod | 117 testpackage/importalias.py:2: ui module must be "as" aliased to uimod |
108 testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod | 118 testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod |
109 testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted | 119 testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted |
110 testpackage/importfromrelative.py:2: direct symbol import from testpackage.unsorted | 120 testpackage/importfromrelative.py:2: direct symbol import from testpackage.unsorted |
121 testpackage/importsymbolfromsub.py:2: direct symbol import from testpackage.subpackage | |
111 testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node | 122 testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node |
112 testpackage/multiple.py:2: multiple imported names: os, sys | 123 testpackage/multiple.py:2: multiple imported names: os, sys |
113 testpackage/multiplegroups.py:3: multiple "from . import" statements | 124 testpackage/multiplegroups.py:3: multiple "from . import" statements |
114 testpackage/relativestdlib.py:2: relative import of stdlib module | 125 testpackage/relativestdlib.py:2: relative import of stdlib module |
115 testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted | 126 testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted |