[Python-modules-commits] [wlc] 01/03: New upstream version 0.6
Michal Cihar
nijel at moszumanska.debian.org
Tue Sep 20 11:47:02 UTC 2016
This is an automated email from the git hooks/post-receive script.
nijel pushed a commit to branch master
in repository wlc.
commit f9d44efe95222aa9d9891912d98f4ff8ac39b4e1
Author: Michal Čihař <michal at cihar.com>
Date: Tue Sep 20 13:45:37 2016 +0200
New upstream version 0.6
---
PKG-INFO | 6 +-
README.rst | 4 +
requirements-test.txt | 1 +
wlc.egg-info/PKG-INFO | 6 +-
wlc.egg-info/SOURCES.txt | 19 ++--
wlc/__init__.py | 126 +++++++++++++++------
wlc/config.py | 2 +-
wlc/main.py | 88 +++++++++-----
wlc/test_base.py | 34 ++++--
...components-hello-weblate-lock--POST--lock=0.swp | Bin 12288 -> 0 bytes
...components-hello-weblate-lock--POST--lock=1.swp | Bin 12288 -> 0 bytes
.../api/.components-hello-weblate-lock.swp | Bin 12288 -> 0 bytes
...mponents-hello-weblate-statistics--GET--page=2} | 0
...mponents-hello-weblate-statistics--GET--page=3} | 0
...onents-hello-weblate-translations--GET--page=2} | 0
.../{languages?page=2 => languages--GET--page=2} | 0
.../{languages?page=3 => languages--GET--page=3} | 0
...anslations?page=2 => translations--GET--page=2} | 0
...anslations?page=3 => translations--GET--page=3} | 0
wlc/test_main.py | 12 +-
wlc/test_wlc.py | 36 +++++-
21 files changed, 244 insertions(+), 90 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 724a126..05477f2 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: wlc
-Version: 0.5
+Version: 0.6
Summary: A command line utility for Weblate, translation tool with tight version control integration
Home-page: https://weblate.org/
Author: Michal Čihař
@@ -16,6 +16,10 @@ Description: wlc
:target: https://travis-ci.org/WeblateOrg/wlc
:alt: Build Status
+ .. image:: https://ci.appveyor.com/api/projects/status/e9a8n9qhvd6ulibw/branch/master?svg=true
+ :target: https://ci.appveyor.com/project/nijel/wlc/branch/master
+ :alt: Build status
+
.. image:: https://landscape.io/github/WeblateOrg/wlc/master/landscape.svg?style=flat
:target: https://landscape.io/github/WeblateOrg/wlc/master
:alt: Code Health
diff --git a/README.rst b/README.rst
index 4b2d6e5..106df93 100644
--- a/README.rst
+++ b/README.rst
@@ -7,6 +7,10 @@ wlc
:target: https://travis-ci.org/WeblateOrg/wlc
:alt: Build Status
+.. image:: https://ci.appveyor.com/api/projects/status/e9a8n9qhvd6ulibw/branch/master?svg=true
+ :target: https://ci.appveyor.com/project/nijel/wlc/branch/master
+ :alt: Build status
+
.. image:: https://landscape.io/github/WeblateOrg/wlc/master/landscape.svg?style=flat
:target: https://landscape.io/github/WeblateOrg/wlc/master
:alt: Code Health
diff --git a/requirements-test.txt b/requirements-test.txt
index a859bee..72a9492 100644
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -1,4 +1,5 @@
codecov
+codacy-coverage
HTTPretty!=0.8.11,!=0.8.12,!=0.8.13,!=0.8.14
pytest
pytest-cov
diff --git a/wlc.egg-info/PKG-INFO b/wlc.egg-info/PKG-INFO
index 724a126..05477f2 100644
--- a/wlc.egg-info/PKG-INFO
+++ b/wlc.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: wlc
-Version: 0.5
+Version: 0.6
Summary: A command line utility for Weblate, translation tool with tight version control integration
Home-page: https://weblate.org/
Author: Michal Čihař
@@ -16,6 +16,10 @@ Description: wlc
:target: https://travis-ci.org/WeblateOrg/wlc
:alt: Build Status
+ .. image:: https://ci.appveyor.com/api/projects/status/e9a8n9qhvd6ulibw/branch/master?svg=true
+ :target: https://ci.appveyor.com/project/nijel/wlc/branch/master
+ :alt: Build status
+
.. image:: https://landscape.io/github/WeblateOrg/wlc/master/landscape.svg?style=flat
:target: https://landscape.io/github/WeblateOrg/wlc/master
:alt: Code Health
diff --git a/wlc.egg-info/SOURCES.txt b/wlc.egg-info/SOURCES.txt
index 4f50660..c8aa01b 100644
--- a/wlc.egg-info/SOURCES.txt
+++ b/wlc.egg-info/SOURCES.txt
@@ -19,9 +19,6 @@ wlc.egg-info/top_level.txt
wlc/test_data/.weblate
wlc/test_data/section
wlc/test_data/wlc
-wlc/test_data/api/.components-hello-weblate-lock--POST--lock=0.swp
-wlc/test_data/api/.components-hello-weblate-lock--POST--lock=1.swp
-wlc/test_data/api/.components-hello-weblate-lock.swp
wlc/test_data/api/components
wlc/test_data/api/components-hello-android
wlc/test_data/api/components-hello-weblate
@@ -33,13 +30,13 @@ wlc/test_data/api/components-hello-weblate-repository--POST--operation=commit
wlc/test_data/api/components-hello-weblate-repository--POST--operation=pull
wlc/test_data/api/components-hello-weblate-repository--POST--operation=push
wlc/test_data/api/components-hello-weblate-statistics
-wlc/test_data/api/components-hello-weblate-statistics?page=2
-wlc/test_data/api/components-hello-weblate-statistics?page=3
+wlc/test_data/api/components-hello-weblate-statistics--GET--page=2
+wlc/test_data/api/components-hello-weblate-statistics--GET--page=3
wlc/test_data/api/components-hello-weblate-translations
-wlc/test_data/api/components-hello-weblate-translations?page=2
+wlc/test_data/api/components-hello-weblate-translations--GET--page=2
wlc/test_data/api/languages
-wlc/test_data/api/languages?page=2
-wlc/test_data/api/languages?page=3
+wlc/test_data/api/languages--GET--page=2
+wlc/test_data/api/languages--GET--page=3
wlc/test_data/api/projects
wlc/test_data/api/projects-hello
wlc/test_data/api/projects-hello-components
@@ -49,11 +46,11 @@ wlc/test_data/api/projects-hello-repository--POST--operation=pull
wlc/test_data/api/projects-hello-repository--POST--operation=push
wlc/test_data/api/projects-invalid
wlc/test_data/api/translations
+wlc/test_data/api/translations--GET--page=2
+wlc/test_data/api/translations--GET--page=3
wlc/test_data/api/translations-hello-weblate-cs
wlc/test_data/api/translations-hello-weblate-cs-repository
wlc/test_data/api/translations-hello-weblate-cs-repository--POST--operation=commit
wlc/test_data/api/translations-hello-weblate-cs-repository--POST--operation=pull
wlc/test_data/api/translations-hello-weblate-cs-repository--POST--operation=push
-wlc/test_data/api/translations-hello-weblate-cs-statistics
-wlc/test_data/api/translations?page=2
-wlc/test_data/api/translations?page=3
\ No newline at end of file
+wlc/test_data/api/translations-hello-weblate-cs-statistics
\ No newline at end of file
diff --git a/wlc/__init__.py b/wlc/__init__.py
index 2f02dd1..c9c3ce6 100644
--- a/wlc/__init__.py
+++ b/wlc/__init__.py
@@ -24,7 +24,7 @@ from urllib.parse import urlencode
import json
-__version__ = '0.5'
+__version__ = '0.6'
URL = 'https://weblate.org/'
DEVEL_URL = 'https://github.com/WeblateOrg/wlc'
@@ -33,10 +33,14 @@ USER_AGENT = 'wlc/{0}'.format(__version__)
class WeblateException(Exception):
+
"""Generic error."""
class Weblate(object):
+
+ """Weblate API wrapper object."""
+
def __init__(self, key='', url=API_URL, config=None):
"""Create the object, storing key and API url."""
if config is not None:
@@ -45,8 +49,28 @@ class Weblate(object):
self.key = key
self.url = url
+ @staticmethod
+ def process_error(error):
+ """Raise WeblateException for known HTTP errors."""
+ if hasattr(error, 'code'):
+ if error.code == 429:
+ raise WeblateException(
+ 'Throttling on the server'
+ )
+ elif error.code == 404:
+ raise WeblateException(
+ 'Object not found on the server'
+ )
+ elif error.code == 403:
+ raise WeblateException(
+ 'You don\'t have permission to access this object'
+ )
+ raise WeblateException(
+ 'HTTP error {0}: {1}'.format(error.code, error.reason)
+ )
+
def request(self, path, params=None):
- """Constructs request object"""
+ """Construct request object."""
if not path.startswith('http'):
path = '{0}{1}'.format(self.url, path)
request = Request(path)
@@ -62,22 +86,7 @@ class Weblate(object):
handle = urlopen(request, params)
content = handle.read()
except IOError as error:
- if hasattr(error, 'code'):
- if error.code == 429:
- raise WeblateException(
- 'Throttling on the server'
- )
- elif error.code == 404:
- raise WeblateException(
- 'Object not found on the server'
- )
- elif error.code == 403:
- raise WeblateException(
- 'You don\'t have permission to access this object'
- )
- raise WeblateException(
- 'HTTP error {0}: {1}'.format(error.code, error.reason)
- )
+ self.process_error(error)
raise
try:
result = json.loads(content.decode('utf-8'))
@@ -98,7 +107,7 @@ class Weblate(object):
return self.request(path)
def list_factory(self, path, parser):
- """Wrapper for listing objects"""
+ """Wrapper for listing objects."""
while path is not None:
data = self.get(path)
@@ -108,12 +117,14 @@ class Weblate(object):
path = data['next']
def _get_factory(self, prefix, path, parser):
- """Wrapper for getting objects"""
+ """Wrapper for getting objects."""
data = self.get('/'.join((prefix, path, '')))
return parser(weblate=self, **data)
def get_object(self, path):
- """Returns object (project, component, translation) based on path
+ """Return object based on path.
+
+ Operates on (project, component or translation objects.
"""
parts = path.strip('/').split('/')
if len(parts) == 3:
@@ -125,36 +136,38 @@ class Weblate(object):
raise ValueError('Not supported path: {0}'.format(path))
def get_project(self, path):
- """Returns project of given path"""
+ """Return project of given path."""
return self._get_factory('projects', path, Project)
def get_component(self, path):
- """Returns component of given path"""
+ """Return component of given path."""
return self._get_factory('components', path, Component)
def get_translation(self, path):
- """Returns translation of given path"""
+ """Return translation of given path."""
return self._get_factory('translations', path, Translation)
def list_projects(self, path='projects/'):
- """Lists projects in the instance"""
+ """List projects in the instance."""
return self.list_factory(path, Project)
def list_components(self, path='components/'):
- """Lists components in the instance"""
+ """List components in the instance."""
return self.list_factory(path, Component)
def list_translations(self, path='translations/'):
- """Lists translations in the instance"""
+ """List translations in the instance."""
return self.list_factory(path, Translation)
def list_languages(self):
- """Lists languages in the instance"""
+ """List languages in the instance."""
return self.list_factory('languages/', Language)
class LazyObject(dict):
- """Object which supports deferred loading"""
+
+ """Object which supports deferred loading."""
+
_params = ()
_mappings = {}
_url = None
@@ -165,6 +178,8 @@ class LazyObject(dict):
_id = 'url'
def __init__(self, weblate, url, **kwargs):
+ """Construct object for given Weblate instance."""
+ super(LazyObject, self).__init__()
self.weblate = weblate
self._url = url
self._data = {}
@@ -186,12 +201,14 @@ class LazyObject(dict):
self._attribs[key] = kwargs[key]
def ensure_loaded(self, attrib):
+ """Ensure attrbiute is loaded from remote."""
if attrib in self._data or attrib in self._attribs:
return
if not self._loaded:
self.refresh()
def refresh(self):
+ """Read object again from remote."""
data = self.weblate.get(self._url)
self._load_params(**data)
self._loaded = True
@@ -210,18 +227,23 @@ class LazyObject(dict):
return len(self._params)
def keys(self):
+ """Return list of attributes."""
return self._params
def items(self):
+ """Iterator over attributes."""
for key in self._params:
yield key, self.__getattr__(key)
def to_value(self):
+ """Return identifier for the object."""
return self.__getattr__(self._id)
class Language(LazyObject):
- """Language object"""
+
+ """Language object."""
+
_params = (
'url', 'web_url',
'code', 'name', 'nplurals', 'pluralequation', 'direction',
@@ -230,24 +252,29 @@ class Language(LazyObject):
class RepoMixin(object):
- """Repository mixin providing generic repository wide operations"""
+
+ """Repository mixin providing generic repository wide operations."""
+
def _get_repo_url(self):
self.ensure_loaded('repository_url')
return self._attribs['repository_url']
def commit(self):
+ """Commit Weblate changes."""
return self.weblate.post(
self._get_repo_url(),
operation='commit'
)
def push(self):
+ """Push Weblate changes upstream."""
return self.weblate.post(
self._get_repo_url(),
operation='push'
)
def pull(self):
+ """Pull upstream changes into Weblate."""
return self.weblate.post(
self._get_repo_url(),
operation='pull'
@@ -255,13 +282,20 @@ class RepoMixin(object):
class ProjectRepository(LazyObject, RepoMixin):
- """Repository object"""
+
+ """Repository object."""
+
_params = ('url', 'needs_commit', 'needs_merge', 'needs_push')
def _get_repo_url(self):
+ """Return repository url."""
return self._data['url']
+
class Repository(ProjectRepository):
+
+ """Repository object."""
+
_params = (
'url', 'needs_commit', 'needs_merge', 'needs_push',
'status', 'merge_failure', 'remote_commit',
@@ -269,9 +303,13 @@ class Repository(ProjectRepository):
class RepoObjectMixin(RepoMixin):
+
+ """Repository mixin."""
+
_repository_class = ProjectRepository
def repository(self):
+ """Return repository object."""
data = self.weblate.get(
self._get_repo_url()
)
@@ -279,7 +317,9 @@ class RepoObjectMixin(RepoMixin):
class Project(LazyObject, RepoObjectMixin):
- """Project object"""
+
+ """Project object."""
+
_params = (
'url', 'web_url',
'name', 'slug', 'web', 'source_language'
@@ -290,13 +330,17 @@ class Project(LazyObject, RepoObjectMixin):
}
def list(self):
+ """List components in the project."""
self.ensure_loaded('components_list_url')
return self.weblate.list_components(
self._attribs['components_list_url']
)
+
class Component(LazyObject, RepoObjectMixin):
- """Component object"""
+
+ """Component object."""
+
_params = (
'url', 'web_url',
'name', 'slug', 'project', 'vcs', 'repo', 'git_export', 'branch',
@@ -310,12 +354,14 @@ class Component(LazyObject, RepoObjectMixin):
_repository_class = Repository
def list(self):
+ """List translations in the component."""
self.ensure_loaded('translations_url')
return self.weblate.list_translations(
self._attribs['translations_url']
)
def statistics(self):
+ """Return statistics for component."""
self.ensure_loaded('statistics_url')
return self.weblate.list_factory(
self._attribs['statistics_url'], Statistics
@@ -326,25 +372,30 @@ class Component(LazyObject, RepoObjectMixin):
return self._attribs['lock_url']
def lock(self):
+ """Lock component from translations."""
return self.weblate.post(
self._get_lock_url(),
lock=1
)
def unlock(self):
+ """Unlock component from translations."""
return self.weblate.post(
self._get_lock_url(),
lock=0
)
def lock_status(self):
+ """Return component lock status."""
return self.weblate.get(
self._get_lock_url(),
)
class Translation(LazyObject, RepoObjectMixin):
- """Translation object"""
+
+ """Translation object."""
+
_params = (
'url', 'web_url',
'language', 'component', 'translated', 'fuzzy', 'total',
@@ -362,16 +413,21 @@ class Translation(LazyObject, RepoObjectMixin):
_repository_class = Repository
def list(self):
+ """API compatibility method, returns self."""
self.ensure_loaded('last_author')
return self
def statistics(self):
+ """Return statistics for translation."""
self.ensure_loaded('statistics_url')
data = self.weblate.get(self._attribs['statistics_url'])
return Statistics(weblate=self.weblate, **data)
class Statistics(LazyObject):
+
+ """Statistics object."""
+
_params = (
'last_author', 'code', 'failing_percent', 'url', 'translated_percent',
'total_words', 'failing', 'translated_words', 'url_translate',
diff --git a/wlc/config.py b/wlc/config.py
index 065074b..7951974 100644
--- a/wlc/config.py
+++ b/wlc/config.py
@@ -65,7 +65,7 @@ class WeblateConfig(RawConfigParser):
cwd = os.path.dirname(cwd)
def get_url_key(self):
- """Returns API URL and key"""
+ """Get API URL and key."""
url = self.get(self.section, 'url')
key = self.get(self.section, 'key')
if not key:
diff --git a/wlc/main.py b/wlc/main.py
index e569615..1c1d97f 100644
--- a/wlc/main.py
+++ b/wlc/main.py
@@ -73,7 +73,12 @@ def get_parser():
'--url', '-u',
help='API URL',
)
- subparser = parser.add_subparsers(dest="cmd")
+ subparser = parser.add_subparsers(
+ title='subcommands',
+ description='Subcommands specify what action to perform.',
+ dest='cmd'
+ )
+ subparser.required = True
for command in COMMANDS:
COMMANDS[command].add_parser(subparser)
@@ -82,8 +87,11 @@ def get_parser():
class CommandError(Exception):
+
"""Generic error from command line."""
+
def __init__(self, message, detail=None):
+ """Create CommandError exception."""
if detail is not None:
message = '\n'.join((message, detail))
super(CommandError, self).__init__(message)
@@ -231,7 +239,8 @@ class Command(object):
class ObjectCommand(Command):
- """Command to require path to object"""
+
+ """Command to require path to object."""
@classmethod
def add_parser(cls, subparser):
@@ -248,7 +257,7 @@ class ObjectCommand(Command):
return parser
def get_object(self):
- """Returns object"""
+ """Return object."""
if self.args.object:
path = self.args.object[0]
else:
@@ -296,7 +305,8 @@ class Version(Command):
@register_command
class ListProjects(Command):
- """Lists projects."""
+
+ """List projects."""
name = 'list-projects'
description = "Lists all projects"
@@ -308,7 +318,8 @@ class ListProjects(Command):
@register_command
class ListComponents(Command):
- """Lists components."""
+
+ """List components."""
name = 'list-components'
description = "Lists all components"
@@ -320,7 +331,8 @@ class ListComponents(Command):
@register_command
class ListLanguages(Command):
- """Lists languages."""
+
+ """List languages."""
name = 'list-languages'
description = "Lists all languages"
@@ -332,7 +344,8 @@ class ListLanguages(Command):
@register_command
class ListTranslations(Command):
- """Lists translations."""
+
+ """List translations."""
name = 'list-translations'
description = "Lists all translations"
@@ -344,25 +357,27 @@ class ListTranslations(Command):
@register_command
class ShowObject(ObjectCommand):
- """Shows object"""
+
+ """Show object."""
name = 'show'
description = "Shows translation, component or project"
def run(self):
- """Executor"""
+ """Executor."""
self.print(self.get_object())
@register_command
class ListObject(ObjectCommand):
- """Lists object"""
+
+ """List object."""
name = 'ls'
description = "List content of translation, component or project"
def run(self):
- """Executor"""
+ """Executor."""
try:
obj = self.get_object()
self.print(list(obj.list()))
@@ -374,13 +389,14 @@ class ListObject(ObjectCommand):
@register_command
class CommitObject(ObjectCommand):
- """Commits object"""
+
+ """Commit object."""
name = 'commit'
description = "Commits changes in translation, component or project"
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
result = obj.commit()
if not result['result']:
@@ -392,7 +408,8 @@ class CommitObject(ObjectCommand):
@register_command
class PushObject(ObjectCommand):
- """Pushes object"""
+
+ """Push object."""
name = 'push'
description = (
@@ -401,19 +418,20 @@ class PushObject(ObjectCommand):
)
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
result = obj.push()
if not result['result']:
raise CommandError(
'Failed to push changes!',
- result['detail'],
+ result['detail'] if 'detail' in result else '',
)
@register_command
class PullObject(ObjectCommand):
- """Pulls object"""
+
+ """Pull object."""
name = 'pull'
description = (
@@ -422,7 +440,7 @@ class PullObject(ObjectCommand):
)
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
result = obj.pull()
if not result['result']:
@@ -434,7 +452,8 @@ class PullObject(ObjectCommand):
@register_command
class RepoObject(ObjectCommand):
- """Displays repository status for object"""
+
+ """Display repository status for object."""
name = 'repo'
description = (
@@ -443,14 +462,15 @@ class RepoObject(ObjectCommand):
)
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
self.print(obj.repository())
@register_command
class StatsObject(ObjectCommand):
- """Displays repository statistics for object"""
+
+ """Display repository statistics for object."""
name = 'stats'
description = (
@@ -459,7 +479,7 @@ class StatsObject(ObjectCommand):
)
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
if isinstance(obj, wlc.Project):
raise CommandError('Not supported')
@@ -470,17 +490,25 @@ class StatsObject(ObjectCommand):
class ComponentCommand(ObjectCommand):
- """Wrapper to allow only component objects"""
+
+ """Wrapper to allow only component objects."""
+
def get_object(self):
+ """Return component object."""
obj = super(ComponentCommand, self).get_object()
if not isinstance(obj, wlc.Component):
raise CommandError('Not supported')
return obj
+ def run(self):
+ """Main execution of the command."""
+ raise NotImplementedError()
+
@register_command
class LockStatusObject(ComponentCommand):
- """Shows lock status"""
+
+ """Show lock status."""
name = 'lock-status'
description = (
@@ -488,14 +516,15 @@ class LockStatusObject(ComponentCommand):
)
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
self.print(obj.lock_status())
@register_command
class LockObject(ComponentCommand):
- """Locks component for transaltion"""
+
+ """Lock component for transaltion."""
name = 'lock'
description = (
@@ -503,14 +532,15 @@ class LockObject(ComponentCommand):
)
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
obj.lock()
@register_command
class UnlockObject(ComponentCommand):
- """Unocks component for transaltion"""
+
+ """Unock component for transaltion."""
name = 'unlock'
description = (
@@ -518,7 +548,7 @@ class UnlockObject(ComponentCommand):
)
def run(self):
- """Executor"""
+ """Executor."""
obj = self.get_object()
obj.unlock()
diff --git a/wlc/test_base.py b/wlc/test_base.py
index bb53a05..a7e3cec 100644
--- a/wlc/test_base.py
+++ b/wlc/test_base.py
@@ -27,29 +27,44 @@ DATA_TEST_BASE = os.path.join(os.path.dirname(__file__), 'test_data', 'api')
class ResponseHandler(object):
+
+ """httpretty response handler."""
+
def __init__(self, body, filename):
+ """Construct response handler object."""
self.body = body
self.filename = filename
- def __call__(self, request, uri, headers):
+ def get_filename(self, request):
+ """Return filename for given request."""
filename = None
if request.method != 'GET':
filename = '--'.join(
(self.filename, request.method, request.body.decode('ascii'))
)
elif '?' in request.path:
- filename = '?'.join(
- (self.filename, request.path.split('?', 1)[-1])
+ filename = '--'.join(
+ (self.filename, request.method, request.path.split('?', 1)[-1])
)
+ return filename
+
+ def get_content(self, request):
+ """Return content for given request."""
+ filename = self.get_filename(request)
if filename is not None:
with open(filename, 'rb') as handle:
- return (200, headers, handle.read())
- return (200, headers, self.body)
+ return handle.read()
+
+ return self.body
+
+ def __call__(self, request, uri, headers):
+ """Function call interface for httpretty."""
+ return (200, headers, self.get_content(request))
def register_uri(path, domain='http://127.0.0.1:8000/api'):
- """Simplified URL registration"""
+ """Simplified URL registration."""
filename = os.path.join(DATA_TEST_BASE, path.replace('/', '-'))
url = '/'.join((domain, path, ''))
with open(filename, 'rb') as handle:
@@ -68,7 +83,7 @@ def register_uri(path, domain='http://127.0.0.1:8000/api'):
def register_error(path, code, domain='http://127.0.0.1:8000/api'):
- """Simplified URL error registration"""
+ """Simplified URL error registration."""
url = '/'.join((domain, path, ''))
httpretty.register_uri(
httpretty.GET,
@@ -107,10 +122,15 @@ def register_uris():
class APITest(TestCase):
+
+ """Base class for API testing."""
+
def setUp(self):
+ """Enable httpretty and register urls."""
httpretty.enable()
register_uris()
def tearDown(self):
+ """Disable httpretty."""
httpretty.disable()
httpretty.reset()
diff --git a/wlc/test_data/api/.components-hello-weblate-lock--POST--lock=0.swp b/wlc/test_data/api/.components-hello-weblate-lock--POST--lock=0.swp
deleted file mode 100644
index 2b1c879..0000000
Binary files a/wlc/test_data/api/.components-hello-weblate-lock--POST--lock=0.swp and /dev/null differ
diff --git a/wlc/test_data/api/.components-hello-weblate-lock--POST--lock=1.swp b/wlc/test_data/api/.components-hello-weblate-lock--POST--lock=1.swp
deleted file mode 100644
index 0990660..0000000
Binary files a/wlc/test_data/api/.components-hello-weblate-lock--POST--lock=1.swp and /dev/null differ
diff --git a/wlc/test_data/api/.components-hello-weblate-lock.swp b/wlc/test_data/api/.components-hello-weblate-lock.swp
deleted file mode 100644
index a8af8b8..0000000
Binary files a/wlc/test_data/api/.components-hello-weblate-lock.swp and /dev/null differ
diff --git a/wlc/test_data/api/components-hello-weblate-statistics?page=2 b/wlc/test_data/api/components-hello-weblate-statistics--GET--page=2
similarity index 100%
rename from wlc/test_data/api/components-hello-weblate-statistics?page=2
rename to wlc/test_data/api/components-hello-weblate-statistics--GET--page=2
diff --git a/wlc/test_data/api/components-hello-weblate-statistics?page=3 b/wlc/test_data/api/components-hello-weblate-statistics--GET--page=3
similarity index 100%
rename from wlc/test_data/api/components-hello-weblate-statistics?page=3
rename to wlc/test_data/api/components-hello-weblate-statistics--GET--page=3
diff --git a/wlc/test_data/api/components-hello-weblate-translations?page=2 b/wlc/test_data/api/components-hello-weblate-translations--GET--page=2
similarity index 100%
rename from wlc/test_data/api/components-hello-weblate-translations?page=2
rename to wlc/test_data/api/components-hello-weblate-translations--GET--page=2
diff --git a/wlc/test_data/api/languages?page=2 b/wlc/test_data/api/languages--GET--page=2
similarity index 100%
rename from wlc/test_data/api/languages?page=2
rename to wlc/test_data/api/languages--GET--page=2
diff --git a/wlc/test_data/api/languages?page=3 b/wlc/test_data/api/languages--GET--page=3
similarity index 100%
rename from wlc/test_data/api/languages?page=3
rename to wlc/test_data/api/languages--GET--page=3
diff --git a/wlc/test_data/api/translations?page=2 b/wlc/test_data/api/translations--GET--page=2
similarity index 100%
rename from wlc/test_data/api/translations?page=2
rename to wlc/test_data/api/translations--GET--page=2
diff --git a/wlc/test_data/api/translations?page=3 b/wlc/test_data/api/translations--GET--page=3
similarity index 100%
rename from wlc/test_data/api/translations?page=3
rename to wlc/test_data/api/translations--GET--page=3
diff --git a/wlc/test_main.py b/wlc/test_main.py
index 7a5be8b..140cf10 100644
--- a/wlc/test_main.py
+++ b/wlc/test_main.py
@@ -19,8 +19,7 @@
#
"""Test command line interface."""
-from io import StringIO, BytesIO
-import httpretty
+from io import StringIO
import json
import sys
import os
@@ -80,7 +79,9 @@ class TestSettings(APITest):
def test_config(self):
"""Configuration using custom config file."""
- output = execute(['--config', TEST_CONFIG, 'list-projects'], settings=False)
+ output = execute(
+ ['--config', TEST_CONFIG, 'list-projects'], settings=False
+ )
self.assertIn('Hello', output)
def test_config_section(self):
@@ -96,7 +97,7 @@ class TestSettings(APITest):
self.assertIn('Hello', output)
def test_config_cwd(self):
- """Test loading settings from current dir"""
+ """Test loading settings from current dir."""
current = os.path.abspath('.')
try:
os.chdir(os.path.join(os.path.dirname(__file__), 'test_data'))
@@ -172,6 +173,9 @@ class TestOutput(APITest):
class TestCommands(APITest):
+
+ """Individual command tests."""
+
def test_version_bare(self):
"""Test version printing."""
output = execute(['version', '--bare'])
diff --git a/wlc/test_wlc.py b/wlc/test_wlc.py
index b7d2bb3..62e648f 100644
--- a/wlc/test_wlc.py
+++ b/wlc/test_wlc.py
@@ -26,7 +26,8 @@ from wlc import (
class WeblateErrorTest(APITest):
- """Testing error handling"""
+
+ """Testing error handling."""
... 178 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/wlc.git
More information about the Python-modules-commits
mailing list