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 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | |
| 8 | import os |
| 9 | import sys, logging |
| 10 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib')) |
| 11 | |
| 12 | import unittest |
| 13 | try: |
| 14 | import bb |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 15 | import hashserv |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 16 | import layerindexlib |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | except RuntimeError as exc: |
| 18 | sys.exit(str(exc)) |
| 19 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 20 | tests = ["bb.tests.codeparser", |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame^] | 21 | "bb.tests.color", |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 22 | "bb.tests.cooker", |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 23 | "bb.tests.cow", |
| 24 | "bb.tests.data", |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 25 | "bb.tests.event", |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 26 | "bb.tests.fetch", |
| 27 | "bb.tests.parse", |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 28 | "bb.tests.persist_data", |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 29 | "bb.tests.runqueue", |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | "bb.tests.utils", |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 31 | "hashserv.tests", |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 32 | "layerindexlib.tests.layerindexobj", |
| 33 | "layerindexlib.tests.restapi", |
| 34 | "layerindexlib.tests.cooker"] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | |
| 36 | for t in tests: |
| 37 | t = '.'.join(t.split('.')[:3]) |
| 38 | __import__(t) |
| 39 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | # Set-up logging |
| 42 | class StdoutStreamHandler(logging.StreamHandler): |
| 43 | """Special handler so that unittest is able to capture stdout""" |
| 44 | def __init__(self): |
| 45 | # Override __init__() because we don't want to set self.stream here |
| 46 | logging.Handler.__init__(self) |
| 47 | |
| 48 | @property |
| 49 | def stream(self): |
| 50 | # We want to dynamically write wherever sys.stdout is pointing to |
| 51 | return sys.stdout |
| 52 | |
| 53 | |
| 54 | handler = StdoutStreamHandler() |
| 55 | bb.logger.addHandler(handler) |
| 56 | bb.logger.setLevel(logging.DEBUG) |
| 57 | |
| 58 | |
| 59 | ENV_HELP = """\ |
| 60 | Environment variables: |
| 61 | BB_SKIP_NETTESTS set to 'yes' in order to skip tests using network |
| 62 | connection |
| 63 | BB_TMPDIR_NOCLEAN set to 'yes' to preserve test tmp directories |
| 64 | """ |
| 65 | |
| 66 | class main(unittest.main): |
| 67 | def _print_help(self, *args, **kwargs): |
| 68 | super(main, self)._print_help(*args, **kwargs) |
| 69 | print(ENV_HELP) |
| 70 | |
| 71 | |
| 72 | if __name__ == '__main__': |
| 73 | main(defaultTest=tests, buffer=True) |