1*1a4b7ee2SBrad Bishop# ex:ts=4:sw=4:sts=4:et 2*1a4b7ee2SBrad Bishop# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- 3*1a4b7ee2SBrad Bishop# 4*1a4b7ee2SBrad Bishop# BitBake Tests for cooker.py 5*1a4b7ee2SBrad Bishop# 6*1a4b7ee2SBrad Bishop# This program is free software; you can redistribute it and/or modify 7*1a4b7ee2SBrad Bishop# it under the terms of the GNU General Public License version 2 as 8*1a4b7ee2SBrad Bishop# published by the Free Software Foundation. 9*1a4b7ee2SBrad Bishop# 10*1a4b7ee2SBrad Bishop# This program is distributed in the hope that it will be useful, 11*1a4b7ee2SBrad Bishop# but WITHOUT ANY WARRANTY; without even the implied warranty of 12*1a4b7ee2SBrad Bishop# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*1a4b7ee2SBrad Bishop# GNU General Public License for more details. 14*1a4b7ee2SBrad Bishop# 15*1a4b7ee2SBrad Bishop# You should have received a copy of the GNU General Public License along 16*1a4b7ee2SBrad Bishop# with this program; if not, write to the Free Software Foundation, Inc., 17*1a4b7ee2SBrad Bishop# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18*1a4b7ee2SBrad Bishop# 19*1a4b7ee2SBrad Bishop 20*1a4b7ee2SBrad Bishopimport unittest 21*1a4b7ee2SBrad Bishopimport tempfile 22*1a4b7ee2SBrad Bishopimport os 23*1a4b7ee2SBrad Bishopimport bb, bb.cooker 24*1a4b7ee2SBrad Bishopimport re 25*1a4b7ee2SBrad Bishopimport logging 26*1a4b7ee2SBrad Bishop 27*1a4b7ee2SBrad Bishop# Cooker tests 28*1a4b7ee2SBrad Bishopclass CookerTest(unittest.TestCase): 29*1a4b7ee2SBrad Bishop def setUp(self): 30*1a4b7ee2SBrad Bishop # At least one variable needs to be set 31*1a4b7ee2SBrad Bishop self.d = bb.data.init() 32*1a4b7ee2SBrad Bishop topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testdata/cooker") 33*1a4b7ee2SBrad Bishop self.d.setVar('TOPDIR', topdir) 34*1a4b7ee2SBrad Bishop 35*1a4b7ee2SBrad Bishop def test_CookerCollectFiles_sublayers(self): 36*1a4b7ee2SBrad Bishop '''Test that a sublayer of an existing layer does not trigger 37*1a4b7ee2SBrad Bishop No bb files matched ...''' 38*1a4b7ee2SBrad Bishop 39*1a4b7ee2SBrad Bishop def append_collection(topdir, path, d): 40*1a4b7ee2SBrad Bishop collection = path.split('/')[-1] 41*1a4b7ee2SBrad Bishop pattern = "^" + topdir + "/" + path + "/" 42*1a4b7ee2SBrad Bishop regex = re.compile(pattern) 43*1a4b7ee2SBrad Bishop priority = 5 44*1a4b7ee2SBrad Bishop 45*1a4b7ee2SBrad Bishop d.setVar('BBFILE_COLLECTIONS', (d.getVar('BBFILE_COLLECTIONS') or "") + " " + collection) 46*1a4b7ee2SBrad Bishop d.setVar('BBFILE_PATTERN_%s' % (collection), pattern) 47*1a4b7ee2SBrad Bishop d.setVar('BBFILE_PRIORITY_%s' % (collection), priority) 48*1a4b7ee2SBrad Bishop 49*1a4b7ee2SBrad Bishop return (collection, pattern, regex, priority) 50*1a4b7ee2SBrad Bishop 51*1a4b7ee2SBrad Bishop topdir = self.d.getVar("TOPDIR") 52*1a4b7ee2SBrad Bishop 53*1a4b7ee2SBrad Bishop # Priorities: list of (collection, pattern, regex, priority) 54*1a4b7ee2SBrad Bishop bbfile_config_priorities = [] 55*1a4b7ee2SBrad Bishop # Order is important for this test, shortest to longest is typical failure case 56*1a4b7ee2SBrad Bishop bbfile_config_priorities.append( append_collection(topdir, 'first', self.d) ) 57*1a4b7ee2SBrad Bishop bbfile_config_priorities.append( append_collection(topdir, 'second', self.d) ) 58*1a4b7ee2SBrad Bishop bbfile_config_priorities.append( append_collection(topdir, 'second/third', self.d) ) 59*1a4b7ee2SBrad Bishop 60*1a4b7ee2SBrad Bishop pkgfns = [ topdir + '/first/recipes/sample1_1.0.bb', 61*1a4b7ee2SBrad Bishop topdir + '/second/recipes/sample2_1.0.bb', 62*1a4b7ee2SBrad Bishop topdir + '/second/third/recipes/sample3_1.0.bb' ] 63*1a4b7ee2SBrad Bishop 64*1a4b7ee2SBrad Bishop class LogHandler(logging.Handler): 65*1a4b7ee2SBrad Bishop def __init__(self): 66*1a4b7ee2SBrad Bishop logging.Handler.__init__(self) 67*1a4b7ee2SBrad Bishop self.logdata = [] 68*1a4b7ee2SBrad Bishop 69*1a4b7ee2SBrad Bishop def emit(self, record): 70*1a4b7ee2SBrad Bishop self.logdata.append(record.getMessage()) 71*1a4b7ee2SBrad Bishop 72*1a4b7ee2SBrad Bishop # Move cooker to use my special logging 73*1a4b7ee2SBrad Bishop logger = bb.cooker.logger 74*1a4b7ee2SBrad Bishop log_handler = LogHandler() 75*1a4b7ee2SBrad Bishop logger.addHandler(log_handler) 76*1a4b7ee2SBrad Bishop collection = bb.cooker.CookerCollectFiles(bbfile_config_priorities) 77*1a4b7ee2SBrad Bishop collection.collection_priorities(pkgfns, self.d) 78*1a4b7ee2SBrad Bishop logger.removeHandler(log_handler) 79*1a4b7ee2SBrad Bishop 80*1a4b7ee2SBrad Bishop # Should be empty (no generated messages) 81*1a4b7ee2SBrad Bishop expected = [] 82*1a4b7ee2SBrad Bishop 83*1a4b7ee2SBrad Bishop self.assertEqual(log_handler.logdata, expected) 84