Mercurial > hg
annotate tests/test-check-code-hg.t @ 19933:621a26eb3a99
demandimport: allow extensions to import own modules by absolute name
Before this patch, python modules of each extensions can't import
another one in own extension by absolute name, because root modules of
each extensions are loaded with "hgext_" prefix.
For example, "import extroot.bar" in "extroot/foo.py" of "extroot"
extension fails, even though "import bar" in it succeeds.
Installing extensions into site-packages of python library path can
avoid this problem, but this solution is not reasonable in some cases:
using binary package of Mercurial on Windows, for example.
This patch retries to import with "hgext_" prefix after ImportError,
if the module in the extension may try to import another one in own
extension.
This patch doesn't change some "_import()"/"_origimport()" invocations
below, because ordinary extensions shouldn't cause such invocations.
- invocation of "_import()" when root module imports sub-module by
absolute path without "fromlist"
for example, "import a.b" in "a.__init__.py".
extensions are loaded with "hgext_" prefix, and this causes
execution of another (= fixed by this patch) code path.
- invocation of "_origimport()" when "level != -1" with "fromlist"
for example, importing after "from __future__ import
absolute_import" (level == 0), or "from . import b" or "from .a
import b" (0 < level),
for portability between python versions and environments,
extensions shouldn't cause "level != -1".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 05 Oct 2013 01:02:22 +0900 |
parents | 9aee3d014394 |
children | 16b5f498f49c |
rev | line source |
---|---|
15557
7bb5ed61b74c
tests: convert test-check-code-hg.py to .t
Mads Kiilerich <mads@kiilerich.com>
parents:
11771
diff
changeset
|
1 $ check_code="$TESTDIR"/../contrib/check-code.py |
7bb5ed61b74c
tests: convert test-check-code-hg.py to .t
Mads Kiilerich <mads@kiilerich.com>
parents:
11771
diff
changeset
|
2 $ cd "$TESTDIR"/.. |
18601
ce844e8e8af2
tests: guard against obsolete markers in the hg repo itself
Kevin Bullock <kbullock@ringworld.org>
parents:
18596
diff
changeset
|
3 $ if hg identify -q > /dev/null 2>&1; then : |
16485
f48b075ff088
tests: solaris sh can not negate exit status with '!'
Mads Kiilerich <mads@kiilerich.com>
parents:
16306
diff
changeset
|
4 > else |
16179
be6ac2ecc7f8
test-check-code-hg: skip test if not in a working dir (issue3248).
Greg Ward <greg@gerg.ca>
parents:
16156
diff
changeset
|
5 > echo "skipped: not a Mercurial working dir" >&2 |
be6ac2ecc7f8
test-check-code-hg: skip test if not in a working dir (issue3248).
Greg Ward <greg@gerg.ca>
parents:
16156
diff
changeset
|
6 > exit 80 |
be6ac2ecc7f8
test-check-code-hg: skip test if not in a working dir (issue3248).
Greg Ward <greg@gerg.ca>
parents:
16156
diff
changeset
|
7 > fi |
15558
c6b600d2348c
tests: run check-code with warnings and maintain a whitelist
Mads Kiilerich <mads@kiilerich.com>
parents:
15557
diff
changeset
|
8 |
19384
96fd9af75834
tests: check-code all python files in one run
Simon Heimberg <simohe@besonet.ch>
parents:
19321
diff
changeset
|
9 Prepare check for Python files without py extension |
19022
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
10 |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
11 $ cp \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
12 > hg \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
13 > hgweb.cgi \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
14 > contrib/convert-repo \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
15 > contrib/dumprevlog \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
16 > contrib/hgweb.fcgi \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
17 > contrib/hgweb.wsgi \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
18 > contrib/simplemerge \ |
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
19 > contrib/undumprevlog \ |
19321
2d03c8da7d98
tests: check-code more python files without py extension
simon@laptop-tosh
parents:
19022
diff
changeset
|
20 > i18n/hggettext \ |
2d03c8da7d98
tests: check-code more python files without py extension
simon@laptop-tosh
parents:
19022
diff
changeset
|
21 > i18n/posplit \ |
2d03c8da7d98
tests: check-code more python files without py extension
simon@laptop-tosh
parents:
19022
diff
changeset
|
22 > tests/hghave \ |
2d03c8da7d98
tests: check-code more python files without py extension
simon@laptop-tosh
parents:
19022
diff
changeset
|
23 > tests/dummyssh \ |
19022
cba222f01056
tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents:
18602
diff
changeset
|
24 > "$TESTTMP"/ |
19385
c455e703348e
tests: rename files to py extension instead of copying a 2nd time
Simon Heimberg <simohe@besonet.ch>
parents:
19384
diff
changeset
|
25 $ for f in "$TESTTMP"/*; do mv "$f" "$f.py"; done |
19384
96fd9af75834
tests: check-code all python files in one run
Simon Heimberg <simohe@besonet.ch>
parents:
19321
diff
changeset
|
26 |
96fd9af75834
tests: check-code all python files in one run
Simon Heimberg <simohe@besonet.ch>
parents:
19321
diff
changeset
|
27 New errors are not allowed. Warnings are strongly discouraged. |
96fd9af75834
tests: check-code all python files in one run
Simon Heimberg <simohe@besonet.ch>
parents:
19321
diff
changeset
|
28 |
19495
9aee3d014394
tests: test-check-code-hg.t works for all files to check
Simon Heimberg <simohe@besonet.ch>
parents:
19386
diff
changeset
|
29 $ { hg manifest 2>/dev/null; ls "$TESTTMP"/*.py | sed 's-\\-/-g'; } | |
9aee3d014394
tests: test-check-code-hg.t works for all files to check
Simon Heimberg <simohe@besonet.ch>
parents:
19386
diff
changeset
|
30 > xargs "$check_code" --warnings --per-file=0 || false |