diff options
author | Monty Taylor <mordred@inaugust.com> | 2013-01-11 17:44:06 -0800 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2013-01-11 17:44:06 -0800 |
commit | 2a36806c698f67f4707cfccb4baabb473e38f06c (patch) | |
tree | fe060da45d5aee7378d9a98a5aafd9cd0ff2aac0 | |
parent | defa46bdab2ee5fad473ec610b0bdabb127da1a5 (diff) | |
download | testrepository-2a36806c698f67f4707cfccb4baabb473e38f06c.tar.gz |
Add setuptools commands for running testr and coverage.
-rw-r--r-- | .bzrignore | 1 | ||||
-rw-r--r-- | BSD | 28 | ||||
-rw-r--r-- | doc/MANUAL.txt | 20 | ||||
-rwxr-xr-x | setup.py | 6 | ||||
-rw-r--r-- | testrepository/setup_command.py | 86 |
5 files changed, 127 insertions, 14 deletions
@@ -4,3 +4,4 @@ test.xml build .testrepository __pycache__ +testrepository.egg-info/ @@ -9,18 +9,18 @@ are met: 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -3. Neither the name of Robert Collins nor the names of Subunit contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. +3. Neither the name of Robert Collins nor the names of Testrepository + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY ROBERT COLLINS AND SUBUNIT CONTRIBUTORS ``AS IS'' -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY ROBERT COLLINS AND TESTREPOSITORY CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/doc/MANUAL.txt b/doc/MANUAL.txt index 566d47e..aa355d2 100644 --- a/doc/MANUAL.txt +++ b/doc/MANUAL.txt @@ -144,3 +144,23 @@ files (for a format 1 repository - the only current format): * repo.conf: This file contains user configuration settings for the repository. ``testr repo-config`` will dump a repo configration and ``test help repo-config`` has online help for all the repository settings. + +setuptools integration +~~~~~~~~~~~~~~~~~~~~~~ + +testrepository provides two different setuptools commands for ease of +integration with setuptools-based workflows: + +* testr: + ``python setup.py testr`` will run testr in parallel mode + Options that would normally be passed to testr run can be added to the + testr-options argument. + ``python setup.py testr --testr-options="--failing"`` will append --failing + to the test run. +* testr_coverage: + ``python setup.py testr_coverage`` will run testr in code coverage mode. This + assumes the installation of the python coverage module. testr_coverage + supports the options from the testr command, and in addition supports the + omit option. + ``python setup.py testr_coverage --omit=ModuleThatSucks.py`` will append + --omit=ModuleThatSucks.py to the coverage report command. @@ -93,4 +93,10 @@ setup(name='testrepository', 'testtools', ] ), + entry_points={ + 'distutils.commands': [ + 'testr = testrepository.setup_command:Testr', + 'testr_coverage = testrepository.setup_command:Coverage', + ], + }, ) diff --git a/testrepository/setup_command.py b/testrepository/setup_command.py new file mode 100644 index 0000000..d1508db --- /dev/null +++ b/testrepository/setup_command.py @@ -0,0 +1,86 @@ +# +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# +# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause +# license at the users choice. A copy of both licenses are available in the +# project source as Apache-2.0 and BSD. You may not use this file except in +# compliance with one of these two licences. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# license you chose for the specific language governing permissions and +# limitations under that license. + +""" +setuptools/distutils commands to run testr via setup.py +""" + +from distutils import cmd +import distutils.errors +import os +import sys + +from testrepository import commands + + +class Testr(cmd.Command): + + description = "Run unit tests using testr" + + user_options = [ + ('testr-args=', 't', "Run 'testr' with these args") + ] + print_slowest = True + + def _run_testr(self, *args): + commands.run_argv([sys.argv[0]] + list(args), + sys.stdin, sys.stdout, sys.stderr) + + def initialize_options(self): + self.testr_args = None + + def finalize_options(self): + if self.testr_args is None: + self.testr_args = [] + else: + self.testr_args = self.testr_args.split() + + def run(self): + """Set up testr repo, then run testr""" + if not os.path.isdir(".testrepository"): + self._run_testr("init") + + testr_ret = self._run_testr("run", "--parallel", *self.testr_args) + if testr_ret: + raise distutils.errors.DistutilsError("testr failed") + if self.print_slowest: + print "Slowest Tests" + self._run_testr("slowest") + + +class Coverage(Testr): + + print_slowest = False + user_options = Testr.user_options + [ + ('omit=', 'o', 'Files to omit from coverage calculations'), + ] + + def initialize_options(self): + Testr.initialize_options(self) + self.omit = "" + + def finalize_options(self): + Testr.finalize_options(self) + if self.omit: + self.omit = "--omit=%s" % self.omit + + def run(self): + package = self.distribution.get_name() + if package.startswith('python-'): + package = package[7:] + options = "--source %s --parallel-mode" % package + os.environ['PYTHON'] = ("coverage run --source %s" % options) + Testr.run(self) + os.system("coverage combine") + os.system("coverage html -d ./cover %s" % self.omit) |