diff 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
line wrap: on
line diff
--- a/tests/test-module-imports.t	Fri Dec 04 14:24:45 2015 -0800
+++ b/tests/test-module-imports.t	Sun Dec 06 14:18:19 2015 +0900
@@ -85,6 +85,16 @@
   >     import testpackage.subpackage.levelpriority
   > EOF
 
+  $ cat > testpackage/importmodulefromsub.py << EOF
+  > from __future__ import absolute_import
+  > from .subpackage import foo  # not a "direct symbol import"
+  > EOF
+
+  $ cat > testpackage/importsymbolfromsub.py << EOF
+  > from __future__ import absolute_import
+  > from .subpackage import foo, nonmodule
+  > EOF
+
   $ cat > testpackage/sortedentries.py << EOF
   > from __future__ import absolute_import
   > from . import (
@@ -108,6 +118,7 @@
   testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod
   testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted
   testpackage/importfromrelative.py:2: direct symbol import from testpackage.unsorted
+  testpackage/importsymbolfromsub.py:2: direct symbol import from testpackage.subpackage
   testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node
   testpackage/multiple.py:2: multiple imported names: os, sys
   testpackage/multiplegroups.py:3: multiple "from . import" statements