##// END OF EJS Templates
hghave: silence future pyflakes warning of unused import
Yuya Nishihara -
r29231:b1b35a90 default
parent child Browse files
Show More
@@ -1,68 +1,69
1 #!/usr/bin/env python
1 #!/usr/bin/env python
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
6
7 from __future__ import absolute_import, print_function
7 from __future__ import absolute_import, print_function
8
8
9 import hghave
9 import hghave
10 import optparse
10 import optparse
11 import os
11 import os
12 import sys
12 import sys
13
13
14 checks = hghave.checks
14 checks = hghave.checks
15
15
16 def list_features():
16 def list_features():
17 for name, feature in sorted(checks.items()):
17 for name, feature in sorted(checks.items()):
18 desc = feature[1]
18 desc = feature[1]
19 print(name + ':', desc)
19 print(name + ':', desc)
20
20
21 def test_features():
21 def test_features():
22 failed = 0
22 failed = 0
23 for name, feature in checks.items():
23 for name, feature in checks.items():
24 check, _ = feature
24 check, _ = feature
25 try:
25 try:
26 check()
26 check()
27 except Exception as e:
27 except Exception as e:
28 print("feature %s failed: %s" % (name, e))
28 print("feature %s failed: %s" % (name, e))
29 failed += 1
29 failed += 1
30 return failed
30 return failed
31
31
32 parser = optparse.OptionParser("%prog [options] [features]")
32 parser = optparse.OptionParser("%prog [options] [features]")
33 parser.add_option("--test-features", action="store_true",
33 parser.add_option("--test-features", action="store_true",
34 help="test available features")
34 help="test available features")
35 parser.add_option("--list-features", action="store_true",
35 parser.add_option("--list-features", action="store_true",
36 help="list available features")
36 help="list available features")
37
37
38 def _loadaddon():
38 def _loadaddon():
39 if 'TESTDIR' in os.environ:
39 if 'TESTDIR' in os.environ:
40 # loading from '.' isn't needed, because `hghave` should be
40 # loading from '.' isn't needed, because `hghave` should be
41 # running at TESTTMP in this case
41 # running at TESTTMP in this case
42 path = os.environ['TESTDIR']
42 path = os.environ['TESTDIR']
43 else:
43 else:
44 path = '.'
44 path = '.'
45
45
46 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
46 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
47 return
47 return
48
48
49 sys.path.insert(0, path)
49 sys.path.insert(0, path)
50 try:
50 try:
51 import hghaveaddon
51 import hghaveaddon
52 assert hghaveaddon # silence pyflakes
52 except BaseException as inst:
53 except BaseException as inst:
53 sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
54 sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
54 % (path, inst))
55 % (path, inst))
55 sys.exit(2)
56 sys.exit(2)
56 sys.path.pop(0)
57 sys.path.pop(0)
57
58
58 if __name__ == '__main__':
59 if __name__ == '__main__':
59 options, args = parser.parse_args()
60 options, args = parser.parse_args()
60 _loadaddon()
61 _loadaddon()
61 if options.list_features:
62 if options.list_features:
62 list_features()
63 list_features()
63 sys.exit(0)
64 sys.exit(0)
64
65
65 if options.test_features:
66 if options.test_features:
66 sys.exit(test_features())
67 sys.exit(test_features())
67
68
68 hghave.require(args)
69 hghave.require(args)
General Comments 0
You need to be logged in to leave comments. Login now