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