bitbake-selftest 2.3 KB

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