bitbake-selftest 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  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. import os
  18. import sys, logging
  19. sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
  20. import unittest
  21. try:
  22. import bb
  23. import layerindexlib
  24. except RuntimeError as exc:
  25. sys.exit(str(exc))
  26. tests = ["bb.tests.codeparser",
  27. "bb.tests.cow",
  28. "bb.tests.data",
  29. "bb.tests.event",
  30. "bb.tests.fetch",
  31. "bb.tests.parse",
  32. "bb.tests.utils",
  33. "layerindexlib.tests.layerindexobj",
  34. "layerindexlib.tests.restapi",
  35. "layerindexlib.tests.cooker"]
  36. for t in tests:
  37. t = '.'.join(t.split('.')[:3])
  38. __import__(t)
  39. # Set-up logging
  40. class StdoutStreamHandler(logging.StreamHandler):
  41. """Special handler so that unittest is able to capture stdout"""
  42. def __init__(self):
  43. # Override __init__() because we don't want to set self.stream here
  44. logging.Handler.__init__(self)
  45. @property
  46. def stream(self):
  47. # We want to dynamically write wherever sys.stdout is pointing to
  48. return sys.stdout
  49. handler = StdoutStreamHandler()
  50. bb.logger.addHandler(handler)
  51. bb.logger.setLevel(logging.DEBUG)
  52. ENV_HELP = """\
  53. Environment variables:
  54. BB_SKIP_NETTESTS set to 'yes' in order to skip tests using network
  55. connection
  56. BB_TMPDIR_NOCLEAN set to 'yes' to preserve test tmp directories
  57. """
  58. class main(unittest.main):
  59. def _print_help(self, *args, **kwargs):
  60. super(main, self)._print_help(*args, **kwargs)
  61. print(ENV_HELP)
  62. if __name__ == '__main__':
  63. main(defaultTest=tests, buffer=True)