bitbake-selftest 2.3 KB

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