Mercurial > hg
comparison tests/hghave @ 25732:b94df10cc3b5
hghave: allow adding customized features at runtime
Before this patch, there is no way to add customized features to
`hghave` without changing `hghave` and `hghave.py` themselves.
This decreases reusability of `run-tests.py` framework for third party
tools, because they may want to examine custom features at runtime
(e.g. existence of some external tools).
To allow adding customized features at runtime, this patch makes
`hghave` import `hghaveaddon` module, only when `hghaveaddon.py` file
can be found in directories below:
- `TESTDIR` for invocation via `run-tests.py`
- `.` for invocation via command line
The path to the directory where `hghaveaddon.py` should be placed is
added to `sys.path` only while importing `hghaveaddon`, because:
- `.` may not be added to `PYTHONPATH`
- adding additional path to `sys.path` may change behavior of
subsequent `import` for other features
`hghave` is terminated with exit code '2' at failure of `import
hghaveaddon`, because exit code '2' terminates `run-tests.py`
immediately.
This is a one of preparations for issue4677.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 03 Jul 2015 06:56:03 +0900 |
parents | 05b3238ba901 |
children | 8107c308ff22 |
comparison
equal
deleted
inserted
replaced
25731:cd1daab5d036 | 25732:b94df10cc3b5 |
---|---|
2 """Test the running system for features availability. Exit with zero | 2 """Test the running system for features availability. Exit with zero |
3 if all features are there, non-zero otherwise. If a feature name is | 3 if all features are there, non-zero otherwise. If a feature name is |
4 prefixed with "no-", the absence of feature is tested. | 4 prefixed with "no-", the absence of feature is tested. |
5 """ | 5 """ |
6 import optparse | 6 import optparse |
7 import sys | 7 import os, sys |
8 import hghave | 8 import hghave |
9 | 9 |
10 checks = hghave.checks | 10 checks = hghave.checks |
11 | 11 |
12 def list_features(): | 12 def list_features(): |
31 parser.add_option("--list-features", action="store_true", | 31 parser.add_option("--list-features", action="store_true", |
32 help="list available features") | 32 help="list available features") |
33 parser.add_option("-q", "--quiet", action="store_true", | 33 parser.add_option("-q", "--quiet", action="store_true", |
34 help="check features silently") | 34 help="check features silently") |
35 | 35 |
36 def _loadaddon(quiet): | |
37 if 'TESTDIR' in os.environ: | |
38 # loading from '.' isn't needed, because `hghave` should be | |
39 # running at TESTTMP in this case | |
40 path = os.environ['TESTDIR'] | |
41 else: | |
42 path = '.' | |
43 | |
44 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')): | |
45 return | |
46 | |
47 sys.path.insert(0, path) | |
48 try: | |
49 import hghaveaddon | |
50 except BaseException, inst: | |
51 if not quiet: | |
52 sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n' | |
53 % (path, inst)) | |
54 sys.exit(2) | |
55 sys.path.pop(0) | |
56 | |
36 if __name__ == '__main__': | 57 if __name__ == '__main__': |
37 options, args = parser.parse_args() | 58 options, args = parser.parse_args() |
59 _loadaddon(options.quiet) | |
38 if options.list_features: | 60 if options.list_features: |
39 list_features() | 61 list_features() |
40 sys.exit(0) | 62 sys.exit(0) |
41 | 63 |
42 if options.test_features: | 64 if options.test_features: |