Skip to content

Commit

Permalink
tools: Switch from nose to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
fetzerch committed Oct 21, 2018
1 parent 97d6048 commit 3c81257
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ deploy:production:
name: $CI_PROJECT_NAME - Production

tools:
image: python:3-alpine
image: python:3.6
variables:
GIT_SUBMODULE_STRATEGY: none
before_script:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
- language: python
python: 3.6
install: pip install tox
script: cd tools && tox
script: cd tools && tox -e py36
57 changes: 54 additions & 3 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
__pycache__

.tox
# C extensions
*.so

.coverage
# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
AUTHORS
ChangeLog

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
cover/
htmlcov/
.tox/
.coverage
.cache
.pytest_cache/
nosetests.xml
coverage.xml
junit-*.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/
3 changes: 0 additions & 3 deletions tools/pylintrc.ini → tools/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[REPORTS]
msg-template="{abspath}:{line}: [{msg_id}({symbol}), {obj}] {msg}"

[MESSAGE CONTROL]
disable=locally-disabled
16 changes: 6 additions & 10 deletions tools/jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,11 @@
mkdir $WORKSPACE/build-python
cd $WORKSPACE/sources/tools
for py in py2 py3; do
tox -e $py-flake8 | tee $WORKSPACE/build-python/$py-flake8.log
tox -e $py-pylint | tee $WORKSPACE/build-python/$py-pylint.log
tox -e $py-coverage -- \
--with-xunit \
--xunit-file=$WORKSPACE/build-python/$py-nosetest.xml \
--cover-xml \
--cover-xml-file=$WORKSPACE/build-python/$py-coverage.xml \
| tee $WORKSPACE/build-python/$py-coverage.log
for py in py27 py35 py36; do
tox -e $py -- --cache-clear \
--junitxml=$WORKSPACE/build-python/$py-junit.xml \
--cov-report=xml:$WORKSPACE/build-python/$py-coverage.xml \
| tee $WORKSPACE/build-python/$py.log
done
Expand Down Expand Up @@ -333,7 +329,7 @@
artifacts: 'build-python/*.xml'
fingerprint: true
- junit:
results: build-python/*-nosetest.xml
results: build-python/*-junit.xml
test-stability: true
- cobertura:
report-file: build-python/*-coverage.xml
Expand Down
31 changes: 15 additions & 16 deletions tools/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,29 @@
# Tox configuration file

[tox]
envlist = flake8,pylint,test,coverage
envlist = py27, py35, py36
skipsdist = True

[flake8]
exclude = .git,.tox,*lib/python*
exclude = .git,.tox,.eggs,*lib/python*,venv*,.venv*

[tox:jenkins]
toxworkdir = {toxinidir}/../../tox

[pytest]
python_files = *.py

[testenv]
basepython = python3.6
deps =
pyserial
pywws
flake8: flake8
pylint: pylint
{pylint,test,coverage}: nose
coverage: coverage
sources = weather_station.py
package = weather_station
pywws<=18.4.1
pytest-cov
pytest-flake8
pytest-pylint
commands =
flake8: flake8
pylint: pylint --rcfile=pylintrc.ini {[testenv]sources}
test: nosetests --nocapture {[testenv]sources} []

# Can't break line: https://bitbucket.org/hpk42/tox/issues/213/multi-line-factor-specification-in
coverage: nosetests --with-coverage --cover-erase --cover-tests --cover-branches --nocapture --cover-package {[testenv]package} {[testenv]sources} []
pytest --flake8 --pylint --pylint-rcfile=.pylintrc \
--junitxml=junit-{envname}.xml \
--cov-config=.coveragerc --cov=weather_station \
--cov-report=term-missing --cov-report=html \
--cov-fail-under=100 \
{posargs}
36 changes: 18 additions & 18 deletions tools/weather_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import time
import threading

from nose.tools import eq_

import pywws.conversions
import serial

Expand Down Expand Up @@ -138,6 +136,7 @@ def receive(self):


class RoomMapping(object):
# pylint: disable=bad-option-value,useless-object-inheritance
""" Maps a sensor to a room based on a mapping string
e.g. 'study:*, garden:rf433_1' """
Expand Down Expand Up @@ -169,38 +168,39 @@ def get_room_mapping(self, sensor):
def test_room_mapping():
""" Tests mapping prefixes """
mapping = RoomMapping('')
eq_(mapping.get_mapping_table(), [(re.compile('^.*$'), '')])
eq_(mapping.get_room_mapping('anysensor'), '')
assert mapping.get_mapping_table() == [(re.compile('^.*$'), '')]
assert mapping.get_room_mapping('anysensor') == ''

mapping = RoomMapping('study')
eq_(mapping.get_mapping_table(), [(re.compile('^.*$'), 'study')])
eq_(mapping.get_room_mapping('anysensor'), 'study')
assert mapping.get_mapping_table() == [(re.compile('^.*$'), 'study')]
assert mapping.get_room_mapping('anysensor') == 'study'

mapping = RoomMapping('study:*')
eq_(mapping.get_mapping_table(), [(re.compile('^.*$'), 'study')])
eq_(mapping.get_room_mapping('anysensor'), 'study')
assert mapping.get_mapping_table() == [(re.compile('^.*$'), 'study')]
assert mapping.get_room_mapping('anysensor') == 'study'

mapping = RoomMapping('study:*, garden:rf433*')
eq_(mapping.get_mapping_table(),
assert mapping.get_mapping_table() == \
[(re.compile('^rf433.*$'), 'garden'),
(re.compile('^.*$'), 'study')])
eq_(mapping.get_room_mapping('anysensor'), 'study')
eq_(mapping.get_room_mapping('rf433'), 'garden')
(re.compile('^.*$'), 'study')]
assert mapping.get_room_mapping('anysensor') == 'study'
assert mapping.get_room_mapping('rf433') == 'garden'

mapping = RoomMapping('garden:rf433*, study:*')
eq_(mapping.get_mapping_table(),
assert mapping.get_mapping_table() == \
[(re.compile('^.*$'), 'study'),
(re.compile('^rf433.*$'), 'garden')])
eq_(mapping.get_room_mapping('anysensor'), 'study')
eq_(mapping.get_room_mapping('rf433'), 'study')
(re.compile('^rf433.*$'), 'garden')]
assert mapping.get_room_mapping('anysensor') == 'study'
assert mapping.get_room_mapping('rf433') == 'study'

mapping = RoomMapping('study:*, garden:rf433*:incorrect')
eq_(mapping.get_mapping_table(),
assert mapping.get_mapping_table() == \
[(re.compile('^rf433.*:incorrect$'), 'garden'),
(re.compile('^.*$'), 'study')])
(re.compile('^.*$'), 'study')]


class CommandLineClient(object): # pragma: no cover
# pylint: disable=bad-option-value,useless-object-inheritance
""" Command line client """

@classmethod
Expand Down

0 comments on commit 3c81257

Please sign in to comment.