Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2012 Richard Purdie |
| 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License version 2 as |
| 7 | # published by the Free Software Foundation. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License along |
| 15 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | |
| 18 | import os |
| 19 | import sys, logging |
| 20 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib')) |
| 21 | |
| 22 | import unittest |
| 23 | try: |
| 24 | import bb |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 25 | import layerindexlib |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | except RuntimeError as exc: |
| 27 | sys.exit(str(exc)) |
| 28 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 29 | tests = ["bb.tests.codeparser", |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | "bb.tests.cooker", |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 31 | "bb.tests.cow", |
| 32 | "bb.tests.data", |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 33 | "bb.tests.event", |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 34 | "bb.tests.fetch", |
| 35 | "bb.tests.parse", |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 36 | "bb.tests.utils", |
| 37 | "layerindexlib.tests.layerindexobj", |
| 38 | "layerindexlib.tests.restapi", |
| 39 | "layerindexlib.tests.cooker"] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
| 41 | for t in tests: |
| 42 | t = '.'.join(t.split('.')[:3]) |
| 43 | __import__(t) |
| 44 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | # Set-up logging |
| 47 | class StdoutStreamHandler(logging.StreamHandler): |
| 48 | """Special handler so that unittest is able to capture stdout""" |
| 49 | def __init__(self): |
| 50 | # Override __init__() because we don't want to set self.stream here |
| 51 | logging.Handler.__init__(self) |
| 52 | |
| 53 | @property |
| 54 | def stream(self): |
| 55 | # We want to dynamically write wherever sys.stdout is pointing to |
| 56 | return sys.stdout |
| 57 | |
| 58 | |
| 59 | handler = StdoutStreamHandler() |
| 60 | bb.logger.addHandler(handler) |
| 61 | bb.logger.setLevel(logging.DEBUG) |
| 62 | |
| 63 | |
| 64 | ENV_HELP = """\ |
| 65 | Environment variables: |
| 66 | BB_SKIP_NETTESTS set to 'yes' in order to skip tests using network |
| 67 | connection |
| 68 | BB_TMPDIR_NOCLEAN set to 'yes' to preserve test tmp directories |
| 69 | """ |
| 70 | |
| 71 | class main(unittest.main): |
| 72 | def _print_help(self, *args, **kwargs): |
| 73 | super(main, self)._print_help(*args, **kwargs) |
| 74 | print(ENV_HELP) |
| 75 | |
| 76 | |
| 77 | if __name__ == '__main__': |
| 78 | main(defaultTest=tests, buffer=True) |