Skip to content

Commit 3c81257

Browse files
committed
tools: Switch from nose to pytest
1 parent 97d6048 commit 3c81257

7 files changed

+95
-52
lines changed

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ deploy:production:
9393
name: $CI_PROJECT_NAME - Production
9494

9595
tools:
96-
image: python:3-alpine
96+
image: python:3.6
9797
variables:
9898
GIT_SUBMODULE_STRATEGY: none
9999
before_script:

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ jobs:
4141
- language: python
4242
python: 3.6
4343
install: pip install tox
44-
script: cd tools && tox
44+
script: cd tools && tox -e py36

tools/.gitignore

+54-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,58 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
13
*.py[cod]
2-
__pycache__
34

4-
.tox
5+
# C extensions
6+
*.so
57

6-
.coverage
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
bin/
12+
build/
13+
develop-eggs/
14+
dist/
15+
eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
AUTHORS
25+
ChangeLog
26+
27+
# Installer logs
28+
pip-log.txt
29+
pip-delete-this-directory.txt
30+
31+
# Unit test / coverage reports
732
cover/
33+
htmlcov/
34+
.tox/
35+
.coverage
36+
.cache
37+
.pytest_cache/
38+
nosetests.xml
39+
coverage.xml
40+
junit-*.xml
41+
42+
# Translations
43+
*.mo
44+
45+
# Mr Developer
46+
.mr.developer.cfg
47+
.project
48+
.pydevproject
49+
50+
# Rope
51+
.ropeproject
52+
53+
# Django stuff:
54+
*.log
55+
*.pot
56+
57+
# Sphinx documentation
58+
docs/_build/

tools/pylintrc.ini tools/.pylintrc

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
[REPORTS]
22
msg-template="{abspath}:{line}: [{msg_id}({symbol}), {obj}] {msg}"
3-
4-
[MESSAGE CONTROL]
5-
disable=locally-disabled

tools/jenkins.yaml

+6-10
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,11 @@
255255
mkdir $WORKSPACE/build-python
256256
cd $WORKSPACE/sources/tools
257257
258-
for py in py2 py3; do
259-
tox -e $py-flake8 | tee $WORKSPACE/build-python/$py-flake8.log
260-
tox -e $py-pylint | tee $WORKSPACE/build-python/$py-pylint.log
261-
tox -e $py-coverage -- \
262-
--with-xunit \
263-
--xunit-file=$WORKSPACE/build-python/$py-nosetest.xml \
264-
--cover-xml \
265-
--cover-xml-file=$WORKSPACE/build-python/$py-coverage.xml \
266-
| tee $WORKSPACE/build-python/$py-coverage.log
258+
for py in py27 py35 py36; do
259+
tox -e $py -- --cache-clear \
260+
--junitxml=$WORKSPACE/build-python/$py-junit.xml \
261+
--cov-report=xml:$WORKSPACE/build-python/$py-coverage.xml \
262+
| tee $WORKSPACE/build-python/$py.log
267263
done
268264
269265
@@ -333,7 +329,7 @@
333329
artifacts: 'build-python/*.xml'
334330
fingerprint: true
335331
- junit:
336-
results: build-python/*-nosetest.xml
332+
results: build-python/*-junit.xml
337333
test-stability: true
338334
- cobertura:
339335
report-file: build-python/*-coverage.xml

tools/tox.ini

+15-16
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,29 @@
1818
# Tox configuration file
1919

2020
[tox]
21-
envlist = flake8,pylint,test,coverage
21+
envlist = py27, py35, py36
2222
skipsdist = True
2323

2424
[flake8]
25-
exclude = .git,.tox,*lib/python*
25+
exclude = .git,.tox,.eggs,*lib/python*,venv*,.venv*
2626

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

30+
[pytest]
31+
python_files = *.py
32+
3033
[testenv]
31-
basepython = python3.6
3234
deps =
3335
pyserial
34-
pywws
35-
flake8: flake8
36-
pylint: pylint
37-
{pylint,test,coverage}: nose
38-
coverage: coverage
39-
sources = weather_station.py
40-
package = weather_station
36+
pywws<=18.4.1
37+
pytest-cov
38+
pytest-flake8
39+
pytest-pylint
4140
commands =
42-
flake8: flake8
43-
pylint: pylint --rcfile=pylintrc.ini {[testenv]sources}
44-
test: nosetests --nocapture {[testenv]sources} []
45-
46-
# Can't break line: https://bitbucket.org/hpk42/tox/issues/213/multi-line-factor-specification-in
47-
coverage: nosetests --with-coverage --cover-erase --cover-tests --cover-branches --nocapture --cover-package {[testenv]package} {[testenv]sources} []
41+
pytest --flake8 --pylint --pylint-rcfile=.pylintrc \
42+
--junitxml=junit-{envname}.xml \
43+
--cov-config=.coveragerc --cov=weather_station \
44+
--cov-report=term-missing --cov-report=html \
45+
--cov-fail-under=100 \
46+
{posargs}

tools/weather_station.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import time
3131
import threading
3232

33-
from nose.tools import eq_
34-
3533
import pywws.conversions
3634
import serial
3735

@@ -138,6 +136,7 @@ def receive(self):
138136

139137

140138
class RoomMapping(object):
139+
# pylint: disable=bad-option-value,useless-object-inheritance
141140
""" Maps a sensor to a room based on a mapping string
142141
143142
e.g. 'study:*, garden:rf433_1' """
@@ -169,38 +168,39 @@ def get_room_mapping(self, sensor):
169168
def test_room_mapping():
170169
""" Tests mapping prefixes """
171170
mapping = RoomMapping('')
172-
eq_(mapping.get_mapping_table(), [(re.compile('^.*$'), '')])
173-
eq_(mapping.get_room_mapping('anysensor'), '')
171+
assert mapping.get_mapping_table() == [(re.compile('^.*$'), '')]
172+
assert mapping.get_room_mapping('anysensor') == ''
174173

175174
mapping = RoomMapping('study')
176-
eq_(mapping.get_mapping_table(), [(re.compile('^.*$'), 'study')])
177-
eq_(mapping.get_room_mapping('anysensor'), 'study')
175+
assert mapping.get_mapping_table() == [(re.compile('^.*$'), 'study')]
176+
assert mapping.get_room_mapping('anysensor') == 'study'
178177

179178
mapping = RoomMapping('study:*')
180-
eq_(mapping.get_mapping_table(), [(re.compile('^.*$'), 'study')])
181-
eq_(mapping.get_room_mapping('anysensor'), 'study')
179+
assert mapping.get_mapping_table() == [(re.compile('^.*$'), 'study')]
180+
assert mapping.get_room_mapping('anysensor') == 'study'
182181

183182
mapping = RoomMapping('study:*, garden:rf433*')
184-
eq_(mapping.get_mapping_table(),
183+
assert mapping.get_mapping_table() == \
185184
[(re.compile('^rf433.*$'), 'garden'),
186-
(re.compile('^.*$'), 'study')])
187-
eq_(mapping.get_room_mapping('anysensor'), 'study')
188-
eq_(mapping.get_room_mapping('rf433'), 'garden')
185+
(re.compile('^.*$'), 'study')]
186+
assert mapping.get_room_mapping('anysensor') == 'study'
187+
assert mapping.get_room_mapping('rf433') == 'garden'
189188

190189
mapping = RoomMapping('garden:rf433*, study:*')
191-
eq_(mapping.get_mapping_table(),
190+
assert mapping.get_mapping_table() == \
192191
[(re.compile('^.*$'), 'study'),
193-
(re.compile('^rf433.*$'), 'garden')])
194-
eq_(mapping.get_room_mapping('anysensor'), 'study')
195-
eq_(mapping.get_room_mapping('rf433'), 'study')
192+
(re.compile('^rf433.*$'), 'garden')]
193+
assert mapping.get_room_mapping('anysensor') == 'study'
194+
assert mapping.get_room_mapping('rf433') == 'study'
196195

197196
mapping = RoomMapping('study:*, garden:rf433*:incorrect')
198-
eq_(mapping.get_mapping_table(),
197+
assert mapping.get_mapping_table() == \
199198
[(re.compile('^rf433.*:incorrect$'), 'garden'),
200-
(re.compile('^.*$'), 'study')])
199+
(re.compile('^.*$'), 'study')]
201200

202201

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

206206
@classmethod

0 commit comments

Comments
 (0)