comparison tests/run.py @ 1452:4217a050a088

tests: drop hard-coded list of tests The list of out of date, missing 'test_helpers' and 'comprehensive/test_custom_layout'. Instead, use the discover functionality introduced in Python 2.7, and available for Python 2.6 and earlier from the 'unittest2' backport. Tested by invoking 'run.py' both with and without '-A' in Python 2.6 & 2.7, and ensuring that passing comprehensive tests as arguments continues to work. As a minor (but welcome) side-effect, this should restore the ability to test hgsubversion under demandimport; previously, test_util was imported before we enabled demandimport, so it didn't affect most of Mercurial. Since unittest2 (and unittest) do define SkipTest, we can remove the earlier import, restoring the likely originally intended testing mode.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Sun, 12 Jun 2016 14:55:57 +0200
parents 025de18d652b
children dcf9eff9b5b7
comparison
equal deleted inserted replaced
1451:945700dac237 1452:4217a050a088
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import optparse 3 import optparse
4 import os 4 import os
5 import sys 5 import sys
6 import unittest
7 6
8 import test_util 7 if sys.version_info[:2] < (2, 7):
9 test_util.SkipTest = None 8 import unittest2 as unittest
10 9 else:
11 def tests(): 10 import unittest
12 import test_binaryfiles
13 import test_diff
14 import test_externals
15 import test_fetch_branches
16 import test_fetch_command
17 import test_fetch_command_regexes
18 import test_fetch_exec
19 import test_fetch_mappings
20 import test_fetch_renames
21 import test_fetch_symlinks
22 import test_fetch_truncated
23 import test_hooks
24 import test_svn_pre_commit_hooks
25 import test_pull
26 import test_pull_fallback
27 import test_push_command
28 import test_push_renames
29 import test_push_dirs
30 import test_push_eol
31 import test_push_autoprops
32 import test_single_dir_clone
33 import test_single_dir_push
34 import test_svnwrap
35 import test_tags
36 import test_template_keywords
37 import test_utility_commands
38 import test_unaffected_core
39 import test_urls
40
41 sys.path.append(os.path.dirname(__file__))
42 sys.path.append(os.path.join(os.path.dirname(__file__), 'comprehensive'))
43
44 import test_rebuildmeta
45 import test_stupid_pull
46 import test_updatemeta
47 import test_verify_and_startrev
48
49 return locals()
50
51 def comprehensive(mod):
52 dir = os.path.basename(os.path.dirname(mod.__file__))
53 return dir == 'comprehensive'
54 11
55 if __name__ == '__main__': 12 if __name__ == '__main__':
56 description = ("This script runs the hgsubversion tests. If no tests are " 13 description = ("This script runs the hgsubversion tests. If no tests are "
57 "specified, all known tests are implied.") 14 "specified, all known tests are implied.")
58 parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]", 15 parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]",
98 # silence output when running outside nose 55 # silence output when running outside nose
99 if not options.showstdout: 56 if not options.showstdout:
100 import tempfile 57 import tempfile
101 sys.stdout = tempfile.TemporaryFile() 58 sys.stdout = tempfile.TemporaryFile()
102 59
103 all_tests = tests() 60 args = [os.path.basename(os.path.splitext(arg)[0]).replace('-', '_')
104 61 for arg in args]
105 args = [i.split('.py')[0].replace('-', '_') for i in args]
106 62
107 loader = unittest.TestLoader() 63 loader = unittest.TestLoader()
108 suite = unittest.TestSuite() 64 suite = unittest.TestSuite()
109 65
110 if not args: 66 if not args:
111 check = lambda x: options.comprehensive or not comprehensive(x) 67 suite = loader.discover('.')
112 suite.addTests(loader.loadTestsFromModule(m) 68
113 for (n, m) in sorted(all_tests.iteritems()) 69 if options.comprehensive:
114 if check(m)) 70 suite.addTests(loader.discover('comprehensive',
71 top_level_dir='comprehensive'))
115 else: 72 else:
116 for arg in args: 73 sys.path.append(os.path.join(os.path.dirname(__file__), 'comprehensive'))
117 if arg == 'test_util': 74
118 continue 75 suite.addTests(loader.loadTestsFromNames(args))
119 elif arg not in all_tests:
120 print >> sys.stderr, 'test module %s not available' % arg
121 else:
122 suite.addTest(loader.loadTestsFromModule(all_tests[arg]))
123 76
124 runner = unittest.TextTestRunner(**testargs) 77 runner = unittest.TextTestRunner(**testargs)
125 result = runner.run(suite) 78 result = runner.run(suite)
126 if not result.wasSuccessful(): 79 if not result.wasSuccessful():
127 sys.exit(1) 80 sys.exit(1)