Commit 7e0c6c10 authored by Aurélien Bompard's avatar Aurélien Bompard

PEP8 checking

parent 09eae1ea
......@@ -11,3 +11,7 @@ python3.4:
python3.5:
script:
- tox -e py35
lint:
script:
- tox -e lint
......@@ -16,7 +16,7 @@
# along with mailman.client. If not, see <http://www.gnu.org/licenses/>.
from setup_helpers import (
description, find_doctests, get_version, long_description, require_python)
description, get_version, long_description, require_python)
from setuptools import setup, find_packages
......@@ -28,7 +28,7 @@ setup(
name='mailmanclient',
version=__version__,
packages=find_packages('src'),
package_dir = {'': 'src'},
package_dir={'': 'src'},
include_package_data=True,
maintainer='Barry Warsaw',
maintainer_email='barry@list.org',
......
......@@ -18,6 +18,11 @@
from __future__ import absolute_import, print_function, unicode_literals
import os
import re
import sys
import codecs
__metaclass__ = type
__all__ = [
......@@ -29,17 +34,10 @@ __all__ = [
]
import os
import re
import sys
import codecs
DEFAULT_VERSION_RE = re.compile(r'(?P<version>\d+\.\d(?:\.\d+)?)')
NL = '\n'
def require_python(minimum):
"""Require at least a minimum Python version.
......@@ -69,7 +67,6 @@ def require_python(minimum):
sys.exit(1)
def get_version(filename, pattern=None):
"""Extract the __version__ from a file without importing it.
......@@ -103,7 +100,6 @@ def get_version(filename, pattern=None):
raise AssertionError('No __version__ assignment found')
def find_doctests(start='.', extension='.txt'):
"""Find separate-file doctests in the package.
......@@ -126,7 +122,6 @@ def find_doctests(start='.', extension='.txt'):
return doctests
def long_description(*filenames):
"""Provide a long description."""
res = []
......
......@@ -18,6 +18,10 @@
from __future__ import absolute_import, print_function, unicode_literals
from mailmanclient._client import Client, MailmanConnectionError
__metaclass__ = type
__all__ = [
'Client',
......@@ -27,6 +31,3 @@ __all__ = [
__version__ = '1.0.1'
from mailmanclient._client import Client, MailmanConnectionError
......@@ -18,13 +18,6 @@
from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'Client',
'MailmanConnectionError',
]
import six
import json
import warnings
......@@ -39,6 +32,13 @@ from six.moves.urllib_parse import (
urlencode, urljoin, urlsplit, urlunsplit, parse_qs)
__metaclass__ = type
__all__ = [
'Client',
'MailmanConnectionError',
]
DEFAULT_PAGE_ITEM_COUNT = 50
MISSING = object()
......@@ -133,12 +133,13 @@ class RESTBase:
for API elements that behave like an object, with REST data accessed
through attributes. If this value is None, the REST data is used to
list available properties.
:cvar _writable_properties: list of properties that can be written to using a
`PATCH` request. If this value is `None`, all properties are writable.
:cvar _writable_properties: list of properties that can be written to using
a `PATCH` request. If this value is `None`, all properties are
writable.
:cvar _read_only_properties: list of properties that cannot be written to
(defaults to `self_link` only).
:cvar _autosave: automatically send a `PATCH` request to the API when a value
is changed. Otherwise, the `save()` method must be called.
:cvar _autosave: automatically send a `PATCH` request to the API when a
value is changed. Otherwise, the `save()` method must be called.
"""
_properties = None
......@@ -169,7 +170,7 @@ class RESTBase:
if self._rest_data is None:
response, content = self._connection.call(self._url)
if isinstance(content, dict) and 'http_etag' in content:
del content['http_etag'] # We don't care about etags.
del content['http_etag'] # We don't care about etags.
self._rest_data = content
return self._rest_data
......@@ -185,14 +186,14 @@ class RESTBase:
def _set(self, key, value):
if (key in self._read_only_properties or (
self._writable_properties is not None
and key not in self._writable_properties)):
self._writable_properties is not None
and key not in self._writable_properties)):
raise ValueError('value is read-only')
# Don't check that the key is in _properties, the accepted values for
# write may be different from the returned values (eg: User.password
# and User.cleartext_password).
if key in self.rest_data and self.rest_data[key] == value:
return # Nothing to do
return # Nothing to do
self._changed_rest_data[key] = value
if self._autosave:
self.save()
......@@ -217,7 +218,7 @@ class RESTObject(RESTBase):
# Transform the KeyError into the more appropriate AttributeError
raise AttributeError(
"'{0}' object has no attribute '{1}'".format(
self.__class__.__name__, name))
self.__class__.__name__, name))
def __setattr__(self, name, value):
# RESTObject must list REST-specific properties or we won't be able to
......@@ -280,7 +281,7 @@ class RESTList(RESTBase, Sequence):
returned member of the list.
"""
_factory = lambda x: x
_factory = lambda x: x # flake8: noqa
@property
def rest_data(self):
......@@ -683,7 +684,8 @@ class MailingList(RESTObject):
@property
def settings(self):
if self._settings is None:
self._settings = Settings(self._connection,
self._settings = Settings(
self._connection,
'lists/{0}/config'.format(self.fqdn_listname))
return self._settings
......@@ -800,9 +802,10 @@ class MailingList(RESTObject):
def manage_request(self, token, action):
"""Alias for moderate_request, kept for compatibility"""
warnings.warn('The `manage_request()` method has been replaced by '
'`moderate_request()` and will be removed in the future.',
DeprecationWarning, stacklevel=2)
warnings.warn(
'The `manage_request()` method has been replaced by '
'`moderate_request()` and will be removed in the future.',
DeprecationWarning, stacklevel=2)
return self.moderate_request(token, action)
def accept_request(self, request_id):
......@@ -859,11 +862,11 @@ class MailingList(RESTObject):
subscriber=address,
display_name=display_name,
)
if pre_verified == True:
if pre_verified:
data['pre_verified'] = True
if pre_confirmed == True:
if pre_confirmed:
data['pre_confirmed'] = True
if pre_approved == True:
if pre_approved:
data['pre_approved'] = True
response, content = self._connection.call('members', data)
# If a member is not immediately subscribed (i.e. verificatoin,
......@@ -1074,8 +1077,10 @@ class Member(RESTObject, PreferencesMixin):
class User(RESTObject, PreferencesMixin):
_properties = ('created_on', 'display_name', 'is_server_owner', 'password', 'self_link', 'user_id')
_writable_properties = ('cleartext_password', 'display_name', 'is_server_owner')
_properties = ('created_on', 'display_name', 'is_server_owner',
'password', 'self_link', 'user_id')
_writable_properties = ('cleartext_password', 'display_name',
'is_server_owner')
def __init__(self, connection, url, data=None):
super(User, self).__init__(connection, url, data)
......
......@@ -23,6 +23,9 @@ distributions. doctest discovery currently requires file system traversal.
from __future__ import absolute_import, print_function, unicode_literals
from inspect import isfunction, ismethod
__metaclass__ = type
__all__ = [
'setup',
......@@ -30,10 +33,6 @@ __all__ = [
]
from inspect import isfunction, ismethod
def stop():
"""Call into pdb.set_trace()"""
# Do the import here so that you get the wacky special hacked pdb instead
......@@ -57,7 +56,6 @@ def dump(results):
print('{0}: {1}'.format(key, results[key]))
def setup(testobj):
"""Test setup."""
# Make sure future statements in our doctests are the same as everywhere
......@@ -75,7 +73,6 @@ def setup(testobj):
testobj.globs['cleanups'] = []
def teardown(testobj):
for cleanup in testobj.globs['cleanups']:
if isfunction(cleanup) or ismethod(cleanup):
......
......@@ -17,11 +17,6 @@
"""nose2 test infrastructure."""
__all__ = [
'NosePlugin',
]
import os
import re
import errno
......@@ -34,12 +29,16 @@ from nose2.events import Plugin
from .vcr_helpers import get_vcr
__all__ = [
'NosePlugin',
]
DOT = '.'
FLAGS = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF
TOPDIR = os.path.dirname(mailmanclient.__file__)
class NosePlugin(Plugin):
configSection = 'mailman'
......@@ -48,12 +47,14 @@ class NosePlugin(Plugin):
self.patterns = []
self.stderr = False
self.record = False
def set_stderr(ignore):
self.stderr = True
self.addArgument(self.patterns, 'P', 'pattern',
'Add a test matching pattern')
self.addFlag(set_stderr, 'E', 'stderr',
'Enable stderr logging to sub-runners')
def set_record(ignore):
self.record = True
self.addFlag(set_record, 'R', 'rerecord',
......@@ -124,8 +125,8 @@ class NosePlugin(Plugin):
test.shortDescription = lambda: None
event.extraTests.append(test)
## def startTest(self, event):
## import sys; print('vvvvv', event.test, file=sys.stderr)
# def startTest(self, event):
# import sys; print('vvvvv', event.test, file=sys.stderr)
## def stopTest(self, event):
## import sys; print('^^^^^', event.test, file=sys.stderr)
# def stopTest(self, event):
# import sys; print('^^^^^', event.test, file=sys.stderr)
......@@ -17,11 +17,6 @@
"""Helpers for VCR"""
__all__ = [
'get_vcr',
]
import vcr
from functools import update_wrapper
......@@ -29,6 +24,11 @@ from six import binary_type, text_type
from six.moves.urllib.parse import urlparse, urlunparse, parse_qsl, urlencode
__all__ = [
'get_vcr',
]
def filter_response_headers(response):
for header in ('Date', 'Server', 'date', 'server'):
# The headers are lowercase on Python 2 and capitalized on Python 3
......@@ -36,6 +36,7 @@ def filter_response_headers(response):
del response['headers'][header]
return response
def reorder_request_params(request):
def reorder_params(params):
parsed = parse_qsl(params)
......@@ -72,7 +73,6 @@ def get_vcr(**kwargs):
)
class vcr_testcase:
"""
Decorator for TestCases that use VCR.
......@@ -88,15 +88,18 @@ class vcr_testcase:
def decorate_class(self, testcase):
"""Create a subclass that will add setUp instructions."""
vcr_instance = self.vcr
class VCRTestCase(testcase):
vcr = vcr_instance
def setUp(self):
cm = self.vcr.use_cassette('.'.join([
#testcase.__module__.rpartition('.')[2],
# testcase.__module__.rpartition('.')[2],
testcase.__name__, self._testMethodName, 'yaml']))
self.cassette = cm.__enter__()
self.addCleanup(cm.__exit__, None, None, None)
super(VCRTestCase, self).setUp()
return update_wrapper(VCRTestCase, testcase,
return update_wrapper(
VCRTestCase, testcase,
assigned=('__module__', '__name__'), updated=[])
......@@ -18,18 +18,18 @@
from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'TestDomains',
]
import unittest
from mailmanclient import Client
from six.moves.urllib_error import HTTPError
__metaclass__ = type
__all__ = [
'TestDomains',
]
class TestDomains(unittest.TestCase):
def setUp(self):
self._client = Client(
......
......@@ -18,20 +18,19 @@
from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'TestPage',
]
import unittest
from mailmanclient._client import Page, DEFAULT_PAGE_ITEM_COUNT
from mock import Mock
from six.moves.urllib_error import HTTPError
from six.moves.urllib_parse import urlsplit, parse_qs
__metaclass__ = type
__all__ = [
'TestPage',
]
class TestPage(unittest.TestCase):
def test_url_simple(self):
......
[tox]
envlist = py27,py34,py35
envlist = py{27,34,35},lint
[testenv]
usedevelop = True
......@@ -14,3 +14,14 @@ deps =
[testenv:record]
basepython = python3
commands = python -m nose2 -v -R
[testenv:lint]
deps =
flake8 > 3.0
commands =
python -m flake8 {posargs}
[flake8]
show-source = true
exclude = .git,.tox,dist,*egg,src/mailmanclient/docs
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