Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 7 | import bb.tinfoil |
| 8 | |
| 9 | from oeqa.selftest.case import OESelftestTestCase |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 10 | from oeqa.utils.commands import get_test_layer |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 11 | |
| 12 | |
| 13 | def 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 | |
| 21 | def tearDownModule(): |
| 22 | tinfoil.shutdown() |
| 23 | |
| 24 | |
| 25 | class 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" |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 41 | -LICENSE = "BSD-3-Clause" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 53 | RDEPENDS:${PN} += "${PYTHON_PN}-threading" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 | - |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 81 | SRC_URI:append = " file://anotherfile" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 | - |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 106 | -SRC_URI:append = " file://anotherfile" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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']) |