diff --git a/.travis.yml b/.travis.yml index ebe996a..ef8a475 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,9 @@ +dist: xenial language: python +cache: + pip: true + directories: + - "$TRAVIS_BUILD_DIR/.tox" python: - 2.7 @@ -9,6 +14,10 @@ env: global: MACKEREL_APIKEY='xxxxxxxx' -before_install: pip install -r requirements.txt +before_install: + - pip install -U -r requirements.txt +before_script: + - flake8 --verbose --jobs=8 -script: python setup.py test +script: + - python setup.py test diff --git a/mackerel/__init__.py b/mackerel/__init__.py index de40ea7..68c04af 100644 --- a/mackerel/__init__.py +++ b/mackerel/__init__.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- __import__('pkg_resources').declare_namespace(__name__) diff --git a/mackerel/client.py b/mackerel/client.py index da1e110..44be228 100644 --- a/mackerel/client.py +++ b/mackerel/client.py @@ -13,6 +13,7 @@ :license: BSD, see LICENSE for more details. """ import logging + import requests import simplejson as json from mackerel.host import Host @@ -25,7 +26,7 @@ class MackerelClientError(Exception): class Client(object): #: Mackerel apikey error message. - ERROR_MESSAGE_FOR_API_KEY_ABSENCE = 'API key is absent. Set your API key in a environment variable called MACKEREL_APIKEY.' + ERROR_MESSAGE_FOR_API_KEY_ABSENCE = 'API key is absent. Set your API key in a environment variable called MACKEREL_APIKEY.' # noqa E501 #: Log format. debug_log_format = ( '[%(asctime)s %(levelname)s][%(pathname)s:%(lineno)d]: %(message)s' @@ -44,8 +45,7 @@ def __init__(self, logger=None, **kwargs): self.api_key = api_key if logger is None: - logging.basicConfig(level=logging.INFO, - format=self.debug_log_format) + logging.basicConfig(level=logging.INFO, format=self.debug_log_format) self.logger = logging.getLogger('mackerel.client') else: self.logger = logger @@ -176,8 +176,9 @@ def _request(self, uri, method='GET', headers=None, params=None): message = '{0} is not supported.'.format(method) raise NotImplementedError(message) - self.logger.debug('Response from {0} is {1}'.format(self.origin, - res.status_code)) + self.logger.debug( + 'Response from {0} is {1}'.format(self.origin, res.status_code), + ) if res.status_code != 200: message = '{0} {1} failed: {2}'.format(method, uri, res.status_code) raise MackerelClientError(message) diff --git a/mackerel/host.py b/mackerel/host.py index c6d27e1..0967376 100644 --- a/mackerel/host.py +++ b/mackerel/host.py @@ -57,10 +57,20 @@ def mac_addr(self): return i['macAddress'] def __repr__(self): + """Host instance.""" repr = '