Use the standard message subscriber to report early errors
[wifi-radar.git] / test / testcommand.py
blob8294d9f76d9d856572a7d4cb0360fdfad5f1b303
1 #!/usr/bin/python
2 # test -- implements a test command for distutils.core.setup
3 # Copyright (c) 2011 Sean Robinson <robinson@tuxfamily.org>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 import distutils.core
25 import unittest
27 class test(distutils.core.Command):
28 """ Run unit tests.
30 This command loads tests using the unittest module's test
31 discovery abilities (see the unittest documentation regarding
32 "Test Discovery").
34 Then the tests are run using unittest.TextTestRunner() with a
35 default verbosity of 2, or a verbosity of 0 if the --quiet
36 option is passed to the command.
38 This command should work with Python >= 2.7 out of the box. It
39 may work in Python 2.4-2.6 with unittest2.
40 """
41 description = "Run unit tests."
43 # List of option tuples: long name, short name (None if no short
44 # name), and help string.
45 user_options = [('start-dir=', 's',
46 "Directory to start discovery ('.' default)"),
47 ('pattern=', 'p',
48 "Pattern to match test files ('test*.py' default)"),
49 ('top-level-dir=', 't',
50 "Top level directory of project (defaults to start directory)"),
53 boolean_options = ['verbose']
55 def initialize_options(self):
56 """ Set the default values for command options.
57 """
58 self.verbosity = 2
59 self.start_dir = '.'
60 self.pattern = 'test*.py'
61 self.top_level_dir = None
63 def finalize_options(self):
64 """ Ensure options are ready to be used during test set-up.
65 """
66 if not self.verbose:
67 self.verbosity = 0
69 def run(self):
70 """ Run the test suites returned by unittest.TestLoader.discover.
71 """
72 discover = unittest.defaultTestLoader.discover
73 for suite in discover(self.start_dir, self.pattern, self.top_level_dir):
74 unittest.TextTestRunner(verbosity=self.verbosity).run(suite)