Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Sep 5, 2017
2 parents b75b994 + 2c03437 commit eb7af5e
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
sudo: false
language: python
python:
- "2.6"
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "pypy"
- "pypy3"

# command to install dependencies
install:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath(os.path.pardir))

import statsd
from statsd import __about__ as statsd

# -- General configuration -----------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e.[docs,tests]
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ universal = 1
[flake8]
ignore = W391
exclude = docs/*,statsd/compat.py

[upload]
sign = 1
54 changes: 37 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
import os
import statsd
import setuptools

# To prevent importing about and thereby breaking the coverage info we use this
# exec hack
about = {}
with open('statsd/__about__.py') as fp:
exec(fp.read(), about)

if os.path.isfile('README.rst'):
long_description = open('README.rst').read()
else:
long_description = 'See http://pypi.python.org/pypi/python-statsd/'

setuptools.setup(
name=statsd.__package_name__,
version=statsd.__version__,
author=statsd.__author__,
author_email=statsd.__author_email__,
description=statsd.__description__,
url=statsd.__url__,
license='BSD',
packages=setuptools.find_packages(exclude=('tests',)),
long_description=long_description,
test_suite='nose.collector',
tests_require=['nose', 'mock', 'coverage'],
classifiers=[
'License :: OSI Approved :: BSD License',
],
)
tests_require = [
'nose',
'coverage',
'mock',
]

docs_require = [
'changelog',
'sphinx>=1.5.0',
]

if __name__ == '__main__':
setuptools.setup(
name=about['__package_name__'],
version=about['__version__'],
author=about['__author__'],
author_email=about['__author_email__'],
description=about['__description__'],
url=about['__url__'],
license='BSD',
packages=setuptools.find_packages(exclude=('docs', 'tests',)),
long_description=long_description,
test_suite='nose.collector',
classifiers=[
'License :: OSI Approved :: BSD License',
],
extras_require={
'docs': docs_require,
'tests': tests_require,
},
)

10 changes: 10 additions & 0 deletions statsd/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__package_name__ = 'python-statsd'
__version__ = '2.1.0'
__author__ = 'Rick van Hattem'
__author_email__ = '[email protected]'
__description__ = (
'''statsd is a client for Etsy's node-js statsd server. '''
'''A proxy for the Graphite stats collection and graphing server.''')
__url__ = 'https://github.com/WoLpH/python-statsd'


9 changes: 0 additions & 9 deletions statsd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
'decrement',
]

__package_name__ = 'python-statsd'
__version__ = '2.0.0'
__author__ = 'Rick van Hattem'
__author_email__ = '[email protected]'
__description__ = (
'''statsd is a client for Etsy's node-js statsd server. '''
'''A proxy for the Graphite stats collection and graphing server.''')
__url__ = 'https://github.com/WoLpH/python-statsd'


# The doctests in this package, when run, will try to send data on the wire.
# To keep this from happening, we hook into nose's machinery to mock out
Expand Down
21 changes: 21 additions & 0 deletions statsd/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ def stop(self, subname='total'):
self._stop = time.time()
return self.send(subname, self._stop - self._start)

def __enter__(self):
'''
Make a context manager out of self to measure time execution in a block
of code.
:return: statsd.timer.Timer
'''
self.start()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
'''
Stop measuring time sending total metric, while exiting block of code.
:param exc_type:
:param exc_val:
:param exc_tb:
:return:
'''
self.stop()

def _decorate(self, name, function, class_=None):
class_ = class_ or Timer

Expand Down
Empty file added tests/conftest.py
Empty file.
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e.[tests]
10 changes: 10 additions & 0 deletions tests/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ def generator():
yield i
time_time.side_effect = generator()

@mock.patch('statsd.Client')
def test_context_manager(self, mock_client):
timer = statsd.Timer('cm')
with timer:
# Do something here
pass

assert self.get_time(mock_client, 'cm.total') == 123.4, \
'This test must execute within 2ms'

@mock.patch('statsd.Client')
def test_context_manager_default(self, mock_client):
timer = self.timer.get_client('default')
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py34, py35, pypy, pypy3, flake8, docs
envlist = py27, py33, py34, py35, py36, pypy, flake8, docs
skip_missing_interpreters = True

[testenv]
Expand All @@ -13,8 +13,9 @@ commands =
nosetests --with-coverage --cover-min-percentage=100

[testenv:flake8]
basepython = python2.7
deps = flake8
commands = flake8 --ignore=W391 statsd
commands = flake8 --ignore=W391 {toxinidir}/statsd {toxinidir}/tests

[testenv:docs]
deps = sphinx
Expand Down

0 comments on commit eb7af5e

Please sign in to comment.