Skip to content
Snippets Groups Projects

add type annotations and pylint configuration

Merged Stuart Prescott requested to merge stuart/python-debian:typing into master
All threads resolved!
Files
13
@@ -28,14 +28,16 @@ import sys
import tempfile
import unittest
import warnings
try:
import six
if six.PY3:
from io import BytesIO, StringIO
else:
from StringIO import StringIO
BytesIO = StringIO
except ImportError:
from io import BytesIO, StringIO
import apt_pkg
import six
import apt_pkg #type: ignore
from debian import deb822
@@ -374,12 +376,12 @@ class TestDeb822(unittest.TestCase):
self.assertEqual(v, deb822_[k])
self.assertEqual(deb822_, dict_)
@staticmethod
def gen_random_string(length=20):
from random import choice
import string
chars = string.ascii_letters + string.digits
return ''.join([choice(chars) for i in range(length)])
gen_random_string = staticmethod(gen_random_string)
def deb822_from_format_string(self, string, dict_=PARSED_PACKAGE, cls=deb822.Deb822):
"""Construct a Deb822 object by formatting string with % dict.
@@ -856,22 +858,18 @@ Description: python modules to work with Debian-related data formats
# Avoid spitting out the encoding warning during testing.
warnings.filterwarnings(action='ignore', category=UnicodeWarning)
filename = 'test_Sources.mixed_encoding'
# TODO: With Python >= 2.7, this might be better written as:
# with open(filename, 'rb') as f1, open(filename, 'rb') as f2:
f1 = open(find_test_file(filename), 'rb')
f2 = open(find_test_file(filename), 'rb')
for paragraphs in [deb822.Sources.iter_paragraphs(f1),
deb822.Sources.iter_paragraphs(f2,
use_apt_pkg=False)]:
p1 = next(paragraphs)
self.assertEqual(p1['maintainer'],
six.u('Adeodato Sim\xf3 <dato@net.com.org.es>'))
p2 = next(paragraphs)
self.assertEqual(p2['uploaders'],
six.u('Frank K\xfcster <frank@debian.org>'))
f2.close()
f1.close()
filename = find_test_file('test_Sources.mixed_encoding')
with open(filename, 'rb') as f1, open(filename, 'rb') as f2:
for paragraphs in [
deb822.Sources.iter_paragraphs(f1),
deb822.Sources.iter_paragraphs(f2, use_apt_pkg=False)
]:
p1 = next(paragraphs)
self.assertEqual(p1['maintainer'],
six.u('Adeodato Sim\xf3 <dato@net.com.org.es>'))
p2 = next(paragraphs)
self.assertEqual(p2['uploaders'],
six.u('Frank K\xfcster <frank@debian.org>'))
def test_dump_text_mode(self):
d = deb822.Deb822(CHANGES_FILE.splitlines())
@@ -1304,9 +1302,9 @@ def _no_space(s):
class RestrictedWrapperTest(unittest.TestCase):
class Wrapper(deb822.RestrictedWrapper):
restricted_field = deb822.RestrictedField('Restricted-Field')
required_field = deb822.RestrictedField('Required-Field', allow_none=False)
space_separated = deb822.RestrictedField(
restricted_field = deb822.RestrictedField('Restricted-Field') # type: ignore
required_field = deb822.RestrictedField('Required-Field', allow_none=False) # type: ignore
space_separated = deb822.RestrictedField( # type: ignore
'Space-Separated',
from_str=lambda s: tuple((s or '').split()),
to_str=lambda seq: ' '.join(_no_space(s) for s in seq) or None)
Loading