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