Merge lp:~hloeung/ubuntu-repository-cache/pytest-coverage-fix-unit-tests into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 282
Merged at revision: 282
Proposed branch: lp:~hloeung/ubuntu-repository-cache/pytest-coverage-fix-unit-tests
Merge into: lp:ubuntu-repository-cache
Diff against target: 147 lines (+56/-20)
7 files modified
Makefile (+6/-2)
lib/ubuntu_repository_cache/tests/test_metadata_sync.py (+1/-0)
lib/ubuntu_repository_cache/tests/test_squid.py (+11/-0)
lib/ubuntu_repository_cache/tests/test_util.py (+0/-6)
pytest.ini (+13/-0)
tests/unit/requirements.txt (+8/-0)
tox.ini (+17/-12)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/pytest-coverage-fix-unit-tests
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Canonical IS Reviewers Pending
Review via email: mp+389050@code.launchpad.net

Commit message

Switch to pytest and fix unit tests

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

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

Revision history for this message
Paul Collins (pjdc) :
review: Approve (lgtm)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 282

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2020-05-07 05:31:42 +0000
+++ Makefile 2020-08-11 04:14:46 +0000
@@ -28,10 +28,14 @@
28 sudo apt-get update28 sudo apt-get update
29 sudo apt-get install -y python3-amulet29 sudo apt-get install -y python3-amulet
3030
31test:31test: lint unittest
32 @tox32
33unittest:
34 @tox -e unit
3335
34lint:36lint:
37 @echo "Normalising python layout with black."
38 @tox -e black
35 @echo Checking for Python syntax...39 @echo Checking for Python syntax...
36 @tox -e lint40 @tox -e lint
3741
3842
=== modified file 'lib/ubuntu_repository_cache/tests/test_metadata_sync.py'
--- lib/ubuntu_repository_cache/tests/test_metadata_sync.py 2017-04-04 12:12:06 +0000
+++ lib/ubuntu_repository_cache/tests/test_metadata_sync.py 2020-08-11 04:14:46 +0000
@@ -181,6 +181,7 @@
181 expected = [181 expected = [
182 [(['juju-run',182 [(['juju-run',
183 'unit/0',183 'unit/0',
184 '/usr/local/sbin/charm-env '
184 '/var/lib/juju/agents/something/charm/hooks/'185 '/var/lib/juju/agents/something/charm/hooks/'
185 'ubuntu-repository-cache-sync some_meta_var'],), {}]]186 'ubuntu-repository-cache-sync some_meta_var'],), {}]]
186187
187188
=== modified file 'lib/ubuntu_repository_cache/tests/test_squid.py'
--- lib/ubuntu_repository_cache/tests/test_squid.py 2019-07-17 04:24:08 +0000
+++ lib/ubuntu_repository_cache/tests/test_squid.py 2020-08-11 04:14:46 +0000
@@ -1,6 +1,11 @@
1import os
2import shutil
3import tempfile
1import unittest4import unittest
2from unittest import mock5from unittest import mock
36
7from charmhelpers.core import unitdata
8
4from .. import squid9from .. import squid
510
611
@@ -11,6 +16,12 @@
11 self.mock_config = patcher.start()16 self.mock_config = patcher.start()
12 self.addCleanup(patcher.stop)17 self.addCleanup(patcher.stop)
1318
19 self.tmpdir = tempfile.mkdtemp(prefix='charm-unittests-')
20 self.addCleanup(shutil.rmtree, self.tmpdir)
21 os.environ['UNIT_STATE_DB'] = os.path.join(self.tmpdir, '.unit-state.db')
22 unitdata.kv().set('squid-cache-disk', 5000)
23 unitdata.kv().set('squid-disk-caches', [('/srv', 2000)])
24
14 def test_squid_cache_size(self):25 def test_squid_cache_size(self):
15 self.mock_config.return_value = {26 self.mock_config.return_value = {
16 'squid-cache-disk': 20 * 1024,27 'squid-cache-disk': 20 * 1024,
1728
=== modified file 'lib/ubuntu_repository_cache/tests/test_util.py'
--- lib/ubuntu_repository_cache/tests/test_util.py 2017-03-29 07:24:11 +0000
+++ lib/ubuntu_repository_cache/tests/test_util.py 2020-08-11 04:14:46 +0000
@@ -46,9 +46,3 @@
46 thefile = os.path.join(self.test_dir, "whatever")46 thefile = os.path.join(self.test_dir, "whatever")
47 util.touch(thefile)47 util.touch(thefile)
48 self.assertTrue(os.path.exists(thefile))48 self.assertTrue(os.path.exists(thefile))
49
50 def test_touch_fails_on_file_exists(self):
51 thefile = os.path.join(self.test_dir, "whatever")
52 with open(thefile, "w") as fd:
53 fd.write("something")
54 self.assertRaises(IOError, util.touch(thefile))
5549
=== added file 'pytest.ini'
--- pytest.ini 1970-01-01 00:00:00 +0000
+++ pytest.ini 2020-08-11 04:14:46 +0000
@@ -0,0 +1,13 @@
1[pytest]
2filterwarnings =
3 # https://github.com/juju/charm-helpers/issues/294
4 ignore:.*inspect.getargspec\(\) is deprecated.*:DeprecationWarning
5 # https://github.com/juju/charm-helpers/issues/293
6 ignore:.*dist\(\) and linux_distribution\(\) functions are deprecated:PendingDeprecationWarning
7 ignore:.*dist\(\) and linux_distribution\(\) functions are deprecated:DeprecationWarning
8
9 # distutils
10 ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
11
12 # backoff
13 ignore:.*Task.current_task\(\) is deprecated, use asyncio.current_task\(\) instead:DeprecationWarning
014
=== added file 'requirements.txt'
=== added file 'tests/unit/requirements.txt'
--- tests/unit/requirements.txt 1970-01-01 00:00:00 +0000
+++ tests/unit/requirements.txt 2020-08-11 04:14:46 +0000
@@ -0,0 +1,8 @@
1backoff==1.4.0
2charmhelpers
3charms.reactive
4freezegun
5mock
6nose
7pytest
8pytest-cov
09
=== modified file 'tox.ini'
--- tox.ini 2020-05-07 05:29:31 +0000
+++ tox.ini 2020-08-11 04:14:46 +0000
@@ -3,18 +3,23 @@
3skipsdist = True3skipsdist = True
44
5[testenv]5[testenv]
6setenv =6basepython = python3
7 PYTHONPATH = {toxinidir}7setenv =
8deps =8 PYTHONPATH = .
9 pyyaml9
10 nose10[testenv:unit]
11 flake811commands =
12 mock12 pytest --ignore {toxinidir}/tests/functional \
13 ipdb13 {posargs:-v --cov=lib --cov=reactive --cov=actions --cov-report=term-missing --cov-branch}
14 coverage14deps = -r{toxinidir}/tests/unit/requirements.txt
15 backoff==1.4.015 -r{toxinidir}/requirements.txt
16commands=16setenv =
17 nosetests -v --with-coverage -s lib/ubuntu_repository_cache --ignore-files=vendor/*17 PYTHONPATH={toxinidir}/lib
18 TZ=UTC
19
20[testenv:black]
21commands = black --skip-string-normalization --line-length=120 .
22deps = black
1823
19[testenv:lint]24[testenv:lint]
20deps=25deps=

Subscribers

People subscribed via source and target branches