1#!/usr/bin/env python3
2#
3# Copyright (C) 2012 Richard Purdie
4#
5# SPDX-License-Identifier: GPL-2.0-only
6#
7
8import os
9import sys, logging
10import warnings
11warnings.simplefilter("default")
12sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
13
14import unittest
15try:
16    import bb
17    import hashserv
18    import layerindexlib
19except RuntimeError as exc:
20    sys.exit(str(exc))
21
22tests = ["bb.tests.codeparser",
23         "bb.tests.color",
24         "bb.tests.cooker",
25         "bb.tests.cow",
26         "bb.tests.data",
27         "bb.tests.event",
28         "bb.tests.fetch",
29         "bb.tests.parse",
30         "bb.tests.persist_data",
31         "bb.tests.runqueue",
32         "bb.tests.siggen",
33         "bb.tests.utils",
34         "bb.tests.compression",
35         "hashserv.tests",
36         "layerindexlib.tests.layerindexobj",
37         "layerindexlib.tests.restapi",
38         "layerindexlib.tests.cooker"]
39
40for t in tests:
41    t = '.'.join(t.split('.')[:3])
42    __import__(t)
43
44
45# Set-up logging
46class StdoutStreamHandler(logging.StreamHandler):
47    """Special handler so that unittest is able to capture stdout"""
48    def __init__(self):
49        # Override __init__() because we don't want to set self.stream here
50        logging.Handler.__init__(self)
51
52    @property
53    def stream(self):
54        # We want to dynamically write wherever sys.stdout is pointing to
55        return sys.stdout
56
57
58handler = StdoutStreamHandler()
59bb.logger.addHandler(handler)
60bb.logger.setLevel(logging.DEBUG)
61
62
63ENV_HELP = """\
64Environment variables:
65  BB_SKIP_NETTESTS      set to 'yes' in order to skip tests using network
66                        connection
67  BB_TMPDIR_NOCLEAN     set to 'yes' to preserve test tmp directories
68"""
69
70class main(unittest.main):
71    def _print_help(self, *args, **kwargs):
72        super(main, self)._print_help(*args, **kwargs)
73        print(ENV_HELP)
74
75
76if __name__ == '__main__':
77        main(defaultTest=tests, buffer=True)
78