Commit ae34d71d authored by Jelmer Vernooij's avatar Jelmer Vernooij

Add tests for ancient-python-version-field.

parent 54086d0f
#!/usr/bin/python3
from debian.changelog import Version
import os
import sys
print("Explicit specify source format.")
......@@ -8,13 +9,11 @@ if os.path.exists('debian/source/format'):
# source format file already exists
sys.exit(0)
from debian.changelog import Changelog
with open('debian/changelog') as f:
ch = Changelog(f, max_blocks=1)
version = Version(os.environ['CURRENT_VERSION'])
with open('debian/source/format', 'w') as f:
if not ch.version.debian_revision:
print("3.0 (native)")
if not version.debian_revision:
f.write("3.0 (native)\n")
else:
print("3.0 (quilt)")
f.write("3.0 (quilt)\n")
print("Fixed-Lintian-Tags: missing-debian-source-format")
......@@ -148,7 +148,6 @@ class PkgRelation(object):
return restrictions
def parse_rel(raw):
# type: (str) -> Dict[str, Optional[Union[str, list, Tuple[str, str]]]]
match = cls.__dep_RE.match(raw)
if match:
parts = match.groupdict()
......@@ -158,7 +157,7 @@ class PkgRelation(object):
'version': None,
'arch': None,
'restrictions': None,
} # type: Dict[str, Optional[Union[str, list, Tuple[str, str]]]]
}
if parts['relop'] or parts['version']:
d['version'] = (parts['relop'], parts['version'])
if parts['archs']:
......@@ -182,11 +181,13 @@ class PkgRelation(object):
return [parse_rel(or_dep) for or_dep in or_deps]
def __repr__(self):
return "%s(%r, %r, %r, %r, %r)" % (self.__class__.__name__,
self.name, self.version, self.arch, self.archqual, self.restrictions)
return "%s(%r, %r, %r, %r, %r)" % (
self.__class__.__name__, self.name, self.version, self.arch,
self.archqual, self.restrictions)
def __tuple__(self):
return (self.name, self.version, self.arch, self.archqual, self.restrictions)
return (self.name, self.version, self.arch, self.archqual,
self.restrictions)
def __eq__(self, other):
if not isinstance(other, PkgRelation):
......@@ -235,7 +236,8 @@ class PkgRelation(object):
self.restrictions))
return s
def __init__(self, name, version=None, arch=None, archqual=None, restrictions=None):
def __init__(self, name, version=None, arch=None, archqual=None,
restrictions=None):
self.name = name
self.version = version
self.arch = arch
......@@ -257,7 +259,7 @@ def parse_relations(text):
ret = []
for top_level in text.split(','):
if top_level == "":
if not ',' in text:
if ',' not in text:
return []
if top_level.isspace():
ret.append((top_level, [], ''))
......@@ -324,7 +326,8 @@ def ensure_minimum_version(relationstr, package, minimum_version):
changed = True
relations.append(
(' ' if len(relations) > 0 else '',
[PkgRelation(name=package, version=('>=', minimum_version))], ''))
[PkgRelation(name=package, version=('>=', minimum_version))],
''))
if changed:
return format_relations(relations)
# Just return the original; we don't preserve all formatting yet.
......
......@@ -29,8 +29,10 @@ from lintian_brush import available_lintian_fixers
class FixerTestCase(unittest.TestCase):
"""Test case that runs a fixer test."""
def __init__(self, fixer, path):
def __init__(self, fixer, fixer_name, name, path):
self._fixer = fixer
self._fixer_name = fixer_name
self._test_name = name
self._path = path
self._testdir = None
self._tempdir = None
......@@ -39,7 +41,17 @@ class FixerTestCase(unittest.TestCase):
def setUp(self):
self._tempdir = tempfile.mkdtemp()
self._testdir = os.path.join(self._tempdir, 'testdir')
shutil.copytree(os.path.join(self._path, 'in'), self._testdir, symlinks=True)
def ignore(src, names):
return [name for name in names if name.endswith('~')]
shutil.copytree(os.path.join(self._path, 'in'), self._testdir,
symlinks=True, ignore=ignore)
def id(self):
return "%s.%s" % (__name__, self._fixer_name, self._test_name)
def __str__(self):
return 'fixer test: %s for %s' % (self._test_name, self._fixer_name)
def tearDown(self):
shutil.rmtree(self._tempdir)
......@@ -58,17 +70,21 @@ class FixerTestCase(unittest.TestCase):
# Assert that message on stdout matches
with open(os.path.join(self._path, 'message'), 'r') as f:
expected_message = f.read()
self.assertEqual(result.description, result.description)
self.assertEqual(result.description.strip(), expected_message.strip())
def test_suite():
suite = unittest.TestSuite()
test_dir = 'tests'
test_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'tests')
for fixer in available_lintian_fixers():
fixer_plain = os.path.splitext(os.path.basename(fixer.script_path))[0]
testpath = os.path.join(test_dir, fixer_plain)
if not os.path.isdir(testpath):
continue
for testname in os.listdir(testpath):
suite.addTest(FixerTestCase(fixer=fixer, path=os.path.join(test_dir, fixer_plain, testname)))
suite.addTest(FixerTestCase(
fixer_name=fixer_plain,
fixer=fixer,
name=testname,
path=os.path.join(test_dir, fixer_plain, testname)))
return suite
......@@ -133,7 +133,8 @@ class FormatRelationsTests(TestCase):
format_relations([(' \n', [PkgRelation('debhelper')], '')]),
' \ndebhelper')
self.assertEqual(
format_relations([(' \n', [PkgRelation('debhelper')], ' \n')]),
format_relations(
[(' \n', [PkgRelation('debhelper')], ' \n')]),
' \ndebhelper \n')
def test_multiple(self):
......@@ -142,17 +143,20 @@ class FormatRelationsTests(TestCase):
format_relations([('', [PkgRelation('debhelper')], ''),
(' ', [PkgRelation('blah')], '')]))
class EnsureMinimumVersionTests(TestCase):
def test_added(self):
self.assertEqual(
'debhelper (>= 9)', ensure_minimum_version('', 'debhelper', '9'))
self.assertEqual(
'blah, debhelper (>= 9)', ensure_minimum_version('blah', 'debhelper', '9'))
'blah, debhelper (>= 9)',
ensure_minimum_version('blah', 'debhelper', '9'))
def test_updated(self):
self.assertEqual(
'debhelper (>= 9)', ensure_minimum_version('debhelper', 'debhelper', '9'))
'debhelper (>= 9)',
ensure_minimum_version('debhelper', 'debhelper', '9'))
self.assertEqual(
'blah, debhelper (>= 9)',
ensure_minimum_version('blah, debhelper', 'debhelper', '9'))
......
Source: lintian-brush
X-Python-Version: >= 2.5
Package: lintian-brush
Description: Testing
Test test
Remove unnecessary X-Python{,3}-Version field in debian/control.
Source: lintian-brush
Package: lintian-brush
Description: Testing
Test test
Source: lintian-brush
X-Python3-Version: >= 3.2
Package: lintian-brush
Description: Testing
Test test
Remove unnecessary X-Python{,3}-Version field in debian/control.
Source: lintian-brush
Package: lintian-brush
Description: Testing
Test test
Remove unnecessary DM-Upload-Allowed field in debian/control.
Fixed-Lintian-Tags: dm-upload-allowed-is-obsolete
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment