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