blob: afe1603d042ae5e60af462e9eb99b0ba5ad10f46 [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
25except RuntimeError as exc:
26 sys.exit(str(exc))
27
Patrick Williamsc0f7c042017-02-23 20:41:17 -060028tests = ["bb.tests.codeparser",
29 "bb.tests.cow",
30 "bb.tests.data",
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031 "bb.tests.event",
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032 "bb.tests.fetch",
33 "bb.tests.parse",
34 "bb.tests.utils"]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035
36for t in tests:
37 t = '.'.join(t.split('.')[:3])
38 __import__(t)
39
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041# Set-up logging
42class 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
54handler = StdoutStreamHandler()
55bb.logger.addHandler(handler)
56bb.logger.setLevel(logging.DEBUG)
57
58
59ENV_HELP = """\
60Environment 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
66class main(unittest.main):
67 def _print_help(self, *args, **kwargs):
68 super(main, self)._print_help(*args, **kwargs)
69 print(ENV_HELP)
70
71
72if __name__ == '__main__':
73 main(defaultTest=tests, buffer=True)