bitbake-selftest 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (C) 2012 Richard Purdie
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import os
  20. import sys, logging
  21. sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
  22. import unittest
  23. try:
  24. import bb
  25. import hashserv
  26. import layerindexlib
  27. except RuntimeError as exc:
  28. sys.exit(str(exc))
  29. tests = ["bb.tests.codeparser",
  30. "bb.tests.cooker",
  31. "bb.tests.cow",
  32. "bb.tests.data",
  33. "bb.tests.event",
  34. "bb.tests.fetch",
  35. "bb.tests.parse",
  36. "bb.tests.persist_data",
  37. "bb.tests.utils",
  38. "hashserv.tests",
  39. "layerindexlib.tests.layerindexobj",
  40. "layerindexlib.tests.restapi",
  41. "layerindexlib.tests.cooker"]
  42. for t in tests:
  43. t = '.'.join(t.split('.')[:3])
  44. __import__(t)
  45. # Set-up logging
  46. class 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. @property
  52. def stream(self):
  53. # We want to dynamically write wherever sys.stdout is pointing to
  54. return sys.stdout
  55. handler = StdoutStreamHandler()
  56. bb.logger.addHandler(handler)
  57. bb.logger.setLevel(logging.DEBUG)
  58. ENV_HELP = """\
  59. Environment variables:
  60. BB_SKIP_NETTESTS set to 'yes' in order to skip tests using network
  61. connection
  62. BB_TMPDIR_NOCLEAN set to 'yes' to preserve test tmp directories
  63. """
  64. class main(unittest.main):
  65. def _print_help(self, *args, **kwargs):
  66. super(main, self)._print_help(*args, **kwargs)
  67. print(ENV_HELP)
  68. if __name__ == '__main__':
  69. main(defaultTest=tests, buffer=True)