##// END OF EJS Templates
tests: enable import checker for all **.py files...
Yuya Nishihara -
r29212:8005e0e0 default
parent child Browse files
Show More
@@ -1,177 +1,181 b''
1 #require test-repo
1 #require test-repo
2
2
3 $ import_checker="$TESTDIR"/../contrib/import-checker.py
3 $ import_checker="$TESTDIR"/../contrib/import-checker.py
4
4
5 Run the doctests from the import checker, and make sure
5 Run the doctests from the import checker, and make sure
6 it's working correctly.
6 it's working correctly.
7 $ TERM=dumb
7 $ TERM=dumb
8 $ export TERM
8 $ export TERM
9 $ python -m doctest $import_checker
9 $ python -m doctest $import_checker
10
10
11 Run additional tests for the import checker
11 Run additional tests for the import checker
12
12
13 $ mkdir testpackage
13 $ mkdir testpackage
14 $ touch testpackage/__init__.py
14 $ touch testpackage/__init__.py
15
15
16 $ cat > testpackage/multiple.py << EOF
16 $ cat > testpackage/multiple.py << EOF
17 > from __future__ import absolute_import
17 > from __future__ import absolute_import
18 > import os, sys
18 > import os, sys
19 > EOF
19 > EOF
20
20
21 $ cat > testpackage/unsorted.py << EOF
21 $ cat > testpackage/unsorted.py << EOF
22 > from __future__ import absolute_import
22 > from __future__ import absolute_import
23 > import sys
23 > import sys
24 > import os
24 > import os
25 > EOF
25 > EOF
26
26
27 $ cat > testpackage/stdafterlocal.py << EOF
27 $ cat > testpackage/stdafterlocal.py << EOF
28 > from __future__ import absolute_import
28 > from __future__ import absolute_import
29 > from . import unsorted
29 > from . import unsorted
30 > import os
30 > import os
31 > EOF
31 > EOF
32
32
33 $ cat > testpackage/requirerelative.py << EOF
33 $ cat > testpackage/requirerelative.py << EOF
34 > from __future__ import absolute_import
34 > from __future__ import absolute_import
35 > import testpackage.unsorted
35 > import testpackage.unsorted
36 > EOF
36 > EOF
37
37
38 $ cat > testpackage/importalias.py << EOF
38 $ cat > testpackage/importalias.py << EOF
39 > from __future__ import absolute_import
39 > from __future__ import absolute_import
40 > import ui
40 > import ui
41 > EOF
41 > EOF
42
42
43 $ cat > testpackage/relativestdlib.py << EOF
43 $ cat > testpackage/relativestdlib.py << EOF
44 > from __future__ import absolute_import
44 > from __future__ import absolute_import
45 > from .. import os
45 > from .. import os
46 > EOF
46 > EOF
47
47
48 $ cat > testpackage/symbolimport.py << EOF
48 $ cat > testpackage/symbolimport.py << EOF
49 > from __future__ import absolute_import
49 > from __future__ import absolute_import
50 > from .unsorted import foo
50 > from .unsorted import foo
51 > EOF
51 > EOF
52
52
53 $ cat > testpackage/latesymbolimport.py << EOF
53 $ cat > testpackage/latesymbolimport.py << EOF
54 > from __future__ import absolute_import
54 > from __future__ import absolute_import
55 > from . import unsorted
55 > from . import unsorted
56 > from mercurial.node import hex
56 > from mercurial.node import hex
57 > EOF
57 > EOF
58
58
59 $ cat > testpackage/multiplegroups.py << EOF
59 $ cat > testpackage/multiplegroups.py << EOF
60 > from __future__ import absolute_import
60 > from __future__ import absolute_import
61 > from . import unsorted
61 > from . import unsorted
62 > from . import more
62 > from . import more
63 > EOF
63 > EOF
64
64
65 $ mkdir testpackage/subpackage
65 $ mkdir testpackage/subpackage
66 $ cat > testpackage/subpackage/levelpriority.py << EOF
66 $ cat > testpackage/subpackage/levelpriority.py << EOF
67 > from __future__ import absolute_import
67 > from __future__ import absolute_import
68 > from . import foo
68 > from . import foo
69 > from .. import parent
69 > from .. import parent
70 > EOF
70 > EOF
71
71
72 $ touch testpackage/subpackage/foo.py
72 $ touch testpackage/subpackage/foo.py
73 $ cat > testpackage/subpackage/__init__.py << EOF
73 $ cat > testpackage/subpackage/__init__.py << EOF
74 > from __future__ import absolute_import
74 > from __future__ import absolute_import
75 > from . import levelpriority # should not cause cycle
75 > from . import levelpriority # should not cause cycle
76 > EOF
76 > EOF
77
77
78 $ cat > testpackage/subpackage/localimport.py << EOF
78 $ cat > testpackage/subpackage/localimport.py << EOF
79 > from __future__ import absolute_import
79 > from __future__ import absolute_import
80 > from . import foo
80 > from . import foo
81 > def bar():
81 > def bar():
82 > # should not cause "higher-level import should come first"
82 > # should not cause "higher-level import should come first"
83 > from .. import unsorted
83 > from .. import unsorted
84 > # but other errors should be detected
84 > # but other errors should be detected
85 > from .. import more
85 > from .. import more
86 > import testpackage.subpackage.levelpriority
86 > import testpackage.subpackage.levelpriority
87 > EOF
87 > EOF
88
88
89 $ cat > testpackage/importmodulefromsub.py << EOF
89 $ cat > testpackage/importmodulefromsub.py << EOF
90 > from __future__ import absolute_import
90 > from __future__ import absolute_import
91 > from .subpackage import foo # not a "direct symbol import"
91 > from .subpackage import foo # not a "direct symbol import"
92 > EOF
92 > EOF
93
93
94 $ cat > testpackage/importsymbolfromsub.py << EOF
94 $ cat > testpackage/importsymbolfromsub.py << EOF
95 > from __future__ import absolute_import
95 > from __future__ import absolute_import
96 > from .subpackage import foo, nonmodule
96 > from .subpackage import foo, nonmodule
97 > EOF
97 > EOF
98
98
99 $ cat > testpackage/sortedentries.py << EOF
99 $ cat > testpackage/sortedentries.py << EOF
100 > from __future__ import absolute_import
100 > from __future__ import absolute_import
101 > from . import (
101 > from . import (
102 > foo,
102 > foo,
103 > bar,
103 > bar,
104 > )
104 > )
105 > EOF
105 > EOF
106
106
107 $ cat > testpackage/importfromalias.py << EOF
107 $ cat > testpackage/importfromalias.py << EOF
108 > from __future__ import absolute_import
108 > from __future__ import absolute_import
109 > from . import ui
109 > from . import ui
110 > EOF
110 > EOF
111
111
112 $ cat > testpackage/importfromrelative.py << EOF
112 $ cat > testpackage/importfromrelative.py << EOF
113 > from __future__ import absolute_import
113 > from __future__ import absolute_import
114 > from testpackage.unsorted import foo
114 > from testpackage.unsorted import foo
115 > EOF
115 > EOF
116
116
117 $ mkdir testpackage2
117 $ mkdir testpackage2
118 $ touch testpackage2/__init__.py
118 $ touch testpackage2/__init__.py
119
119
120 $ cat > testpackage2/latesymbolimport.py << EOF
120 $ cat > testpackage2/latesymbolimport.py << EOF
121 > from __future__ import absolute_import
121 > from __future__ import absolute_import
122 > from testpackage import unsorted
122 > from testpackage import unsorted
123 > from mercurial.node import hex
123 > from mercurial.node import hex
124 > EOF
124 > EOF
125
125
126 $ python "$import_checker" testpackage*/*.py testpackage/subpackage/*.py
126 $ python "$import_checker" testpackage*/*.py testpackage/subpackage/*.py
127 testpackage/importalias.py:2: ui module must be "as" aliased to uimod
127 testpackage/importalias.py:2: ui module must be "as" aliased to uimod
128 testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod
128 testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod
129 testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted
129 testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted
130 testpackage/importfromrelative.py:2: direct symbol import foo from testpackage.unsorted
130 testpackage/importfromrelative.py:2: direct symbol import foo from testpackage.unsorted
131 testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage
131 testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage
132 testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node
132 testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node
133 testpackage/multiple.py:2: multiple imported names: os, sys
133 testpackage/multiple.py:2: multiple imported names: os, sys
134 testpackage/multiplegroups.py:3: multiple "from . import" statements
134 testpackage/multiplegroups.py:3: multiple "from . import" statements
135 testpackage/relativestdlib.py:2: relative import of stdlib module
135 testpackage/relativestdlib.py:2: relative import of stdlib module
136 testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted
136 testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted
137 testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo
137 testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo
138 testpackage/stdafterlocal.py:3: stdlib import "os" follows local import: testpackage
138 testpackage/stdafterlocal.py:3: stdlib import "os" follows local import: testpackage
139 testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage
139 testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage
140 testpackage/subpackage/localimport.py:7: multiple "from .. import" statements
140 testpackage/subpackage/localimport.py:7: multiple "from .. import" statements
141 testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority
141 testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority
142 testpackage/symbolimport.py:2: direct symbol import foo from testpackage.unsorted
142 testpackage/symbolimport.py:2: direct symbol import foo from testpackage.unsorted
143 testpackage/unsorted.py:3: imports not lexically sorted: os < sys
143 testpackage/unsorted.py:3: imports not lexically sorted: os < sys
144 testpackage2/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node
144 testpackage2/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node
145 [1]
145 [1]
146
146
147 $ cd "$TESTDIR"/..
147 $ cd "$TESTDIR"/..
148
148
149 There are a handful of cases here that require renaming a module so it
149 There are a handful of cases here that require renaming a module so it
150 doesn't overlap with a stdlib module name. There are also some cycles
150 doesn't overlap with a stdlib module name. There are also some cycles
151 here that we should still endeavor to fix, and some cycles will be
151 here that we should still endeavor to fix, and some cycles will be
152 hidden by deduplication algorithm in the cycle detector, so fixing
152 hidden by deduplication algorithm in the cycle detector, so fixing
153 these may expose other cycles.
153 these may expose other cycles.
154
154
155 Known-bad files are excluded by -X as some of them would produce unstable
155 Known-bad files are excluded by -X as some of them would produce unstable
156 outputs, which should be fixed later.
156 outputs, which should be fixed later.
157
157
158 $ hg locate 'mercurial/**.py' 'hgext/**.py' 'tests/**.py' \
158 $ hg locate '**.py' \
159 > 'tests/**.t' \
159 > 'tests/**.t' \
160 > -X contrib/debugshell.py \
161 > -X contrib/win32/hgwebdir_wsgi.py \
162 > -X doc/gendoc.py \
163 > -X doc/hgmanpage.py \
160 > -X tests/test-hgweb-auth.py \
164 > -X tests/test-hgweb-auth.py \
161 > -X tests/hypothesishelpers.py \
165 > -X tests/hypothesishelpers.py \
162 > -X tests/test-ctxmanager.py \
166 > -X tests/test-ctxmanager.py \
163 > -X tests/test-lock.py \
167 > -X tests/test-lock.py \
164 > -X tests/test-verify-repo-operations.py \
168 > -X tests/test-verify-repo-operations.py \
165 > -X tests/test-hook.t \
169 > -X tests/test-hook.t \
166 > -X tests/test-import.t \
170 > -X tests/test-import.t \
167 > -X tests/test-check-module-imports.t \
171 > -X tests/test-check-module-imports.t \
168 > -X tests/test-commit-interactive.t \
172 > -X tests/test-commit-interactive.t \
169 > -X tests/test-contrib-check-code.t \
173 > -X tests/test-contrib-check-code.t \
170 > -X tests/test-extension.t \
174 > -X tests/test-extension.t \
171 > -X tests/test-hghave.t \
175 > -X tests/test-hghave.t \
172 > -X tests/test-hgweb-no-path-info.t \
176 > -X tests/test-hgweb-no-path-info.t \
173 > -X tests/test-hgweb-no-request-uri.t \
177 > -X tests/test-hgweb-no-request-uri.t \
174 > -X tests/test-hgweb-non-interactive.t \
178 > -X tests/test-hgweb-non-interactive.t \
175 > | sed 's-\\-/-g' | python "$import_checker" -
179 > | sed 's-\\-/-g' | python "$import_checker" -
176 Import cycle: hgext.largefiles.basestore -> hgext.largefiles.localstore -> hgext.largefiles.basestore
180 Import cycle: hgext.largefiles.basestore -> hgext.largefiles.localstore -> hgext.largefiles.basestore
177 [1]
181 [1]
General Comments 0
You need to be logged in to leave comments. Login now