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