##// END OF EJS Templates
tests: add repository check for pyflakes test...
Matt Mackall -
r21208:0e1cbd3d stable
parent child Browse files
Show More
@@ -1,328 +1,333 b''
1 1 import os, stat
2 2 import re
3 3 import sys
4 4 import tempfile
5 5
6 6 tempprefix = 'hg-hghave-'
7 7
8 8 def matchoutput(cmd, regexp, ignorestatus=False):
9 9 """Return True if cmd executes successfully and its output
10 10 is matched by the supplied regular expression.
11 11 """
12 12 r = re.compile(regexp)
13 13 fh = os.popen(cmd)
14 14 s = fh.read()
15 15 try:
16 16 ret = fh.close()
17 17 except IOError:
18 18 # Happen in Windows test environment
19 19 ret = 1
20 20 return (ignorestatus or ret is None) and r.search(s)
21 21
22 22 def has_baz():
23 23 return matchoutput('baz --version 2>&1', r'baz Bazaar version')
24 24
25 25 def has_bzr():
26 26 try:
27 27 import bzrlib
28 28 return bzrlib.__doc__ is not None
29 29 except ImportError:
30 30 return False
31 31
32 32 def has_bzr114():
33 33 try:
34 34 import bzrlib
35 35 return (bzrlib.__doc__ is not None
36 36 and bzrlib.version_info[:2] >= (1, 14))
37 37 except ImportError:
38 38 return False
39 39
40 40 def has_cvs():
41 41 re = r'Concurrent Versions System.*?server'
42 42 return matchoutput('cvs --version 2>&1', re) and not has_msys()
43 43
44 44 def has_cvs112():
45 45 re = r'Concurrent Versions System \(CVS\) 1.12.*?server'
46 46 return matchoutput('cvs --version 2>&1', re) and not has_msys()
47 47
48 48 def has_darcs():
49 49 return matchoutput('darcs --version', r'2\.[2-9]', True)
50 50
51 51 def has_mtn():
52 52 return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
53 53 'mtn --version', r'monotone 0\.', True)
54 54
55 55 def has_eol_in_paths():
56 56 try:
57 57 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
58 58 os.close(fd)
59 59 os.remove(path)
60 60 return True
61 61 except (IOError, OSError):
62 62 return False
63 63
64 64 def has_executablebit():
65 65 try:
66 66 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
67 67 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
68 68 try:
69 69 os.close(fh)
70 70 m = os.stat(fn).st_mode & 0777
71 71 new_file_has_exec = m & EXECFLAGS
72 72 os.chmod(fn, m ^ EXECFLAGS)
73 73 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
74 74 finally:
75 75 os.unlink(fn)
76 76 except (IOError, OSError):
77 77 # we don't care, the user probably won't be able to commit anyway
78 78 return False
79 79 return not (new_file_has_exec or exec_flags_cannot_flip)
80 80
81 81 def has_icasefs():
82 82 # Stolen from mercurial.util
83 83 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
84 84 os.close(fd)
85 85 try:
86 86 s1 = os.stat(path)
87 87 d, b = os.path.split(path)
88 88 p2 = os.path.join(d, b.upper())
89 89 if path == p2:
90 90 p2 = os.path.join(d, b.lower())
91 91 try:
92 92 s2 = os.stat(p2)
93 93 return s2 == s1
94 94 except OSError:
95 95 return False
96 96 finally:
97 97 os.remove(path)
98 98
99 99 def has_fifo():
100 100 if getattr(os, "mkfifo", None) is None:
101 101 return False
102 102 name = tempfile.mktemp(dir='.', prefix=tempprefix)
103 103 try:
104 104 os.mkfifo(name)
105 105 os.unlink(name)
106 106 return True
107 107 except OSError:
108 108 return False
109 109
110 110 def has_killdaemons():
111 111 return True
112 112
113 113 def has_cacheable_fs():
114 114 from mercurial import util
115 115
116 116 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
117 117 os.close(fd)
118 118 try:
119 119 return util.cachestat(path).cacheable()
120 120 finally:
121 121 os.remove(path)
122 122
123 123 def has_lsprof():
124 124 try:
125 125 import _lsprof
126 126 return True
127 127 except ImportError:
128 128 return False
129 129
130 130 def has_gettext():
131 131 return matchoutput('msgfmt --version', 'GNU gettext-tools')
132 132
133 133 def has_git():
134 134 return matchoutput('git --version 2>&1', r'^git version')
135 135
136 136 def has_docutils():
137 137 try:
138 138 from docutils.core import publish_cmdline
139 139 return True
140 140 except ImportError:
141 141 return False
142 142
143 143 def getsvnversion():
144 144 m = matchoutput('svn --version --quiet 2>&1', r'^(\d+)\.(\d+)')
145 145 if not m:
146 146 return (0, 0)
147 147 return (int(m.group(1)), int(m.group(2)))
148 148
149 149 def has_svn15():
150 150 return getsvnversion() >= (1, 5)
151 151
152 152 def has_svn13():
153 153 return getsvnversion() >= (1, 3)
154 154
155 155 def has_svn():
156 156 return matchoutput('svn --version 2>&1', r'^svn, version') and \
157 157 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
158 158
159 159 def has_svn_bindings():
160 160 try:
161 161 import svn.core
162 162 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
163 163 if version < (1, 4):
164 164 return False
165 165 return True
166 166 except ImportError:
167 167 return False
168 168
169 169 def has_p4():
170 170 return (matchoutput('p4 -V', r'Rev\. P4/') and
171 171 matchoutput('p4d -V', r'Rev\. P4D/'))
172 172
173 173 def has_symlink():
174 174 if getattr(os, "symlink", None) is None:
175 175 return False
176 176 name = tempfile.mktemp(dir='.', prefix=tempprefix)
177 177 try:
178 178 os.symlink(".", name)
179 179 os.unlink(name)
180 180 return True
181 181 except (OSError, AttributeError):
182 182 return False
183 183
184 184 def has_hardlink():
185 185 from mercurial import util
186 186 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
187 187 os.close(fh)
188 188 name = tempfile.mktemp(dir='.', prefix=tempprefix)
189 189 try:
190 190 try:
191 191 util.oslink(fn, name)
192 192 os.unlink(name)
193 193 return True
194 194 except OSError:
195 195 return False
196 196 finally:
197 197 os.unlink(fn)
198 198
199 199 def has_tla():
200 200 return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
201 201
202 202 def has_gpg():
203 203 return matchoutput('gpg --version 2>&1', r'GnuPG')
204 204
205 205 def has_unix_permissions():
206 206 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
207 207 try:
208 208 fname = os.path.join(d, 'foo')
209 209 for umask in (077, 007, 022):
210 210 os.umask(umask)
211 211 f = open(fname, 'w')
212 212 f.close()
213 213 mode = os.stat(fname).st_mode
214 214 os.unlink(fname)
215 215 if mode & 0777 != ~umask & 0666:
216 216 return False
217 217 return True
218 218 finally:
219 219 os.rmdir(d)
220 220
221 221 def has_root():
222 222 return getattr(os, 'geteuid', None) and os.geteuid() == 0
223 223
224 224 def has_pyflakes():
225 225 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
226 226 r"<stdin>:1: 're' imported but unused",
227 227 True)
228 228
229 229 def has_pygments():
230 230 try:
231 231 import pygments
232 232 return True
233 233 except ImportError:
234 234 return False
235 235
236 236 def has_python243():
237 237 return sys.version_info >= (2, 4, 3)
238 238
239 239 def has_outer_repo():
240 240 # failing for other reasons than 'no repo' imply that there is a repo
241 241 return not matchoutput('hg root 2>&1',
242 242 r'abort: no repository found', True)
243 243
244 244 def has_ssl():
245 245 try:
246 246 import ssl
247 247 import OpenSSL
248 248 OpenSSL.SSL.Context
249 249 return True
250 250 except ImportError:
251 251 return False
252 252
253 253 def has_windows():
254 254 return os.name == 'nt'
255 255
256 256 def has_system_sh():
257 257 return os.name != 'nt'
258 258
259 259 def has_serve():
260 260 return os.name != 'nt' # gross approximation
261 261
262 def has_test_repo():
263 t = os.environ["TESTDIR"]
264 return os.path.isdir(os.path.join(t, "..", ".hg"))
265
262 266 def has_tic():
263 267 try:
264 268 import curses
265 269 curses.COLOR_BLUE
266 270 return matchoutput('test -x "`which tic`"', '')
267 271 except ImportError:
268 272 return False
269 273
270 274 def has_msys():
271 275 return os.getenv('MSYSTEM')
272 276
273 277 def has_aix():
274 278 return sys.platform.startswith("aix")
275 279
276 280 def has_absimport():
277 281 import __future__
278 282 from mercurial import util
279 283 return util.safehasattr(__future__, "absolute_import")
280 284
281 285 def has_py3k():
282 286 return 3 == sys.version_info[0]
283 287
284 288 checks = {
285 289 "true": (lambda: True, "yak shaving"),
286 290 "false": (lambda: False, "nail clipper"),
287 291 "baz": (has_baz, "GNU Arch baz client"),
288 292 "bzr": (has_bzr, "Canonical's Bazaar client"),
289 293 "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"),
290 294 "cacheable": (has_cacheable_fs, "cacheable filesystem"),
291 295 "cvs": (has_cvs, "cvs client/server"),
292 296 "cvs112": (has_cvs112, "cvs client/server >= 1.12"),
293 297 "darcs": (has_darcs, "darcs client"),
294 298 "docutils": (has_docutils, "Docutils text processing library"),
295 299 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
296 300 "execbit": (has_executablebit, "executable bit"),
297 301 "fifo": (has_fifo, "named pipes"),
298 302 "gettext": (has_gettext, "GNU Gettext (msgfmt)"),
299 303 "git": (has_git, "git command line client"),
300 304 "gpg": (has_gpg, "gpg client"),
301 305 "hardlink": (has_hardlink, "hardlinks"),
302 306 "icasefs": (has_icasefs, "case insensitive file system"),
303 307 "killdaemons": (has_killdaemons, 'killdaemons.py support'),
304 308 "lsprof": (has_lsprof, "python lsprof module"),
305 309 "mtn": (has_mtn, "monotone client (>= 1.0)"),
306 310 "outer-repo": (has_outer_repo, "outer repo"),
307 311 "p4": (has_p4, "Perforce server and client"),
308 312 "pyflakes": (has_pyflakes, "Pyflakes python linter"),
309 313 "pygments": (has_pygments, "Pygments source highlighting library"),
310 314 "python243": (has_python243, "python >= 2.4.3"),
311 315 "root": (has_root, "root permissions"),
312 316 "serve": (has_serve, "platform and python can manage 'hg serve -d'"),
313 317 "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"),
314 318 "svn": (has_svn, "subversion client and admin tools"),
315 319 "svn13": (has_svn13, "subversion client and admin tools >= 1.3"),
316 320 "svn15": (has_svn15, "subversion client and admin tools >= 1.5"),
317 321 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
318 322 "symlink": (has_symlink, "symbolic links"),
319 323 "system-sh": (has_system_sh, "system() uses sh"),
324 "test-repo": (has_test_repo, "running tests from repository"),
320 325 "tic": (has_tic, "terminfo compiler and curses module"),
321 326 "tla": (has_tla, "GNU Arch tla client"),
322 327 "unix-permissions": (has_unix_permissions, "unix-style permissions"),
323 328 "windows": (has_windows, "Windows"),
324 329 "msys": (has_msys, "Windows with MSYS"),
325 330 "aix": (has_aix, "AIX"),
326 331 "absimport": (has_absimport, "absolute_import in __future__"),
327 332 "py3k": (has_py3k, "running with Python 3.x"),
328 333 }
@@ -1,19 +1,21 b''
1 $ "$TESTDIR/hghave" pyflakes || exit 80
1 #if test-repo pyflakes
2
2 3 $ cd "`dirname "$TESTDIR"`"
3 4
4 5 run pyflakes on all tracked files ending in .py or without a file ending
5 6 (skipping binary file random-seed)
7
6 8 $ hg manifest 2>/dev/null | egrep "\.py$|^[^.]*$" | grep -v /random_seed$ \
7 9 > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
8 10 contrib/win32/hgwebdir_wsgi.py:*: 'win32traceutil' imported but unused (glob)
9 11 setup.py:*: 'sha' imported but unused (glob)
10 12 setup.py:*: 'zlib' imported but unused (glob)
11 13 setup.py:*: 'bz2' imported but unused (glob)
12 14 setup.py:*: 'py2exe' imported but unused (glob)
13 15 tests/hghave.py:*: '_lsprof' imported but unused (glob)
14 16 tests/hghave.py:*: 'publish_cmdline' imported but unused (glob)
15 17 tests/hghave.py:*: 'pygments' imported but unused (glob)
16 18 tests/hghave.py:*: 'ssl' imported but unused (glob)
17 19 contrib/win32/hgwebdir_wsgi.py:93: 'from isapi.install import *' used; unable to detect undefined names (glob)
18 20
19
21 #endif
General Comments 0
You need to be logged in to leave comments. Login now