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