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