test_lib_patch.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import pytest
  2. import checkpackagelib.test_util as util
  3. import checkpackagelib.lib_patch as m
  4. ApplyOrder = [
  5. ('standard', # catches https://bugs.busybox.net/show_bug.cgi?id=11271
  6. '0001-description.patch',
  7. '',
  8. []),
  9. ('standard with path',
  10. 'path/0001-description.patch',
  11. '',
  12. []),
  13. ('acceptable format',
  14. '1-description.patch',
  15. '',
  16. []),
  17. ('acceptable format with path',
  18. 'path/1-description.patch',
  19. '',
  20. []),
  21. ('old format',
  22. 'package-0001-description.patch',
  23. '',
  24. [['package-0001-description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
  25. ('old format with path',
  26. 'path/package-0001-description.patch',
  27. '',
  28. [['path/package-0001-description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
  29. ('missing number',
  30. 'description.patch',
  31. '',
  32. [['description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
  33. ('missing number with path',
  34. 'path/description.patch',
  35. '',
  36. [['path/description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
  37. ]
  38. @pytest.mark.parametrize('testname,filename,string,expected', ApplyOrder)
  39. def test_ApplyOrder(testname, filename, string, expected):
  40. warnings = util.check_file(m.ApplyOrder, filename, string)
  41. assert warnings == expected
  42. NumberedSubject = [
  43. ('no subject',
  44. 'patch',
  45. '',
  46. []),
  47. ('acceptable because it is not a git patch',
  48. 'patch',
  49. 'Subject: [PATCH 24/105] text\n',
  50. []),
  51. ('good',
  52. 'patch',
  53. 'Subject: [PATCH] text\n'
  54. 'diff --git a/configure.ac b/configure.ac\n',
  55. []),
  56. ('bad',
  57. 'patch',
  58. 'Subject: [PATCH 24/105] text\n'
  59. 'diff --git a/configure.ac b/configure.ac\n',
  60. [["patch:1: generate your patches with 'git format-patch -N'",
  61. 'Subject: [PATCH 24/105] text\n']]),
  62. ]
  63. @pytest.mark.parametrize('testname,filename,string,expected', NumberedSubject)
  64. def test_NumberedSubject(testname, filename, string, expected):
  65. warnings = util.check_file(m.NumberedSubject, filename, string)
  66. assert warnings == expected
  67. Sob = [
  68. ('good',
  69. 'patch',
  70. 'Signed-off-by: John Doe <johndoe@example.com>\n',
  71. []),
  72. ('empty',
  73. 'patch',
  74. '',
  75. [['patch:0: missing Signed-off-by in the header (url#_format_and_licensing_of_the_package_patches)']]),
  76. ('bad',
  77. 'patch',
  78. 'Subject: [PATCH 24/105] text\n',
  79. [['patch:0: missing Signed-off-by in the header (url#_format_and_licensing_of_the_package_patches)']]),
  80. ]
  81. @pytest.mark.parametrize('testname,filename,string,expected', Sob)
  82. def test_Sob(testname, filename, string, expected):
  83. warnings = util.check_file(m.Sob, filename, string)
  84. assert warnings == expected
  85. Upstream = [
  86. ('good',
  87. 'patch',
  88. 'Upstream: https://some/amazing/patch/submission\n',
  89. []),
  90. ('empty',
  91. 'patch',
  92. '',
  93. [['patch:0: missing Upstream in the header (url#_additional_patch_documentation)']]),
  94. ('bad',
  95. 'patch',
  96. 'Subject: [PATCH 24/105] text\n',
  97. [['patch:0: missing Upstream in the header (url#_additional_patch_documentation)']]),
  98. ]
  99. @pytest.mark.parametrize('testname,filename,string,expected', Upstream)
  100. def test_Upstream(testname, filename, string, expected):
  101. warnings = util.check_file(m.Upstream, filename, string)
  102. assert warnings == expected