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