comparison tests/test-imports-checker.t @ 48876:42d2b31cee0b

tests: remove from __future__ from inline Python in tests This is no longer required since we require Python 3 and the linter no longer requires these statements. Differential Revision: https://phab.mercurial-scm.org/D12255
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 20 Feb 2022 15:28:44 -0700
parents 303576116ac1
children
comparison
equal deleted inserted replaced
48875:6000f5b25c9b 48876:42d2b31cee0b
14 14
15 $ mkdir testpackage 15 $ mkdir testpackage
16 $ touch testpackage/__init__.py 16 $ touch testpackage/__init__.py
17 17
18 $ cat > testpackage/multiple.py << EOF 18 $ cat > testpackage/multiple.py << EOF
19 > from __future__ import absolute_import
20 > import os, sys 19 > import os, sys
21 > EOF 20 > EOF
22 21
23 $ cat > testpackage/unsorted.py << EOF 22 $ cat > testpackage/unsorted.py << EOF
24 > from __future__ import absolute_import
25 > import sys 23 > import sys
26 > import os 24 > import os
27 > EOF 25 > EOF
28 26
29 $ cat > testpackage/stdafterlocal.py << EOF 27 $ cat > testpackage/stdafterlocal.py << EOF
30 > from __future__ import absolute_import
31 > from . import unsorted 28 > from . import unsorted
32 > import os 29 > import os
33 > EOF 30 > EOF
34 31
35 $ cat > testpackage/requirerelative.py << EOF 32 $ cat > testpackage/requirerelative.py << EOF
36 > from __future__ import absolute_import
37 > import testpackage.unsorted 33 > import testpackage.unsorted
38 > EOF 34 > EOF
39 35
40 $ cat > testpackage/importalias.py << EOF 36 $ cat > testpackage/importalias.py << EOF
41 > from __future__ import absolute_import
42 > import ui 37 > import ui
43 > EOF 38 > EOF
44 39
45 $ cat > testpackage/relativestdlib.py << EOF 40 $ cat > testpackage/relativestdlib.py << EOF
46 > from __future__ import absolute_import
47 > from .. import os 41 > from .. import os
48 > EOF 42 > EOF
49 43
50 $ cat > testpackage/stdlibfrom.py << EOF 44 $ cat > testpackage/stdlibfrom.py << EOF
51 > from __future__ import absolute_import
52 > from collections import abc 45 > from collections import abc
53 > EOF 46 > EOF
54 47
55 $ cat > testpackage/symbolimport.py << EOF 48 $ cat > testpackage/symbolimport.py << EOF
56 > from __future__ import absolute_import
57 > from .unsorted import foo 49 > from .unsorted import foo
58 > EOF 50 > EOF
59 51
60 $ cat > testpackage/latesymbolimport.py << EOF 52 $ cat > testpackage/latesymbolimport.py << EOF
61 > from __future__ import absolute_import
62 > from . import unsorted 53 > from . import unsorted
63 > from mercurial.node import hex 54 > from mercurial.node import hex
64 > EOF 55 > EOF
65 56
66 $ cat > testpackage/multiplegroups.py << EOF 57 $ cat > testpackage/multiplegroups.py << EOF
67 > from __future__ import absolute_import
68 > from . import unsorted 58 > from . import unsorted
69 > from . import more 59 > from . import more
70 > EOF 60 > EOF
71 61
72 $ mkdir testpackage/subpackage 62 $ mkdir testpackage/subpackage
73 $ cat > testpackage/subpackage/levelpriority.py << EOF 63 $ cat > testpackage/subpackage/levelpriority.py << EOF
74 > from __future__ import absolute_import
75 > from . import foo 64 > from . import foo
76 > from .. import parent 65 > from .. import parent
77 > EOF 66 > EOF
78 67
79 $ touch testpackage/subpackage/foo.py 68 $ touch testpackage/subpackage/foo.py
80 $ cat > testpackage/subpackage/__init__.py << EOF 69 $ cat > testpackage/subpackage/__init__.py << EOF
81 > from __future__ import absolute_import
82 > from . import levelpriority # should not cause cycle 70 > from . import levelpriority # should not cause cycle
83 > EOF 71 > EOF
84 72
85 $ cat > testpackage/subpackage/localimport.py << EOF 73 $ cat > testpackage/subpackage/localimport.py << EOF
86 > from __future__ import absolute_import
87 > from . import foo 74 > from . import foo
88 > def bar(): 75 > def bar():
89 > # should not cause "higher-level import should come first" 76 > # should not cause "higher-level import should come first"
90 > from .. import unsorted 77 > from .. import unsorted
91 > # but other errors should be detected 78 > # but other errors should be detected
92 > from .. import more 79 > from .. import more
93 > import testpackage.subpackage.levelpriority 80 > import testpackage.subpackage.levelpriority
94 > EOF 81 > EOF
95 82
96 $ cat > testpackage/importmodulefromsub.py << EOF 83 $ cat > testpackage/importmodulefromsub.py << EOF
97 > from __future__ import absolute_import
98 > from .subpackage import foo # not a "direct symbol import" 84 > from .subpackage import foo # not a "direct symbol import"
99 > EOF 85 > EOF
100 86
101 $ cat > testpackage/importsymbolfromsub.py << EOF 87 $ cat > testpackage/importsymbolfromsub.py << EOF
102 > from __future__ import absolute_import
103 > from .subpackage import foo, nonmodule 88 > from .subpackage import foo, nonmodule
104 > EOF 89 > EOF
105 90
106 $ cat > testpackage/sortedentries.py << EOF 91 $ cat > testpackage/sortedentries.py << EOF
107 > from __future__ import absolute_import
108 > from . import ( 92 > from . import (
109 > foo, 93 > foo,
110 > bar, 94 > bar,
111 > ) 95 > )
112 > EOF 96 > EOF
113 97
114 $ cat > testpackage/importfromalias.py << EOF 98 $ cat > testpackage/importfromalias.py << EOF
115 > from __future__ import absolute_import
116 > from . import ui 99 > from . import ui
117 > EOF 100 > EOF
118 101
119 $ cat > testpackage/importfromrelative.py << EOF 102 $ cat > testpackage/importfromrelative.py << EOF
120 > from __future__ import absolute_import
121 > from testpackage.unsorted import foo 103 > from testpackage.unsorted import foo
122 > EOF 104 > EOF
123 105
124 $ mkdir testpackage2 106 $ mkdir testpackage2
125 $ touch testpackage2/__init__.py 107 $ touch testpackage2/__init__.py
126 108
127 $ cat > testpackage2/latesymbolimport.py << EOF 109 $ cat > testpackage2/latesymbolimport.py << EOF
128 > from __future__ import absolute_import
129 > from testpackage import unsorted 110 > from testpackage import unsorted
130 > from mercurial.node import hex 111 > from mercurial.node import hex
131 > EOF 112 > EOF
132 113
133 # Shadowing a stdlib module to test "relative import of stdlib module" is 114 # Shadowing a stdlib module to test "relative import of stdlib module" is
135 116
136 $ mkdir email 117 $ mkdir email
137 $ touch email/__init__.py 118 $ touch email/__init__.py
138 $ touch email/errors.py 119 $ touch email/errors.py
139 $ cat > email/utils.py << EOF 120 $ cat > email/utils.py << EOF
140 > from __future__ import absolute_import
141 > from . import errors 121 > from . import errors
142 > EOF 122 > EOF
143 123
144 $ "$PYTHON" "$import_checker" testpackage*/*.py testpackage/subpackage/*.py \ 124 $ "$PYTHON" "$import_checker" testpackage*/*.py testpackage/subpackage/*.py \
145 > email/*.py 125 > email/*.py
146 testpackage/importalias.py:2: ui module must be "as" aliased to uimod 126 testpackage/importalias.py:1: ui module must be "as" aliased to uimod
147 testpackage/importfromalias.py:2: ui from testpackage must be "as" aliased to uimod 127 testpackage/importfromalias.py:1: ui from testpackage must be "as" aliased to uimod
148 testpackage/importfromrelative.py:2: import should be relative: testpackage.unsorted 128 testpackage/importfromrelative.py:1: import should be relative: testpackage.unsorted
149 testpackage/importfromrelative.py:2: direct symbol import foo from testpackage.unsorted 129 testpackage/importfromrelative.py:1: direct symbol import foo from testpackage.unsorted
150 testpackage/importsymbolfromsub.py:2: direct symbol import nonmodule from testpackage.subpackage 130 testpackage/importsymbolfromsub.py:1: direct symbol import nonmodule from testpackage.subpackage
151 testpackage/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node 131 testpackage/latesymbolimport.py:2: symbol import follows non-symbol import: mercurial.node
152 testpackage/multiple.py:2: multiple imported names: os, sys 132 testpackage/multiple.py:1: multiple imported names: os, sys
153 testpackage/multiplegroups.py:3: multiple "from . import" statements 133 testpackage/multiplegroups.py:2: multiple "from . import" statements
154 testpackage/relativestdlib.py:2: relative import of stdlib module 134 testpackage/relativestdlib.py:1: relative import of stdlib module
155 testpackage/requirerelative.py:2: import should be relative: testpackage.unsorted 135 testpackage/requirerelative.py:1: import should be relative: testpackage.unsorted
156 testpackage/sortedentries.py:2: imports from testpackage not lexically sorted: bar < foo 136 testpackage/sortedentries.py:1: imports from testpackage not lexically sorted: bar < foo
157 testpackage/stdafterlocal.py:3: stdlib import "os" follows local import: testpackage 137 testpackage/stdafterlocal.py:2: stdlib import "os" follows local import: testpackage
158 testpackage/stdlibfrom.py:2: direct symbol import abc from collections 138 testpackage/stdlibfrom.py:1: direct symbol import abc from collections
159 testpackage/subpackage/levelpriority.py:3: higher-level import should come first: testpackage 139 testpackage/subpackage/levelpriority.py:2: higher-level import should come first: testpackage
160 testpackage/subpackage/localimport.py:7: multiple "from .. import" statements 140 testpackage/subpackage/localimport.py:6: multiple "from .. import" statements
161 testpackage/subpackage/localimport.py:8: import should be relative: testpackage.subpackage.levelpriority 141 testpackage/subpackage/localimport.py:7: import should be relative: testpackage.subpackage.levelpriority
162 testpackage/symbolimport.py:2: direct symbol import foo from testpackage.unsorted 142 testpackage/symbolimport.py:1: direct symbol import foo from testpackage.unsorted
163 testpackage/unsorted.py:3: imports not lexically sorted: os < sys 143 testpackage/unsorted.py:2: imports not lexically sorted: os < sys
164 testpackage2/latesymbolimport.py:3: symbol import follows non-symbol import: mercurial.node 144 testpackage2/latesymbolimport.py:2: symbol import follows non-symbol import: mercurial.node
165 [1] 145 [1]