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