blob: 99f1af910f49e0be9dea5da9b910ce63c82a9fef [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002#
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
18import os
19import sys, logging
20sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
21
22import unittest
23try:
24 import bb
Brad Bishop19323692019-04-05 15:28:33 -040025 import hashserv
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080026 import layerindexlib
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027except RuntimeError as exc:
28 sys.exit(str(exc))
29
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030tests = ["bb.tests.codeparser",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031 "bb.tests.cooker",
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032 "bb.tests.cow",
33 "bb.tests.data",
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034 "bb.tests.event",
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035 "bb.tests.fetch",
36 "bb.tests.parse",
Brad Bishop19323692019-04-05 15:28:33 -040037 "bb.tests.persist_data",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080038 "bb.tests.utils",
Brad Bishop19323692019-04-05 15:28:33 -040039 "hashserv.tests",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080040 "layerindexlib.tests.layerindexobj",
41 "layerindexlib.tests.restapi",
42 "layerindexlib.tests.cooker"]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
44for t in tests:
45 t = '.'.join(t.split('.')[:3])
46 __import__(t)
47
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049# Set-up logging
50class 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
62handler = StdoutStreamHandler()
63bb.logger.addHandler(handler)
64bb.logger.setLevel(logging.DEBUG)
65
66
67ENV_HELP = """\
68Environment 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
74class main(unittest.main):
75 def _print_help(self, *args, **kwargs):
76 super(main, self)._print_help(*args, **kwargs)
77 print(ENV_HELP)
78
79
80if __name__ == '__main__':
81 main(defaultTest=tests, buffer=True)