Skip to content

Commit

Permalink
Merge pull request #258 from deniszh/backport/1.1.x/pr-253_pr-254_pr-…
Browse files Browse the repository at this point in the history
…255_pr-257_pr-257

[1.1.x] Include tests in PyPI distributions | Make rrd2whisper.py run with Python 3 | E722 do not use bare except | Add testing for Python 3.7 in Travis and update languages in setup.py | Run tox from Travis
  • Loading branch information
deniszh authored Aug 27, 2018
2 parents 79c0111 + 85fb97a commit 8ae9706
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ htmlcov/*
ve
.idea
*.iml
*.swp
55 changes: 30 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
language: python
sudo: false
python: 2.7

python:
- 2.7
- pypy
- 3.2
- 3.3
- 3.4
- 3.5
- 3.6
- pypy3
# 3.7 needs xenial and sudo https://github.com/travis-ci/travis-ci/issues/9815
# This enables 3.7 without globally enabling sudo and dist: xenial for other build jobs
matrix:
include:
- python: 2.7
env:
- TOXENV=py27
- python: 3.4
env:
- TOXENV=py34
- python: 3.5
env:
- TOXENV=py35
- python: 3.6
env:
- TOXENV=py36
- python: 3.7
dist: xenial
sudo: true
env:
- TOXENV=py37
- python: 3.7
dist: xenial
sudo: true
env:
- TOXENV=lint

install:
- pip install .
- (python --version 2>&1 | grep -q "Python 3.2." && pip install "coverage<4" coveralls) || pip install coverage coveralls
- pip install tox

script:
- bin/whisper-create.py --help
- bin/whisper-dump.py --help
- bin/whisper-fetch.py --help
- bin/whisper-fill.py --help
- bin/whisper-info.py --help
- bin/whisper-merge.py --help
- bin/whisper-resize.py --help
- bin/whisper-set-aggregation-method.py --help
- bin/whisper-update.py --help
- contrib/whisper-auto-update.py --help
- contrib/whisper-auto-resize.py --help
- "if echo $TRAVIS_PYTHON_VERSION | egrep -q '^pypy$'; then pip install unittest2; fi"
# Coverage of tests ensures we don't have dead coded in the tests
- coverage run --include='whisper.py,test_whisper.py' test_whisper.py
- tox -e $TOXENV

after_success:
coveralls
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude .* MANIFEST.in
global-exclude __pycache__
global-exclude *.py[co]
include test_whisper.py
2 changes: 1 addition & 1 deletion bin/rrd2whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Ignore SIGPIPE
signal.signal(signal.SIGPIPE, signal.SIG_DFL)

aggregationMethods = whisper.aggregationMethods
aggregationMethods = list(whisper.aggregationMethods)

# RRD doesn't have a 'sum' or 'total' type
aggregationMethods.remove('sum')
Expand Down
4 changes: 2 additions & 2 deletions bin/whisper-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def read_header(map):
try:
(aggregationType, maxRetention, xFilesFactor, archiveCount) \
= struct.unpack(whisper.metadataFormat, map[:whisper.metadataSize])
except:
except (struct.error, ValueError, TypeError):
raise whisper.CorruptWhisperFile("Unable to unpack header")

archives = []
Expand All @@ -57,7 +57,7 @@ def read_header(map):
whisper.archiveInfoFormat,
map[archiveOffset:archiveOffset + whisper.archiveInfoSize]
)
except:
except (struct.error, ValueError, TypeError):
raise whisper.CorruptWhisperFile("Unable to read archive %d metadata" % i)

archiveInfo = {
Expand Down
2 changes: 1 addition & 1 deletion bin/whisper-resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
try:
print('Renaming new database to: %s' % path)
os.rename(tmpfile, path)
except:
except (OSError, FileNotFoundError, PermissionError):
traceback.print_exc()
print('\nOperation failed, restoring backup')
os.rename(backup, path)
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
install_requires=['six'],
classifiers=[
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
Expand Down
18 changes: 17 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@ envlist =
py34,
py35,
py36,
py37,
pypy,
pypy3,
lint,

[testenv]
commands =
coverage run --branch --omit=.tox/* -m unittest discover
sh -c 'bin/whisper-create.py --help >/dev/null'
sh -c 'bin/whisper-create.py --help >/dev/null'
sh -c 'bin/whisper-dump.py --help >/dev/null'
sh -c 'bin/whisper-fetch.py --help >/dev/null'
sh -c 'bin/whisper-fill.py --help >/dev/null'
sh -c 'bin/whisper-info.py --help >/dev/null'
sh -c 'bin/whisper-merge.py --help >/dev/null'
sh -c 'bin/whisper-resize.py --help >/dev/null'
sh -c 'bin/whisper-set-aggregation-method.py --help >/dev/null'
sh -c 'bin/whisper-update.py --help >/dev/null'
sh -c 'contrib/whisper-auto-update.py --help >/dev/null'
sh -c 'contrib/whisper-auto-resize.py --help >/dev/null'
coverage run --branch --include='whisper.py,test_whisper.py' test_whisper.py
coverage xml
coverage report
deps =
coverage
mock
whitelist_externals =
sh

[testenv:lint]
deps = flake8
Expand Down
6 changes: 3 additions & 3 deletions whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ def __readHeader(fh):
try:
(aggregationType, maxRetention, xff, archiveCount) \
= struct.unpack(metadataFormat, packedMetadata)
except:
except (struct.error, ValueError, TypeError):
raise CorruptWhisperFile("Unable to read header", fh.name)

try:
aggregationTypeToMethod[aggregationType]
except:
except KeyError:
raise CorruptWhisperFile("Unable to read header", fh.name)

if not 0 <= xff <= 1:
Expand Down Expand Up @@ -398,7 +398,7 @@ def __writeHeaderMetadata(fh, aggregationMethod, maxRetention, xFilesFactor, arc

try:
xFilesFactor = float(xFilesFactor)
except:
except ValueError:
raise InvalidXFilesFactor("Invalid xFilesFactor %s, not a float" %
xFilesFactor)

Expand Down

0 comments on commit 8ae9706

Please sign in to comment.