1*4882a593Smuzhiyun# 2*4882a593Smuzhiyun# SPDX-License-Identifier: MIT 3*4882a593Smuzhiyun# 4*4882a593Smuzhiyun 5*4882a593Smuzhiyunimport bb.tinfoil 6*4882a593Smuzhiyun 7*4882a593Smuzhiyunfrom oeqa.selftest.case import OESelftestTestCase 8*4882a593Smuzhiyunfrom oeqa.utils.commands import get_test_layer 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun 11*4882a593Smuzhiyundef setUpModule(): 12*4882a593Smuzhiyun global tinfoil 13*4882a593Smuzhiyun global metaselftestpath 14*4882a593Smuzhiyun metaselftestpath = get_test_layer() 15*4882a593Smuzhiyun tinfoil = bb.tinfoil.Tinfoil(tracking=True) 16*4882a593Smuzhiyun tinfoil.prepare(config_only=False, quiet=2) 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun 19*4882a593Smuzhiyundef tearDownModule(): 20*4882a593Smuzhiyun tinfoil.shutdown() 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun 23*4882a593Smuzhiyunclass RecipeUtilsTests(OESelftestTestCase): 24*4882a593Smuzhiyun """ Tests for the recipeutils module functions """ 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun def test_patch_recipe_varflag(self): 27*4882a593Smuzhiyun import oe.recipeutils 28*4882a593Smuzhiyun rd = tinfoil.parse_recipe('python3-async-test') 29*4882a593Smuzhiyun vals = {'SRC_URI[md5sum]': 'aaaaaa', 'LICENSE': 'something'} 30*4882a593Smuzhiyun patches = oe.recipeutils.patch_recipe(rd, rd.getVar('FILE'), vals, patch=True, relpath=metaselftestpath) 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun expected_patch = """ 33*4882a593Smuzhiyun--- a/recipes-devtools/python/python-async-test.inc 34*4882a593Smuzhiyun+++ b/recipes-devtools/python/python-async-test.inc 35*4882a593Smuzhiyun@@ -1,14 +1,14 @@ 36*4882a593Smuzhiyun SUMMARY = "Python framework to process interdependent tasks in a pool of workers" 37*4882a593Smuzhiyun HOMEPAGE = "http://github.com/gitpython-developers/async" 38*4882a593Smuzhiyun SECTION = "devel/python" 39*4882a593Smuzhiyun-LICENSE = "BSD-3-Clause" 40*4882a593Smuzhiyun+LICENSE = "something" 41*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://PKG-INFO;beginline=8;endline=8;md5=88df8e78b9edfd744953862179f2d14e" 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun inherit pypi 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun PYPI_PACKAGE = "async" 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun-SRC_URI[md5sum] = "9b06b5997de2154f3bc0273f80bcef6b" 48*4882a593Smuzhiyun+SRC_URI[md5sum] = "aaaaaa" 49*4882a593Smuzhiyun SRC_URI[sha256sum] = "ac6894d876e45878faae493b0cf61d0e28ec417334448ac0a6ea2229d8343051" 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun RDEPENDS:${PN} += "${PYTHON_PN}-threading" 52*4882a593Smuzhiyun""" 53*4882a593Smuzhiyun patchlines = [] 54*4882a593Smuzhiyun for f in patches: 55*4882a593Smuzhiyun for line in f: 56*4882a593Smuzhiyun patchlines.append(line) 57*4882a593Smuzhiyun self.maxDiff = None 58*4882a593Smuzhiyun self.assertEqual(''.join(patchlines).strip(), expected_patch.strip()) 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun def test_patch_recipe_singleappend(self): 62*4882a593Smuzhiyun import oe.recipeutils 63*4882a593Smuzhiyun rd = tinfoil.parse_recipe('recipeutils-test') 64*4882a593Smuzhiyun val = rd.getVar('SRC_URI', False).split() 65*4882a593Smuzhiyun del val[1] 66*4882a593Smuzhiyun val = ' '.join(val) 67*4882a593Smuzhiyun vals = {'SRC_URI': val} 68*4882a593Smuzhiyun patches = oe.recipeutils.patch_recipe(rd, rd.getVar('FILE'), vals, patch=True, relpath=metaselftestpath) 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun expected_patch = """ 71*4882a593Smuzhiyun--- a/recipes-test/recipeutils/recipeutils-test_1.2.bb 72*4882a593Smuzhiyun+++ b/recipes-test/recipeutils/recipeutils-test_1.2.bb 73*4882a593Smuzhiyun@@ -8,6 +8,4 @@ 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun BBCLASSEXTEND = "native nativesdk" 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun-SRC_URI += "file://somefile" 78*4882a593Smuzhiyun- 79*4882a593Smuzhiyun SRC_URI:append = " file://anotherfile" 80*4882a593Smuzhiyun""" 81*4882a593Smuzhiyun patchlines = [] 82*4882a593Smuzhiyun for f in patches: 83*4882a593Smuzhiyun for line in f: 84*4882a593Smuzhiyun patchlines.append(line) 85*4882a593Smuzhiyun self.assertEqual(''.join(patchlines).strip(), expected_patch.strip()) 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun def test_patch_recipe_appends(self): 89*4882a593Smuzhiyun import oe.recipeutils 90*4882a593Smuzhiyun rd = tinfoil.parse_recipe('recipeutils-test') 91*4882a593Smuzhiyun val = rd.getVar('SRC_URI', False).split() 92*4882a593Smuzhiyun vals = {'SRC_URI': val[0]} 93*4882a593Smuzhiyun patches = oe.recipeutils.patch_recipe(rd, rd.getVar('FILE'), vals, patch=True, relpath=metaselftestpath) 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun expected_patch = """ 96*4882a593Smuzhiyun--- a/recipes-test/recipeutils/recipeutils-test_1.2.bb 97*4882a593Smuzhiyun+++ b/recipes-test/recipeutils/recipeutils-test_1.2.bb 98*4882a593Smuzhiyun@@ -8,6 +8,3 @@ 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun BBCLASSEXTEND = "native nativesdk" 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun-SRC_URI += "file://somefile" 103*4882a593Smuzhiyun- 104*4882a593Smuzhiyun-SRC_URI:append = " file://anotherfile" 105*4882a593Smuzhiyun""" 106*4882a593Smuzhiyun patchlines = [] 107*4882a593Smuzhiyun for f in patches: 108*4882a593Smuzhiyun for line in f: 109*4882a593Smuzhiyun patchlines.append(line) 110*4882a593Smuzhiyun self.assertEqual(''.join(patchlines).strip(), expected_patch.strip()) 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun def test_validate_pn(self): 114*4882a593Smuzhiyun import oe.recipeutils 115*4882a593Smuzhiyun expected_results = { 116*4882a593Smuzhiyun 'test': '', 117*4882a593Smuzhiyun 'glib-2.0': '', 118*4882a593Smuzhiyun 'gtk+': '', 119*4882a593Smuzhiyun 'forcevariable': 'reserved', 120*4882a593Smuzhiyun 'pn-something': 'reserved', 121*4882a593Smuzhiyun 'test.bb': 'file', 122*4882a593Smuzhiyun 'test_one': 'character', 123*4882a593Smuzhiyun 'test!': 'character', 124*4882a593Smuzhiyun } 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun for pn, expected in expected_results.items(): 127*4882a593Smuzhiyun result = oe.recipeutils.validate_pn(pn) 128*4882a593Smuzhiyun if expected: 129*4882a593Smuzhiyun self.assertIn(expected, result) 130*4882a593Smuzhiyun else: 131*4882a593Smuzhiyun self.assertEqual(result, '') 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun def test_split_var_value(self): 134*4882a593Smuzhiyun import oe.recipeutils 135*4882a593Smuzhiyun res = oe.recipeutils.split_var_value('test.1 test.2 ${@call_function("hi there world", false)} test.4') 136*4882a593Smuzhiyun self.assertEqual(res, ['test.1', 'test.2', '${@call_function("hi there world", false)}', 'test.4']) 137