Merge lp:~zyga/lava-test/fix-926867 into lp:lava-test/0.0

Proposed by Zygmunt Krynicki
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 117
Merged at revision: 112
Proposed branch: lp:~zyga/lava-test/fix-926867
Merge into: lp:lava-test/0.0
Diff against target: 223 lines (+126/-37)
7 files modified
.bzrignore (+4/-5)
.testr.conf (+0/-3)
MANIFEST.in (+0/-1)
lava_test/core/providers.py (+12/-13)
setup.py (+5/-1)
tests/__init__.py (+0/-14)
tests/test_providers.py (+105/-0)
To merge this branch: bzr merge lp:~zyga/lava-test/fix-926867
Reviewer Review Type Date Requested Status
Paul Larson (community) Approve
Review via email: mp+91689@code.launchpad.net

Description of the change

This branch fixes bug 926867 and adds a few tests to prove it

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

+1, and with tests too! \o/

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2011-09-12 09:19:10 +0000
3+++ .bzrignore 2012-02-06 17:55:20 +0000
4@@ -1,8 +1,7 @@
5+*.egg
6+*.egg-info
7+*.tmp
8 .idea
9 .testrepository
10+build
11 dist
12-lava_test.egg-info
13-*~
14-*.tmp
15-*.py[co]
16-build
17
18=== removed file '.testr.conf'
19--- .testr.conf 2010-06-14 20:32:28 +0000
20+++ .testr.conf 1970-01-01 00:00:00 +0000
21@@ -1,3 +0,0 @@
22-[DEFAULT]
23-test_command=PYTHONPATH=. python -m subunit.run $IDLIST
24-test_id_list_default=tests.test_suite
25
26=== modified file 'MANIFEST.in'
27--- MANIFEST.in 2011-09-12 09:19:10 +0000
28+++ MANIFEST.in 2012-02-06 17:55:20 +0000
29@@ -1,3 +1,2 @@
30 include COPYING
31 include README
32-include .testr.conf
33
34=== modified file 'lava_test/core/providers.py'
35--- lava_test/core/providers.py 2012-01-18 21:45:51 +0000
36+++ lava_test/core/providers.py 2012-02-06 17:55:20 +0000
37@@ -172,19 +172,18 @@
38 if test.test_id in self._cache:
39 raise ValueError("Duplicate test %s declared" % test.test_id)
40 self._cache[test.test_id] = test
41- except IOError, err:
42- logging.warning("Failed to load the " + test_url)
43- if hasattr(e, 'reason'):
44- logging.warning("WARNING: URL Reason: "+ e.reason)
45- elif hasattr(e, 'code'):
46- logging.warning('WARNING: URL Error code: ' + e.code)
47- else:
48- logging.exception("WARNING: Unknown IO error", str(err))
49- except ValueError, err:
50- logging.warning('Error found when parsing the' + test_url)
51- except Exception, err:
52- logging.warning('Failed to load the' + test_url)
53- logging.warning("Unknown exception : " + str(err))
54+ except IOError as exc:
55+ logging.warning(
56+ "Unable to load test definition from %r: %r", test_url, exc)
57+ if hasattr(exc, 'reason'):
58+ logging.warning("Error reason: %r", exc.reason)
59+ elif hasattr(exc, 'code'):
60+ logging.warning('Error code: %r', exc.code)
61+ except Exception as exc:
62+ # This can be a number of things, including URL errors, JSON
63+ # errors and validation errors
64+ logging.warning('Unable to load test definition from %r: %r',
65+ test_url, exc)
66
67 def __iter__(self):
68 self._fill_cache()
69
70=== modified file 'setup.py'
71--- setup.py 2011-09-12 09:19:10 +0000
72+++ setup.py 2012-02-06 17:55:20 +0000
73@@ -28,7 +28,7 @@
74 long_description=open("README").read(),
75 packages=find_packages(exclude=['tests']),
76 license="GNU GPLv3",
77- test_suite='tests.test_suite',
78+ test_suite='unittest2.collector',
79 entry_points="""
80 [console_scripts]
81 lava-test=lava_test.main:main
82@@ -60,5 +60,9 @@
83 setup_requires=[
84 'versiontools >= 1.4'
85 ],
86+ tests_require=[
87+ 'unittest2',
88+ 'mocker >= 1.1',
89+ ],
90 zip_safe=False,
91 include_package_data=True)
92
93=== modified file 'tests/__init__.py'
94--- tests/__init__.py 2011-09-12 09:19:10 +0000
95+++ tests/__init__.py 2012-02-06 17:55:20 +0000
96@@ -12,17 +12,3 @@
97 #
98 # You should have received a copy of the GNU General Public License
99 # along with this program. If not, see <http://www.gnu.org/licenses/>.
100-
101-import unittest
102-
103-def test_suite():
104- module_names = ['tests.test_lavatest_commands',
105- 'tests.test_lavatest_test',
106- 'tests.test_lavatest_testinstaller',
107- 'tests.test_lavatest_testparser',
108- 'tests.test_lavatest_testrunner',
109- 'tests.test_hwprofile',
110- 'tests.test_swprofile']
111- loader = unittest.TestLoader()
112- suite = loader.loadTestsFromNames(module_names)
113- return suite
114
115=== added file 'tests/test_providers.py'
116--- tests/test_providers.py 1970-01-01 00:00:00 +0000
117+++ tests/test_providers.py 2012-02-06 17:55:20 +0000
118@@ -0,0 +1,105 @@
119+# Copyright (c) 2012 Linaro Limited
120+#
121+# This program is free software: you can redistribute it and/or modify
122+# it under the terms of the GNU General Public License as published by
123+# the Free Software Foundation, either version 3 of the License, or
124+# (at your option) any later version.
125+#
126+# This program is distributed in the hope that it will be useful,
127+# but WITHOUT ANY WARRANTY; without even the implied warranty of
128+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129+# GNU General Public License for more details.
130+#
131+# You should have received a copy of the GNU General Public License
132+# along with this program. If not, see <http://www.gnu.org/licenses/>.
133+
134+from mocker import MockerTestCase
135+
136+from lava_test.core.providers import RegistryProvider
137+
138+
139+class RegistryProviderTests(MockerTestCase):
140+
141+ # Helper values used in test methods
142+ _code = 1
143+ _reason = "reason"
144+ _test_id = 'test1'
145+ _test_id_list = ['test1', 'test2']
146+ _url = "http://example.org/test.json"
147+
148+ def _prepare_provider_that_crashes_with_error(self, error):
149+ self.provider = self.mocker.patch(
150+ RegistryProvider({'entries': [self._url]}))
151+ self.expect(self.provider._fill_cache()).passthrough()
152+ self.expect(self.provider._load_remote_test(self._url)).throw(error)
153+
154+ def _test_fill_cache_response(self):
155+ # Now onto testing:
156+ self.mocker.replay()
157+ # Call _fill_cache()
158+ self.provider._fill_cache()
159+ # the actual tests are validated as mocker expectation
160+
161+ def test_fill_cache_IOError_handling_with_just_reason(self):
162+ # We want to test resilience to IOError that has a 'reason' attribute
163+ error = IOError()
164+ error.reason = self._reason
165+ self._prepare_provider_that_crashes_with_error(error)
166+ # Now this ought to log a few warning messages
167+ logging = self.mocker.replace("logging", passthrough=False)
168+ logging.warning(
169+ "Unable to load test definition from %r: %r",
170+ self._url, error)
171+ logging.warning("Error reason: %r", self._reason)
172+ self._test_fill_cache_response()
173+
174+ def test_fill_cache_IOError_handling_with_just_code(self):
175+ # We want to test resilience to IOError that has a 'code' attribute
176+ error = IOError()
177+ error.code = self._code
178+ provider = self._prepare_provider_that_crashes_with_error(error)
179+ # Now this ought to log a few warning messages
180+ logging = self.mocker.replace("logging", passthrough=False)
181+ logging.warning(
182+ "Unable to load test definition from %r: %r",
183+ self._url, error)
184+ logging.warning("Error code: %r", self._code)
185+ self._test_fill_cache_response()
186+
187+ def test_fill_cache_IOError_handling_without_anything(self):
188+ # We want to test resilience to IOError that has no attributes
189+ error = IOError()
190+ provider = self._prepare_provider_that_crashes_with_error(error)
191+ # Now this ought to log a few warning messages
192+ logging = self.mocker.replace("logging", passthrough=False)
193+ logging.warning(
194+ "Unable to load test definition from %r: %r",
195+ self._url, error)
196+ self._test_fill_cache_response()
197+
198+ def test_fill_cache_ValueError_handling(self):
199+ # We want to test resilience to ValueError
200+ error = ValueError()
201+ provider = self._prepare_provider_that_crashes_with_error(error)
202+ # Now this ought to log a few warning messages
203+ logging = self.mocker.replace("logging", passthrough=False)
204+ logging.warning(
205+ "Unable to load test definition from %r: %r",
206+ self._url, error)
207+ self._test_fill_cache_response()
208+
209+ def test_iter_calls_fill_cache(self):
210+ provider = self.mocker.patch(RegistryProvider({}))
211+ self.expect(iter(provider)).passthrough()
212+ self.expect(provider._fill_cache())
213+ self.expect(provider._cache.iterkeys()).generate(self._test_id_list)
214+ self.mocker.replay()
215+ self.assertSequenceEqual(list(provider), self._test_id_list)
216+
217+ def test_getitem_calls_fill_cache(self):
218+ provider = self.mocker.patch(RegistryProvider({}))
219+ self.expect(provider[self._test_id]).passthrough()
220+ self.expect(provider._fill_cache())
221+ self.expect(provider._cache[self._test_id])
222+ self.mocker.replay()
223+ provider[self._test_id]

Subscribers

People subscribed via source and target branches