Merge ~jslarraz/review-tools:work-on-test-cases into review-tools:master
- Git
- lp:~jslarraz/review-tools
- work-on-test-cases
- Merge into master
Proposed by
Jorge Sancho Larraz
Status: | Merged |
---|---|
Merged at revision: | 2979f040fdce69a935de810afca9430afae3a89c |
Proposed branch: | ~jslarraz/review-tools:work-on-test-cases |
Merge into: | review-tools:master |
Diff against target: |
491 lines (+128/-167) 4 files modified
reviewtools/containers/base_container.py (+12/-3) reviewtools/containers/squashfs_container.py (+0/-11) reviewtools/tests/containers/test_base_container.py (+97/-120) reviewtools/tests/containers/test_squashfs_container.py (+19/-33) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alex Murray | Needs Fixing | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jorge Sancho Larraz (jslarraz) wrote (last edit ): | # |
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Alex Murray (alexmurray) wrote : | # |
LGTM except one minor change needed to the comment in base_container.py
review:
Needs Fixing
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/reviewtools/containers/base_container.py b/reviewtools/containers/base_container.py | |||
2 | index 3c4555f..0759469 100644 | |||
3 | --- a/reviewtools/containers/base_container.py | |||
4 | +++ b/reviewtools/containers/base_container.py | |||
5 | @@ -90,6 +90,9 @@ class BaseContainer: | |||
6 | 90 | # Check max/min size if defined | 90 | # Check max/min size if defined |
7 | 91 | self.check_container_size() | 91 | self.check_container_size() |
8 | 92 | 92 | ||
9 | 93 | # Check container has the expected format | ||
10 | 94 | self.check_container_format() | ||
11 | 95 | |||
12 | 93 | @property | 96 | @property |
13 | 94 | def unpack_dir(self) -> str: | 97 | def unpack_dir(self) -> str: |
14 | 95 | """ | 98 | """ |
15 | @@ -143,7 +146,9 @@ class BaseContainer: | |||
16 | 143 | format is specific to the container type. This method needs to be | 146 | format is specific to the container type. This method needs to be |
17 | 144 | implemented by the specific subclasses. | 147 | implemented by the specific subclasses. |
18 | 145 | """ | 148 | """ |
20 | 146 | raise NotImplementedError("Must be implemented by subclasses") | 149 | raise NotImplementedError( |
21 | 150 | "Must be implemented by subclasses" | ||
22 | 151 | ) # pragma: no cover | ||
23 | 147 | 152 | ||
24 | 148 | def get_container_size(self) -> int: | 153 | def get_container_size(self) -> int: |
25 | 149 | """ | 154 | """ |
26 | @@ -188,7 +193,9 @@ class BaseContainer: | |||
27 | 188 | estimation method is specific to the container type. This method | 193 | estimation method is specific to the container type. This method |
28 | 189 | needs to be implemented by the specific subclasses. | 194 | needs to be implemented by the specific subclasses. |
29 | 190 | """ | 195 | """ |
31 | 191 | raise NotImplementedError("Must be implemented by subclasses") | 196 | raise NotImplementedError( |
32 | 197 | "Must be implemented by subclasses" | ||
33 | 198 | ) # pragma: no cover | ||
34 | 192 | 199 | ||
35 | 193 | def check_unpacked_size(self): | 200 | def check_unpacked_size(self): |
36 | 194 | """ | 201 | """ |
37 | @@ -243,7 +250,9 @@ class BaseContainer: | |||
38 | 243 | estimation method is specific to the container type. This method | 250 | estimation method is specific to the container type. This method |
39 | 244 | needs to be implemented by the specific subclasses. | 251 | needs to be implemented by the specific subclasses. |
40 | 245 | """ | 252 | """ |
42 | 246 | raise NotImplementedError("Must be implemented by subclasses") | 253 | raise NotImplementedError( |
43 | 254 | "Must be implemented by subclasses" | ||
44 | 255 | ) # pragma: no cover | ||
45 | 247 | 256 | ||
46 | 248 | def get_file(self, fn: str) -> bytes: | 257 | def get_file(self, fn: str) -> bytes: |
47 | 249 | """ | 258 | """ |
48 | diff --git a/reviewtools/containers/squashfs_container.py b/reviewtools/containers/squashfs_container.py | |||
49 | index 631fe76..4896bbb 100644 | |||
50 | --- a/reviewtools/containers/squashfs_container.py | |||
51 | +++ b/reviewtools/containers/squashfs_container.py | |||
52 | @@ -10,17 +10,6 @@ class SquashfsContainer(BaseContainer): | |||
53 | 10 | BaseContainer to handle functionality that is specific to Squashfs containers. | 10 | BaseContainer to handle functionality that is specific to Squashfs containers. |
54 | 11 | """ | 11 | """ |
55 | 12 | 12 | ||
56 | 13 | def __init__(self, fn): | ||
57 | 14 | """ | ||
58 | 15 | If SquashfsContainer is initialized with a container file, it will also | ||
59 | 16 | verify that the provided file is actually a squashfs, in addition to the | ||
60 | 17 | checks performed by the BaseContainer. | ||
61 | 18 | """ | ||
62 | 19 | super().__init__(fn) | ||
63 | 20 | |||
64 | 21 | # Check is squash file | ||
65 | 22 | self.check_container_format() | ||
66 | 23 | |||
67 | 24 | def check_container_format(self): | 13 | def check_container_format(self): |
68 | 25 | """ | 14 | """ |
69 | 26 | Checks that the container file has the expected format. | 15 | Checks that the container file has the expected format. |
70 | diff --git a/reviewtools/tests/containers/test_base_container.py b/reviewtools/tests/containers/test_base_container.py | |||
71 | index 277be8f..d4e0726 100644 | |||
72 | --- a/reviewtools/tests/containers/test_base_container.py | |||
73 | +++ b/reviewtools/tests/containers/test_base_container.py | |||
74 | @@ -1,10 +1,19 @@ | |||
75 | 1 | import os | 1 | import os |
76 | 2 | import shutil | 2 | import shutil |
77 | 3 | import unittest | 3 | import unittest |
79 | 4 | from tempfile import mkdtemp | 4 | from unittest.mock import patch |
80 | 5 | from tempfile import mkdtemp, mkstemp | ||
81 | 5 | from reviewtools.containers.base_container import BaseContainer, ContainerException | 6 | from reviewtools.containers.base_container import BaseContainer, ContainerException |
82 | 6 | 7 | ||
83 | 7 | 8 | ||
84 | 9 | def _mock_check_container_format(self): | ||
85 | 10 | return True | ||
86 | 11 | |||
87 | 12 | |||
88 | 13 | def _mock_calculate_unpacked_size(self): | ||
89 | 14 | return 10**3 | ||
90 | 15 | |||
91 | 16 | |||
92 | 8 | class TestBaseContainer(unittest.TestCase): | 17 | class TestBaseContainer(unittest.TestCase): |
93 | 9 | """Tests for reviewtools.containers.base_container.BaseContainer""" | 18 | """Tests for reviewtools.containers.base_container.BaseContainer""" |
94 | 10 | 19 | ||
95 | @@ -17,11 +26,33 @@ class TestBaseContainer(unittest.TestCase): | |||
96 | 17 | cls.fn = cls._create_container(cls) | 26 | cls.fn = cls._create_container(cls) |
97 | 18 | cls.unpack_dir = cls._create_unpackdir(cls) | 27 | cls.unpack_dir = cls._create_unpackdir(cls) |
98 | 19 | 28 | ||
99 | 29 | # Mock required classes | ||
100 | 30 | cls.patches = [ | ||
101 | 31 | unittest.mock.patch( | ||
102 | 32 | "reviewtools.tests.containers.test_base_container.BaseContainer.check_container_format", | ||
103 | 33 | _mock_check_container_format, | ||
104 | 34 | ), | ||
105 | 35 | unittest.mock.patch( | ||
106 | 36 | "reviewtools.tests.containers.test_base_container.BaseContainer.calculate_unpacked_size", | ||
107 | 37 | _mock_calculate_unpacked_size, | ||
108 | 38 | ), | ||
109 | 39 | unittest.mock.patch( | ||
110 | 40 | "reviewtools.tests.containers.test_base_container.BaseContainer._unpack_dir", | ||
111 | 41 | cls.unpack_dir, | ||
112 | 42 | ), | ||
113 | 43 | ] | ||
114 | 44 | for patch in cls.patches: | ||
115 | 45 | patch.start() | ||
116 | 46 | |||
117 | 20 | @classmethod | 47 | @classmethod |
118 | 21 | def tearDownClass(cls): | 48 | def tearDownClass(cls): |
119 | 22 | if os.path.exists(cls.tmp_dir): | 49 | if os.path.exists(cls.tmp_dir): |
120 | 23 | shutil.rmtree(cls.tmp_dir) | 50 | shutil.rmtree(cls.tmp_dir) |
121 | 24 | 51 | ||
122 | 52 | # Stop mocking | ||
123 | 53 | for patch in cls.patches: | ||
124 | 54 | patch.stop() | ||
125 | 55 | |||
126 | 25 | def _create_container(self, container_size: int = 10000): | 56 | def _create_container(self, container_size: int = 10000): |
127 | 26 | fn = os.path.join(self.tmp_dir, "container.test") | 57 | fn = os.path.join(self.tmp_dir, "container.test") |
128 | 27 | with open(fn, "w") as f: | 58 | with open(fn, "w") as f: |
129 | @@ -49,112 +80,89 @@ map: | |||
130 | 49 | return unpack_dir | 80 | return unpack_dir |
131 | 50 | 81 | ||
132 | 51 | # Test class initialization | 82 | # Test class initialization |
140 | 52 | def test_initialization_container__happy(self): | 83 | def test_initialization__happy(self): |
141 | 53 | try: | 84 | BaseContainer(self.fn) |
142 | 54 | BaseContainer(self.fn) | 85 | |
143 | 55 | except ContainerException: | 86 | def test_initialization__missing_extension(self): |
144 | 56 | self.fail( | 87 | fd, plain_file = mkstemp() |
145 | 57 | "An unexpected error occurred during BaseContainer initialization with container file" | 88 | with self.assertRaises(ContainerException) as context: |
146 | 58 | ) | 89 | BaseContainer(plain_file) |
147 | 90 | self.assertEqual( | ||
148 | 91 | "container filename must include an extension", context.exception.value | ||
149 | 92 | ) | ||
150 | 93 | os.unlink(plain_file) | ||
151 | 59 | 94 | ||
152 | 60 | def test_initialization__missing_file(self): | 95 | def test_initialization__missing_file(self): |
153 | 61 | with self.assertRaises(ContainerException) as context: | 96 | with self.assertRaises(ContainerException) as context: |
154 | 62 | BaseContainer("/non/existing/path") | 97 | BaseContainer("/non/existing/path") |
159 | 63 | self.assertTrue( | 98 | self.assertTrue("Could not find " in context.exception.value) |
156 | 64 | "does not exists or has incorrect permissions" | ||
157 | 65 | in context.exception.value | ||
158 | 66 | ) | ||
160 | 67 | 99 | ||
161 | 68 | # Test deletion | 100 | # Test deletion |
162 | 69 | def test_check_cleanup(self): | 101 | def test_check_cleanup(self): |
170 | 70 | try: | 102 | container = BaseContainer(self.fn) |
171 | 71 | container = BaseContainer(self.fn) | 103 | tmp_dir = container.tmp_dir |
172 | 72 | tmp_dir = container.tmp_dir | 104 | del container |
173 | 73 | del container | 105 | self.assertFalse(os.path.exists(tmp_dir)) |
167 | 74 | self.assertFalse(os.path.exists(tmp_dir)) | ||
168 | 75 | except Exception: | ||
169 | 76 | self.fail("An unexpected error occurred during deletion test") | ||
174 | 77 | 106 | ||
175 | 78 | # Test check container size | 107 | # Test check container size |
176 | 79 | def test_check_container_size__happy(self): | 108 | def test_check_container_size__happy(self): |
177 | 80 | container = BaseContainer(self.fn) | 109 | container = BaseContainer(self.fn) |
178 | 81 | container._min_packed_size = 0 | 110 | container._min_packed_size = 0 |
179 | 82 | container._max_packed_size = 10**6 | 111 | container._max_packed_size = 10**6 |
184 | 83 | try: | 112 | container.check_container_size() |
181 | 84 | container.check_container_size() | ||
182 | 85 | except ContainerException: | ||
183 | 86 | self.fail("An unexpected error occurred while checking file size") | ||
185 | 87 | 113 | ||
186 | 88 | def test_check_container_size__too_big(self): | 114 | def test_check_container_size__too_big(self): |
187 | 89 | container = BaseContainer(self.fn) | 115 | container = BaseContainer(self.fn) |
188 | 90 | container._max_packed_size = 1 | 116 | container._max_packed_size = 1 |
189 | 91 | with self.assertRaises(ContainerException) as context: | 117 | with self.assertRaises(ContainerException) as context: |
190 | 92 | container.check_container_size() | 118 | container.check_container_size() |
192 | 93 | self.assertTrue("container file is too large " in context.exception.value) | 119 | self.assertTrue("container file is too large " in context.exception.value) |
193 | 94 | 120 | ||
194 | 95 | def test_check_container_size__too_small(self): | 121 | def test_check_container_size__too_small(self): |
195 | 96 | container = BaseContainer(self.fn) | 122 | container = BaseContainer(self.fn) |
196 | 97 | container._min_packed_size = 10**6 | 123 | container._min_packed_size = 10**6 |
197 | 98 | with self.assertRaises(ContainerException) as context: | 124 | with self.assertRaises(ContainerException) as context: |
198 | 99 | container.check_container_size() | 125 | container.check_container_size() |
200 | 100 | self.assertTrue("container file is too small " in context.exception.value) | 126 | self.assertTrue("container file is too small " in context.exception.value) |
201 | 101 | 127 | ||
202 | 102 | # Test check unpacked size | 128 | # Test check unpacked size |
203 | 103 | def _mock_calculate_unpacked_size(self): | ||
204 | 104 | return 10**3 | ||
205 | 105 | |||
206 | 106 | def test_check_unpacked_size__happy(self): | 129 | def test_check_unpacked_size__happy(self): |
207 | 107 | container = BaseContainer(self.fn) | 130 | container = BaseContainer(self.fn) |
208 | 108 | container.calculate_unpacked_size = self._mock_calculate_unpacked_size | ||
209 | 109 | container._min_unpacked_size = 0 | 131 | container._min_unpacked_size = 0 |
210 | 110 | container._max_unpacked_size = 10**6 | 132 | container._max_unpacked_size = 10**6 |
215 | 111 | try: | 133 | container.check_unpacked_size() |
212 | 112 | container.check_unpacked_size() | ||
213 | 113 | except ContainerException: | ||
214 | 114 | self.fail("An unexpected error occurred while checking file size") | ||
216 | 115 | 134 | ||
217 | 116 | def test_check_unpacked_size__too_big(self): | 135 | def test_check_unpacked_size__too_big(self): |
218 | 117 | container = BaseContainer(self.fn) | 136 | container = BaseContainer(self.fn) |
219 | 118 | container.calculate_unpacked_size = self._mock_calculate_unpacked_size | ||
220 | 119 | container._max_unpacked_size = 1 | 137 | container._max_unpacked_size = 1 |
221 | 120 | with self.assertRaises(ContainerException) as context: | 138 | with self.assertRaises(ContainerException) as context: |
222 | 121 | container.check_unpacked_size() | 139 | container.check_unpacked_size() |
224 | 122 | self.assertTrue("container file is too large " in context.exception.value) | 140 | self.assertTrue("unpacked directory is too large " in context.exception.value) |
225 | 123 | 141 | ||
226 | 124 | def test_check_unpacked_size__too_small(self): | 142 | def test_check_unpacked_size__too_small(self): |
227 | 125 | container = BaseContainer(self.fn) | 143 | container = BaseContainer(self.fn) |
228 | 126 | container.calculate_unpacked_size = self._mock_calculate_unpacked_size | ||
229 | 127 | container._min_unpacked_size = 10**6 | 144 | container._min_unpacked_size = 10**6 |
230 | 128 | with self.assertRaises(ContainerException) as context: | 145 | with self.assertRaises(ContainerException) as context: |
231 | 129 | container.check_unpacked_size() | 146 | container.check_unpacked_size() |
233 | 130 | self.assertTrue("container file is too small " in context.exception.value) | 147 | self.assertTrue("unpacked directory is too small " in context.exception.value) |
234 | 131 | 148 | ||
235 | 132 | # Test get file | 149 | # Test get file |
236 | 133 | def test_get_file__happy(self): | 150 | def test_get_file__happy(self): |
244 | 134 | try: | 151 | container = BaseContainer(self.fn) |
245 | 135 | container = BaseContainer(self.fn) | 152 | snap_yaml = container.get_file("meta/icon.png") |
246 | 136 | container._unpack_dir = self.unpack_dir | 153 | self.assertEqual(snap_yaml.decode(), "Test") |
240 | 137 | snap_yaml = container.get_file("meta/icon.png") | ||
241 | 138 | self.assertEqual(snap_yaml.decode(), "Test") | ||
242 | 139 | except ContainerException: | ||
243 | 140 | self.fail("An unexpected error occurred while getting meta/icon.png") | ||
247 | 141 | 154 | ||
248 | 142 | def test_get_file__missing_file(self): | 155 | def test_get_file__missing_file(self): |
249 | 156 | container = BaseContainer(self.fn) | ||
250 | 143 | with self.assertRaises(ContainerException) as context: | 157 | with self.assertRaises(ContainerException) as context: |
251 | 144 | container = BaseContainer(self.fn) | ||
252 | 145 | container._unpack_dir = self.unpack_dir | ||
253 | 146 | container.get_file("non/existent/file") | 158 | container.get_file("non/existent/file") |
255 | 147 | self.assertTrue("Could not find" in context.exception.value) | 159 | self.assertTrue("Could not find" in context.exception.value) |
256 | 148 | 160 | ||
257 | 149 | # Test get yaml | 161 | # Test get yaml |
258 | 150 | def test_get_file_as_yaml__happy(self): | 162 | def test_get_file_as_yaml__happy(self): |
266 | 151 | try: | 163 | container = BaseContainer(self.fn) |
267 | 152 | container = BaseContainer(self.fn) | 164 | snap_yaml = container.get_file_as_yaml("meta/snap.yaml") |
268 | 153 | container._unpack_dir = self.unpack_dir | 165 | self.assertEqual(snap_yaml, {"map": {"key": "value"}}) |
262 | 154 | snap_yaml = container.get_file_as_yaml("meta/snap.yaml") | ||
263 | 155 | self.assertEqual(snap_yaml, {"map": {"key": "value"}}) | ||
264 | 156 | except ContainerException: | ||
265 | 157 | self.fail("An unexpected error occurred while getting meta/snap.yaml") | ||
269 | 158 | 166 | ||
270 | 159 | def test_get_file_as_yaml__dup_keys(self): | 167 | def test_get_file_as_yaml__dup_keys(self): |
271 | 160 | # Write the file to test | 168 | # Write the file to test |
272 | @@ -169,7 +177,6 @@ map: | |||
273 | 169 | 177 | ||
274 | 170 | with self.assertRaises(ContainerException) as context: | 178 | with self.assertRaises(ContainerException) as context: |
275 | 171 | container = BaseContainer(self.fn) | 179 | container = BaseContainer(self.fn) |
276 | 172 | container._unpack_dir = self.unpack_dir | ||
277 | 173 | container.get_file_as_yaml("test.yaml") | 180 | container.get_file_as_yaml("test.yaml") |
278 | 174 | self.assertTrue('found duplicate key "key"' in context.exception.value) | 181 | self.assertTrue('found duplicate key "key"' in context.exception.value) |
279 | 175 | 182 | ||
280 | @@ -188,7 +195,6 @@ map: | |||
281 | 188 | ) | 195 | ) |
282 | 189 | 196 | ||
283 | 190 | container = BaseContainer(self.fn) | 197 | container = BaseContainer(self.fn) |
284 | 191 | container._unpack_dir = self.unpack_dir | ||
285 | 192 | container.get_file_as_yaml("test.yaml", allow_duplicate_keys=True) | 198 | container.get_file_as_yaml("test.yaml", allow_duplicate_keys=True) |
286 | 193 | 199 | ||
287 | 194 | # Clean the tested file | 200 | # Clean the tested file |
288 | @@ -204,7 +210,6 @@ mode: 0777 | |||
289 | 204 | ) | 210 | ) |
290 | 205 | 211 | ||
291 | 206 | container = BaseContainer(self.fn) | 212 | container = BaseContainer(self.fn) |
292 | 207 | container._unpack_dir = self.unpack_dir | ||
293 | 208 | test_yaml = container.get_file_as_yaml("test.yaml", yaml_version="1.1") | 213 | test_yaml = container.get_file_as_yaml("test.yaml", yaml_version="1.1") |
294 | 209 | self.assertEqual(test_yaml["mode"], 511) | 214 | self.assertEqual(test_yaml["mode"], 511) |
295 | 210 | 215 | ||
296 | @@ -221,7 +226,6 @@ mode: 0777 | |||
297 | 221 | ) | 226 | ) |
298 | 222 | 227 | ||
299 | 223 | container = BaseContainer(self.fn) | 228 | container = BaseContainer(self.fn) |
300 | 224 | container._unpack_dir = self.unpack_dir | ||
301 | 225 | test_yaml = container.get_file_as_yaml("test.yaml") | 229 | test_yaml = container.get_file_as_yaml("test.yaml") |
302 | 226 | self.assertEqual(test_yaml["mode"], 777) | 230 | self.assertEqual(test_yaml["mode"], 777) |
303 | 227 | 231 | ||
304 | @@ -230,76 +234,49 @@ mode: 0777 | |||
305 | 230 | 234 | ||
306 | 231 | # Test get files list | 235 | # Test get files list |
307 | 232 | def test_get_files_list__happy(self): | 236 | def test_get_files_list__happy(self): |
317 | 233 | try: | 237 | container = BaseContainer(self.fn) |
318 | 234 | container = BaseContainer(self.fn) | 238 | self.assertCountEqual( |
319 | 235 | container._unpack_dir = self.unpack_dir | 239 | container.get_files_list(), |
320 | 236 | self.assertCountEqual( | 240 | self.expected_files, |
321 | 237 | container.get_files_list(), | 241 | ) |
313 | 238 | self.expected_files, | ||
314 | 239 | ) | ||
315 | 240 | except ContainerException: | ||
316 | 241 | self.fail("An unexpected error occurred while getting files list") | ||
322 | 242 | 242 | ||
323 | 243 | def test_get_files_list_abs__happy(self): | 243 | def test_get_files_list_abs__happy(self): |
336 | 244 | try: | 244 | container = BaseContainer(self.fn) |
337 | 245 | container = BaseContainer(self.fn) | 245 | self.assertCountEqual( |
338 | 246 | container._unpack_dir = self.unpack_dir | 246 | container.get_files_list(abs=True), |
339 | 247 | self.assertCountEqual( | 247 | [os.path.join(container.unpack_dir, file) for file in self.expected_files], |
340 | 248 | container.get_files_list(abs=True), | 248 | ) |
329 | 249 | [ | ||
330 | 250 | os.path.join(container.unpack_dir, file) | ||
331 | 251 | for file in self.expected_files | ||
332 | 252 | ], | ||
333 | 253 | ) | ||
334 | 254 | except ContainerException: | ||
335 | 255 | self.fail("An unexpected error occurred while getting files list") | ||
341 | 256 | 249 | ||
342 | 257 | def test_files__happy(self): | 250 | def test_files__happy(self): |
352 | 258 | try: | 251 | container = BaseContainer(self.fn) |
353 | 259 | container = BaseContainer(self.fn) | 252 | self.assertCountEqual( |
354 | 260 | container._unpack_dir = self.unpack_dir | 253 | container.files, |
355 | 261 | self.assertCountEqual( | 254 | self.expected_files, |
356 | 262 | container.files, | 255 | ) |
348 | 263 | self.expected_files, | ||
349 | 264 | ) | ||
350 | 265 | except ContainerException: | ||
351 | 266 | self.fail("An unexpected error occurred while getting files list") | ||
357 | 267 | 256 | ||
358 | 268 | # Test get binaries list | 257 | # Test get binaries list |
359 | 269 | def test_get_compiled_binaries_list__happy(self): | 258 | def test_get_compiled_binaries_list__happy(self): |
370 | 270 | try: | 259 | container = BaseContainer(self.fn) |
371 | 271 | container = BaseContainer(self.fn) | 260 | self.assertCountEqual( |
372 | 272 | container._unpack_dir = self.unpack_dir | 261 | container.get_compiled_binaries_list(), self.expected_binaries |
373 | 273 | self.assertCountEqual( | 262 | ) |
364 | 274 | container.get_compiled_binaries_list(), self.expected_binaries | ||
365 | 275 | ) | ||
366 | 276 | except ContainerException: | ||
367 | 277 | self.fail( | ||
368 | 278 | "An unexpected error occurred while getting compiled binaries list" | ||
369 | 279 | ) | ||
374 | 280 | 263 | ||
375 | 281 | def test_get_compiled_binaries_list_abs__happy(self): | 264 | def test_get_compiled_binaries_list_abs__happy(self): |
390 | 282 | try: | 265 | container = BaseContainer(self.fn) |
391 | 283 | container = BaseContainer(self.fn) | 266 | self.assertCountEqual( |
392 | 284 | container._unpack_dir = self.unpack_dir | 267 | container.get_compiled_binaries_list(abs=True), |
393 | 285 | self.assertCountEqual( | 268 | [ |
394 | 286 | container.get_compiled_binaries_list(abs=True), | 269 | os.path.join(container.unpack_dir, file) |
395 | 287 | [ | 270 | for file in self.expected_binaries |
396 | 288 | os.path.join(container.unpack_dir, file) | 271 | ], |
397 | 289 | for file in self.expected_binaries | 272 | ) |
384 | 290 | ], | ||
385 | 291 | ) | ||
386 | 292 | except ContainerException: | ||
387 | 293 | self.fail( | ||
388 | 294 | "An unexpected error occurred while getting compiled binaries list" | ||
389 | 295 | ) | ||
398 | 296 | 273 | ||
399 | 297 | def test_bin_files__happy(self): | 274 | def test_bin_files__happy(self): |
408 | 298 | try: | 275 | container = BaseContainer(self.fn) |
409 | 299 | container = BaseContainer(self.fn) | 276 | self.assertCountEqual(container.bin_files, self.expected_binaries) |
410 | 300 | container._unpack_dir = self.unpack_dir | 277 | |
411 | 301 | self.assertCountEqual(container.bin_files, self.expected_binaries) | 278 | |
412 | 302 | except ContainerException: | 279 | class TestContainerException(unittest.TestCase): |
413 | 303 | self.fail( | 280 | def test_exception__happy(self): |
414 | 304 | "An unexpected error occurred while getting compiled binaries list" | 281 | e = ContainerException("Test exception") |
415 | 305 | ) | 282 | self.assertEqual(str(e), "Test exception") |
416 | diff --git a/reviewtools/tests/containers/test_squashfs_container.py b/reviewtools/tests/containers/test_squashfs_container.py | |||
417 | index 7d19a77..3241f23 100644 | |||
418 | --- a/reviewtools/tests/containers/test_squashfs_container.py | |||
419 | +++ b/reviewtools/tests/containers/test_squashfs_container.py | |||
420 | @@ -22,52 +22,38 @@ class TestSquashfsContainer(unittest.TestCase): | |||
421 | 22 | 22 | ||
422 | 23 | # Test initialization | 23 | # Test initialization |
423 | 24 | def test_check_initialization__happy(self): | 24 | def test_check_initialization__happy(self): |
430 | 25 | try: | 25 | SquashfsContainer(self.fn) |
425 | 26 | SquashfsContainer(self.fn) | ||
426 | 27 | except Exception: | ||
427 | 28 | self.fail( | ||
428 | 29 | "An unexpected error occurred during SquashfsContainer initialization with container file" | ||
429 | 30 | ) | ||
431 | 31 | 26 | ||
432 | 32 | def test_check_initialization__invalid_format(self): | 27 | def test_check_initialization__invalid_format(self): |
433 | 28 | fd, plain_file = mkstemp(suffix=".snap") | ||
434 | 33 | with self.assertRaises(ContainerException) as context: | 29 | with self.assertRaises(ContainerException) as context: |
435 | 34 | fd, plain_file = mkstemp() | ||
436 | 35 | SquashfsContainer(plain_file) | 30 | SquashfsContainer(plain_file) |
441 | 36 | self.assertEqual( | 31 | self.assertEqual( |
442 | 37 | "unsupported package format (not squashfs)", context.exception.value | 32 | "Unsupported package format (not squashfs)", context.exception.value |
443 | 38 | ) | 33 | ) |
444 | 39 | os.unlink(plain_file) | 34 | os.unlink(plain_file) |
445 | 40 | 35 | ||
446 | 41 | # Test check format | 36 | # Test check format |
447 | 42 | def test_calculate_unpacked_size__happy(self): | 37 | def test_calculate_unpacked_size__happy(self): |
456 | 43 | try: | 38 | # unpacked size calculated is a bit smaller than actual size as it does not consider that |
457 | 44 | # unpacked size calculated is a bit smaller than actual size as it does not consider that | 39 | # folders require at least one complete block |
458 | 45 | # folders require at least one complete block | 40 | container = SquashfsContainer(self.fn) |
459 | 46 | container = SquashfsContainer(self.fn) | 41 | size = container.calculate_unpacked_size() |
460 | 47 | size = container.calculate_unpacked_size() | 42 | self.assertTrue(isinstance(size, int)) |
453 | 48 | self.assertTrue(isinstance(size, int)) | ||
454 | 49 | except Exception: | ||
455 | 50 | self.fail("An unexpected error occurred during unpacked size calculation") | ||
461 | 51 | 43 | ||
462 | 52 | # Test unpack | 44 | # Test unpack |
463 | 53 | def test_unpack__happy(self): | 45 | def test_unpack__happy(self): |
469 | 54 | try: | 46 | container = SquashfsContainer(self.fn) |
470 | 55 | container = SquashfsContainer(self.fn) | 47 | container.unpack() |
466 | 56 | container.unpack() | ||
467 | 57 | except Exception: | ||
468 | 58 | self.fail("An unexpected error occurred during unpack") | ||
471 | 59 | 48 | ||
472 | 60 | def test_unpack__force(self): | 49 | def test_unpack__force(self): |
479 | 61 | try: | 50 | container = SquashfsContainer(self.fn) |
480 | 62 | container = SquashfsContainer(self.fn) | 51 | container.unpack() |
481 | 63 | container.unpack() | 52 | container.unpack(force=True) |
476 | 64 | container.unpack(force=True) | ||
477 | 65 | except Exception: | ||
478 | 66 | self.fail("An unexpected error occurred during unpack") | ||
482 | 67 | 53 | ||
483 | 68 | def test_unpack__no_force(self): | 54 | def test_unpack__no_force(self): |
484 | 55 | container = SquashfsContainer(self.fn) | ||
485 | 56 | container.unpack() | ||
486 | 69 | with self.assertRaises(ContainerException) as context: | 57 | with self.assertRaises(ContainerException) as context: |
487 | 70 | container = SquashfsContainer(self.fn) | ||
488 | 71 | container.unpack() | ||
489 | 72 | container.unpack() | 58 | container.unpack() |
491 | 73 | self.assertTrue(" exists. Aborting." in context.exception.value) | 59 | self.assertTrue(" exists. Aborting." in context.exception.value) |
Move check for container format to BaseContainer initialization and properly mock required functions: https:/ /git.launchpad. net/~jslarraz/ review- tools/commit/ ?id=9477ee65005 44e63ed46ea19ab 1486c8f4cf268c
Remove unneeded exception handling on error cases from tests classes (makes code cleaner and improves coverage): https:/ /git.launchpad. net/~jslarraz/ review- tools/commit/ ?id=acb74aab8da b0c2d0eedb354ad da7bb0ea10e295
Add missing tests case for missing extension on container file name and mock _unpack_dir: https:/ /git.launchpad. net/~jslarraz/ review- tools/commit/ ?id=037aefd2f9d adec3b3734b1b2f 368df8cba569b2