|
1 | 1 | from __future__ import (absolute_import, division, print_function, |
2 | 2 | unicode_literals) |
| 3 | +import inspect |
3 | 4 | import os |
4 | 5 | import shutil |
5 | 6 | import subprocess |
@@ -99,30 +100,23 @@ def generate_testing_command(self): |
99 | 100 | cmd_pre += pre |
100 | 101 | cmd_post += post |
101 | 102 |
|
| 103 | + test_args = filter(lambda arg: hasattr(self, arg), |
| 104 | + self._get_test_runner_args()) |
| 105 | + |
| 106 | + test_args = ', '.join('{0}={1!r}'.format(arg, getattr(self, arg)) |
| 107 | + for arg in test_args) |
| 108 | + |
102 | 109 | if PY3: |
103 | 110 | set_flag = "import builtins; builtins._ASTROPY_TEST_ = True" |
104 | 111 | else: |
105 | 112 | set_flag = "import __builtin__; __builtin__._ASTROPY_TEST_ = True" |
106 | 113 |
|
107 | | - cmd = ('{cmd_pre}{0}; import {1.package_name}, sys; result = (' |
108 | | - '{1.package_name}.test(' |
109 | | - 'package={1.package!r}, ' |
110 | | - 'test_path={1.test_path!r}, ' |
111 | | - 'args={1.args!r}, ' |
112 | | - 'plugins={1.plugins!r}, ' |
113 | | - 'verbose={1.verbose_results!r}, ' |
114 | | - 'pastebin={1.pastebin!r}, ' |
115 | | - 'remote_data={1.remote_data!r}, ' |
116 | | - 'pep8={1.pep8!r}, ' |
117 | | - 'pdb={1.pdb!r}, ' |
118 | | - 'open_files={1.open_files!r}, ' |
119 | | - 'parallel={1.parallel!r}, ' |
120 | | - 'docs_path={1.docs_path!r}, ' |
121 | | - 'skip_docs={1.skip_docs!r}, ' |
122 | | - 'repeat={1.repeat!r})); ' |
123 | | - '{cmd_post}' |
| 114 | + cmd = ('{cmd_pre}{0}; import {1.package_name}, sys; result = ' |
| 115 | + '{1.package_name}.test({test_args}); {cmd_post}' |
124 | 116 | 'sys.exit(result)') |
125 | | - return cmd.format(set_flag, self, cmd_pre=cmd_pre, cmd_post=cmd_post) |
| 117 | + |
| 118 | + return cmd.format(set_flag, self, cmd_pre=cmd_pre, |
| 119 | + cmd_post=cmd_post, test_args=test_args) |
126 | 120 |
|
127 | 121 | def _validate_required_deps(self): |
128 | 122 | """ |
@@ -155,7 +149,6 @@ def run(self): |
155 | 149 | try: |
156 | 150 | # Construct this modules testing command |
157 | 151 | cmd = self.generate_testing_command() |
158 | | - |
159 | 152 | # Run the tests in a subprocess--this is necessary since |
160 | 153 | # new extension modules may have appeared, and this is the |
161 | 154 | # easiest way to set up a new environment |
@@ -248,3 +241,33 @@ def _generate_coverage_commands(self): |
248 | 241 | os.path.abspath('.'), self.testing_path)) |
249 | 242 |
|
250 | 243 | return cmd_pre, cmd_post |
| 244 | + |
| 245 | + def _get_test_runner_args(self): |
| 246 | + """ |
| 247 | + A hack to determine what arguments are supported by the package's |
| 248 | + test() function. In the future there should be a more straightforward |
| 249 | + API to determine this (really it should be determined by the |
| 250 | + ``TestRunner`` class for whatever version of Astropy is in use). |
| 251 | + """ |
| 252 | + |
| 253 | + if PY3: |
| 254 | + import builtins |
| 255 | + builtins._ASTROPY_TEST_ = True |
| 256 | + else: |
| 257 | + import __builtin__ |
| 258 | + __builtin__._ASTROPY_TEST_ = True |
| 259 | + |
| 260 | + try: |
| 261 | + pkg = __import__(self.package_name) |
| 262 | + if not hasattr(pkg, 'test'): |
| 263 | + raise ImportError( |
| 264 | + 'package {0} does not have a {0}.test() function as ' |
| 265 | + 'required by the Astropy test runner'.format(package_name)) |
| 266 | + |
| 267 | + argspec = inspect.getargspec(pkg.test) |
| 268 | + return argspec.args |
| 269 | + finally: |
| 270 | + if PY3: |
| 271 | + del builtins._ASTROPY_TEST_ |
| 272 | + else: |
| 273 | + del __builtin__._ASTROPY_TEST_ |
0 commit comments