Mercurial > hg
comparison tests/run-tests.py @ 21006:723e41ad59b4
run-tests: Pass arguments into argument parser
Before, arguments were not passed into the optparse.OptionParser
instance and were coming from sys.argv. This patch enables consumers to
define the list of arguments to parse without having to adjust sys.argv.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 24 Mar 2014 21:37:33 -0700 |
parents | 3d1d16b19e7d |
children | 57179a4bf77a |
comparison
equal
deleted
inserted
replaced
21005:3d38ebb586fe | 21006:723e41ad59b4 |
---|---|
131 entries[line] = filename | 131 entries[line] = filename |
132 | 132 |
133 f.close() | 133 f.close() |
134 return entries | 134 return entries |
135 | 135 |
136 def parseargs(): | 136 def parseargs(args): |
137 parser = optparse.OptionParser("%prog [options] [tests]") | 137 parser = optparse.OptionParser("%prog [options] [tests]") |
138 | 138 |
139 # keep these sorted | 139 # keep these sorted |
140 parser.add_option("--blacklist", action="append", | 140 parser.add_option("--blacklist", action="append", |
141 help="skip tests listed in the specified blacklist file") | 141 help="skip tests listed in the specified blacklist file") |
208 help='run tests in random order') | 208 help='run tests in random order') |
209 | 209 |
210 for option, (envvar, default) in defaults.items(): | 210 for option, (envvar, default) in defaults.items(): |
211 defaults[option] = type(default)(os.environ.get(envvar, default)) | 211 defaults[option] = type(default)(os.environ.get(envvar, default)) |
212 parser.set_defaults(**defaults) | 212 parser.set_defaults(**defaults) |
213 (options, args) = parser.parse_args() | 213 (options, args) = parser.parse_args(args) |
214 | 214 |
215 # jython is always pure | 215 # jython is always pure |
216 if 'java' in sys.platform or '__pypy__' in sys.modules: | 216 if 'java' in sys.platform or '__pypy__' in sys.modules: |
217 options.pure = True | 217 options.pure = True |
218 | 218 |
1174 return 80 | 1174 return 80 |
1175 | 1175 |
1176 testtypes = [('.py', pytest, '.out'), | 1176 testtypes = [('.py', pytest, '.out'), |
1177 ('.t', tsttest, '')] | 1177 ('.t', tsttest, '')] |
1178 | 1178 |
1179 def main(): | 1179 def main(args): |
1180 (options, args) = parseargs() | 1180 (options, args) = parseargs(args) |
1181 os.umask(022) | 1181 os.umask(022) |
1182 | 1182 |
1183 checktools() | 1183 checktools() |
1184 | 1184 |
1185 if not args: | 1185 if not args: |
1297 finally: | 1297 finally: |
1298 time.sleep(.1) | 1298 time.sleep(.1) |
1299 cleanup(options) | 1299 cleanup(options) |
1300 | 1300 |
1301 if __name__ == '__main__': | 1301 if __name__ == '__main__': |
1302 main() | 1302 main(sys.argv[1:]) |