cooker.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #
  2. # BitBake Tests for cooker.py
  3. #
  4. # SPDX-License-Identifier: GPL-2.0-only
  5. #
  6. import unittest
  7. import os
  8. import bb, bb.cooker
  9. import re
  10. import logging
  11. # Cooker tests
  12. class CookerTest(unittest.TestCase):
  13. def setUp(self):
  14. # At least one variable needs to be set
  15. self.d = bb.data.init()
  16. topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testdata/cooker")
  17. self.d.setVar('TOPDIR', topdir)
  18. def test_CookerCollectFiles_sublayers(self):
  19. '''Test that a sublayer of an existing layer does not trigger
  20. No bb files matched ...'''
  21. def append_collection(topdir, path, d):
  22. collection = path.split('/')[-1]
  23. pattern = "^" + topdir + "/" + path + "/"
  24. regex = re.compile(pattern)
  25. priority = 5
  26. d.setVar('BBFILE_COLLECTIONS', (d.getVar('BBFILE_COLLECTIONS') or "") + " " + collection)
  27. d.setVar('BBFILE_PATTERN_%s' % (collection), pattern)
  28. d.setVar('BBFILE_PRIORITY_%s' % (collection), priority)
  29. return (collection, pattern, regex, priority)
  30. topdir = self.d.getVar("TOPDIR")
  31. # Priorities: list of (collection, pattern, regex, priority)
  32. bbfile_config_priorities = []
  33. # Order is important for this test, shortest to longest is typical failure case
  34. bbfile_config_priorities.append( append_collection(topdir, 'first', self.d) )
  35. bbfile_config_priorities.append( append_collection(topdir, 'second', self.d) )
  36. bbfile_config_priorities.append( append_collection(topdir, 'second/third', self.d) )
  37. pkgfns = [ topdir + '/first/recipes/sample1_1.0.bb',
  38. topdir + '/second/recipes/sample2_1.0.bb',
  39. topdir + '/second/third/recipes/sample3_1.0.bb' ]
  40. class LogHandler(logging.Handler):
  41. def __init__(self):
  42. logging.Handler.__init__(self)
  43. self.logdata = []
  44. def emit(self, record):
  45. self.logdata.append(record.getMessage())
  46. # Move cooker to use my special logging
  47. logger = bb.cooker.logger
  48. log_handler = LogHandler()
  49. logger.addHandler(log_handler)
  50. collection = bb.cooker.CookerCollectFiles(bbfile_config_priorities)
  51. collection.collection_priorities(pkgfns, pkgfns, self.d)
  52. logger.removeHandler(log_handler)
  53. # Should be empty (no generated messages)
  54. expected = []
  55. self.assertEqual(log_handler.logdata, expected)