recipeutils.py 4.2 KB

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