Merge ~hloeung/ntp-charm:master into ntp-charm:master

Proposed by Haw Loeung on 2019-08-01
Status: Merged
Approved by: Haw Loeung on 2019-08-02
Approved revision: 603452e172b89858355edb5719a59acf9e222a3b
Merged at revision: 43f8719cc2f8a8500c00c2d517a45bb019771cf8
Proposed branch: ~hloeung/ntp-charm:master
Merge into: ntp-charm:master
Diff against target: 205 lines (+82/-19)
8 files modified
.gitignore (+8/-1)
Makefile (+14/-4)
pytest.ini (+10/-0)
requirements.txt (+1/-0)
tox.ini (+29/-0)
unit_tests/requirements.txt (+6/-0)
unit_tests/test_ntp_scoring.py (+1/-1)
unit_tests/test_ntp_source_score.py (+13/-13)
Reviewer Review Type Date Requested Status
Stuart Bishop 2019-08-01 Approve on 2019-08-02
Canonical IS Reviewers 2019-08-01 Pending
Review via email: mp+370890@code.launchpad.net

Commit message

Use tox for lint and unit test

To post a comment you must log in.

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Stuart Bishop (stub) wrote :

Yup

review: Approve

Change successfully merged at revision 43f8719cc2f8a8500c00c2d517a45bb019771cf8

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index bee8a64..cdd3989 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1 +1,8 @@
6-__pycache__
7+*.pyc
8+*.swp
9+*~
10+.coverage
11+.tox/
12+.unit-state.db
13+__pycache__/
14+
15diff --git a/Makefile b/Makefile
16index 3f560da..67cab7d 100644
17--- a/Makefile
18+++ b/Makefile
19@@ -6,11 +6,21 @@ CHARM_NAME := ntp
20 CS_CHANNEL := candidate
21 CSDEST := cs:~$(TEAM)/$(CHARM_NAME)
22
23-test:
24- $(PYTHON) -m unittest unit_tests/test_*.py
25+clean:
26+ @echo "Cleaning files"
27+ @rm -rf ./.tox
28+ @rm -rf ./.pytest_cache
29+ @rm -rf ./unit_tests/__pycache__ ./reactive/__pycache__ ./lib/__pycache__ ./actions/__pycache__
30+ @rm -rf ./.coverage ./.unit-state.db
31
32-lint: test
33- @python3 -m flake8 --max-line-length=120 actions lib reactive
34+test: unittest
35+
36+unittest:
37+ @tox -e unit
38+
39+lint:
40+ @echo "Running flake8"
41+ @tox -e lint
42
43 build: lint
44 charm build
45diff --git a/pytest.ini b/pytest.ini
46new file mode 100644
47index 0000000..4b4e9c5
48--- /dev/null
49+++ b/pytest.ini
50@@ -0,0 +1,10 @@
51+[pytest]
52+filterwarnings =
53+ # https://github.com/juju/charm-helpers/issues/294
54+ ignore:.*inspect.getargspec\(\) is deprecated.*:DeprecationWarning
55+ # https://github.com/juju/charm-helpers/issues/293
56+ ignore:.*dist\(\) and linux_distribution\(\) functions are deprecated:PendingDeprecationWarning
57+ ignore:.*dist\(\) and linux_distribution\(\) functions are deprecated:DeprecationWarning
58+
59+ # distutils
60+ ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
61diff --git a/requirements.txt b/requirements.txt
62new file mode 100644
63index 0000000..8462291
64--- /dev/null
65+++ b/requirements.txt
66@@ -0,0 +1 @@
67+# Include python requirements here
68diff --git a/tox.ini b/tox.ini
69new file mode 100644
70index 0000000..337da3d
71--- /dev/null
72+++ b/tox.ini
73@@ -0,0 +1,29 @@
74+[tox]
75+skipsdist=True
76+envlist = unit
77+skip_missing_interpreters = True
78+
79+[testenv]
80+basepython = python3
81+setenv =
82+ PYTHONPATH = .
83+
84+[testenv:unit]
85+commands = pytest -v --ignore {toxinidir}/tests --cov=lib --cov=reactive --cov=actions --cov-report=term-missing --cov-branch
86+deps = -r{toxinidir}/unit_tests/requirements.txt
87+ -r{toxinidir}/requirements.txt
88+setenv =
89+ PYTHONPATH={toxinidir}/lib
90+ TZ=UTC
91+
92+[testenv:lint]
93+commands = flake8
94+deps = flake8
95+
96+[flake8]
97+exclude =
98+ .git,
99+ __pycache__,
100+ .tox,
101+max-line-length = 120
102+max-complexity = 11
103diff --git a/unit_tests/requirements.txt b/unit_tests/requirements.txt
104new file mode 100644
105index 0000000..79c71e5
106--- /dev/null
107+++ b/unit_tests/requirements.txt
108@@ -0,0 +1,6 @@
109+charmhelpers
110+charms.reactive
111+mock
112+psutil
113+pytest
114+pytest-cov
115diff --git a/unit_tests/test_ntp_scoring.py b/unit_tests/test_ntp_scoring.py
116index dd704d3..39837b7 100644
117--- a/unit_tests/test_ntp_scoring.py
118+++ b/unit_tests/test_ntp_scoring.py
119@@ -6,7 +6,7 @@ import sys
120 import unittest
121
122 sys.path.append('lib')
123-import ntp_scoring
124+import ntp_scoring # NOQA: E402
125
126
127 class TestNtpScoring(unittest.TestCase):
128diff --git a/unit_tests/test_ntp_source_score.py b/unit_tests/test_ntp_source_score.py
129index 9804955..f38280a 100644
130--- a/unit_tests/test_ntp_source_score.py
131+++ b/unit_tests/test_ntp_source_score.py
132@@ -11,15 +11,15 @@ from ntp_source_score import (
133 get_source_delays,
134 rms,
135 run_cmd,
136-)
137+) # NOQA: E402
138
139 ntpdate_output = """
140 ...
141 reference time: dda179ee.3ec34fdd Mon, Oct 30 2017 20:14:06.245
142 originate timestamp: dda17a5b.af7c528b Mon, Oct 30 2017 20:15:55.685
143 transmit timestamp: dda17a5b.80b4dc04 Mon, Oct 30 2017 20:15:55.502
144-filter delay: 0.54126 0.36757 0.36655 0.36743
145- 0.00000 0.00000 0.00000 0.00000
146+filter delay: 0.54126 0.36757 0.36655 0.36743
147+ 0.00000 0.00000 0.00000 0.00000
148 filter offset: 0.099523 0.012978 0.011831 0.011770
149 0.000000 0.000000 0.000000 0.000000
150 delay 0.36655, dispersion 0.01126
151@@ -28,8 +28,8 @@ offset 0.011831
152 reference time: dda17695.69e65b2f Mon, Oct 30 2017 19:59:49.413
153 originate timestamp: dda17a5b.afcec2dd Mon, Oct 30 2017 20:15:55.686
154 transmit timestamp: dda17a5b.80bb2488 Mon, Oct 30 2017 20:15:55.502
155-filter delay: 0.36520 0.36487 0.36647 0.36604
156- 0.00000 0.00000 0.00000 0.00000
157+filter delay: 0.36520 0.36487 0.36647 0.36604
158+ 0.00000 0.00000 0.00000 0.00000
159 filter offset: 0.012833 0.013758 0.013731 0.013629
160 0.000000 0.000000 0.000000 0.000000
161 delay 0.36487, dispersion 0.00049
162@@ -38,8 +38,8 @@ offset 0.013758
163 reference time: dda1782c.6aec9646 Mon, Oct 30 2017 20:06:36.417
164 originate timestamp: dda17a5b.d2d04ef4 Mon, Oct 30 2017 20:15:55.823
165 transmit timestamp: dda17a5b.b37c4098 Mon, Oct 30 2017 20:15:55.701
166-filter delay: 0.28581 0.28406 0.28551 0.28596
167- 0.00000 0.00000 0.00000 0.00000
168+filter delay: 0.28581 0.28406 0.28551 0.28596
169+ 0.00000 0.00000 0.00000 0.00000
170 filter offset: -0.00802 -0.00854 -0.00791 -0.00787
171 0.000000 0.000000 0.000000 0.000000
172 delay 0.28406, dispersion 0.00050
173@@ -48,8 +48,8 @@ offset -0.008544
174 reference time: dda17735.4a03e3ca Mon, Oct 30 2017 20:02:29.289
175 originate timestamp: dda17a5c.1634d231 Mon, Oct 30 2017 20:15:56.086
176 transmit timestamp: dda17a5b.e6934fad Mon, Oct 30 2017 20:15:55.900
177-filter delay: 0.37044 0.37077 0.37050 0.37086
178- 0.00000 0.00000 0.00000 0.00000
179+filter delay: 0.37044 0.37077 0.37050 0.37086
180+ 0.00000 0.00000 0.00000 0.00000
181 filter offset: 0.013993 0.013624 0.013425 0.013362
182 0.000000 0.000000 0.000000 0.000000
183 delay 0.37044, dispersion 0.00046
184@@ -58,8 +58,8 @@ offset 0.013993
185 reference time: dda17695.69e65b2f Mon, Oct 30 2017 19:59:49.413
186 originate timestamp: dda17a5c.4944bb52 Mon, Oct 30 2017 20:15:56.286
187 transmit timestamp: dda17a5c.19cf5199 Mon, Oct 30 2017 20:15:56.100
188-filter delay: 0.36873 0.36823 0.36911 0.36781
189- 0.00000 0.00000 0.00000 0.00000
190+filter delay: 0.36873 0.36823 0.36911 0.36781
191+ 0.00000 0.00000 0.00000 0.00000
192 filter offset: 0.014635 0.014599 0.014166 0.014239
193 0.000000 0.000000 0.000000 0.000000
194 delay 0.36781, dispersion 0.00026
195@@ -68,8 +68,8 @@ offset 0.014239
196 reference time: dda179ee.3ec34fdd Mon, Oct 30 2017 20:14:06.245
197 originate timestamp: dda17a5c.7bbd3828 Mon, Oct 30 2017 20:15:56.483
198 transmit timestamp: dda17a5c.4cf92e99 Mon, Oct 30 2017 20:15:56.300
199-filter delay: 0.36554 0.36617 0.36673 0.36618
200- 0.00000 0.00000 0.00000 0.00000
201+filter delay: 0.36554 0.36617 0.36673 0.36618
202+ 0.00000 0.00000 0.00000 0.00000
203 filter offset: 0.012466 0.012691 0.012863 0.012346
204 0.000000 0.000000 0.000000 0.000000
205 delay 0.36554, dispersion 0.00018

Subscribers

People subscribed via source and target branches