recipeutils.py 4.2 KB

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