buildroot/utils/checkpackagelib/test_lib_patch.py
Ricardo Martincoski fc254881e6 utils/checkpackagelib: add unit tests
So anyone willing to contribute to check-package can run all tests in
less than 1 second by using:
$ python3 -m pytest -v utils/checkpackagelib/

Most test cases are in the form:
@pytest.mark.parametrize('testname,filename,string,expected', function)
 - testname: a short description of the scenario tested, added in order
   to improve readability of the log when some tests fail
 - filename: the filename the check-package function being tested thinks
   it is testing
 - string: the content of the file being sent to the function under test
 - expected: all expected warnings that a given function from
   check-package should generate for a given file named filename and
   with string as its content.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Cc: Arnout Vandecappelle <arnout@mind.be>
Cc: Romain Naour <romain.naour@gmail.com>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2022-02-06 15:35:19 +01:00

97 lines
2.8 KiB
Python

import pytest
import checkpackagelib.test_util as util
import checkpackagelib.lib_patch as m
ApplyOrder = [
('standard', # catches https://bugs.busybox.net/show_bug.cgi?id=11271
'0001-description.patch',
'',
[]),
('standard with path',
'path/0001-description.patch',
'',
[]),
('acceptable format',
'1-description.patch',
'',
[]),
('acceptable format with path',
'path/1-description.patch',
'',
[]),
('old format',
'package-0001-description.patch',
'',
[['package-0001-description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
('old format with path',
'path/package-0001-description.patch',
'',
[['path/package-0001-description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
('missing number',
'description.patch',
'',
[['description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
('missing number with path',
'path/description.patch',
'',
[['path/description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
]
@pytest.mark.parametrize('testname,filename,string,expected', ApplyOrder)
def test_ApplyOrder(testname, filename, string, expected):
warnings = util.check_file(m.ApplyOrder, filename, string)
assert warnings == expected
NumberedSubject = [
('no subject',
'patch',
'',
[]),
('acceptable because it is not a git patch',
'patch',
'Subject: [PATCH 24/105] text\n',
[]),
('good',
'patch',
'Subject: [PATCH] text\n'
'diff --git a/configure.ac b/configure.ac\n',
[]),
('bad',
'patch',
'Subject: [PATCH 24/105] text\n'
'diff --git a/configure.ac b/configure.ac\n',
[["patch:1: generate your patches with 'git format-patch -N'",
'Subject: [PATCH 24/105] text\n']]),
]
@pytest.mark.parametrize('testname,filename,string,expected', NumberedSubject)
def test_NumberedSubject(testname, filename, string, expected):
warnings = util.check_file(m.NumberedSubject, filename, string)
assert warnings == expected
Sob = [
('good',
'patch',
'Signed-off-by: John Doe <johndoe@example.com>\n',
[]),
('empty',
'patch',
'',
[['patch:0: missing Signed-off-by in the header (url#_format_and_licensing_of_the_package_patches)']]),
('bad',
'patch',
'Subject: [PATCH 24/105] text\n',
[['patch:0: missing Signed-off-by in the header (url#_format_and_licensing_of_the_package_patches)']]),
]
@pytest.mark.parametrize('testname,filename,string,expected', Sob)
def test_Sob(testname, filename, string, expected):
warnings = util.check_file(m.Sob, filename, string)
assert warnings == expected