Merge ~jslarraz/review-tools:use-container-in-review-classes into review-tools:master

Proposed by Jorge Sancho Larraz
Status: Merged
Merged at revision: 4dde3f9bc9e65eabb972292c0bc99d100c5cfcc5
Proposed branch: ~jslarraz/review-tools:use-container-in-review-classes
Merge into: review-tools:master
Diff against target: 690 lines (+72/-112)
8 files modified
reviewtools/sr_common.py (+0/-12)
reviewtools/sr_functional.py (+8/-6)
reviewtools/sr_lint.py (+19/-25)
reviewtools/sr_security.py (+3/-2)
reviewtools/sr_tests.py (+0/-15)
reviewtools/tests/schemas/test_schema_snap.py (+0/-1)
reviewtools/tests/test_sr_functional.py (+7/-12)
reviewtools/tests/test_sr_lint.py (+35/-39)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+466877@code.launchpad.net

Commit message

remove mappings `self.pkg_* = self.snap.*` in sr_common and make use of self.snap.* directly in review classes

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

More nice cleanups - thanks @jslarraz, you are on fire 🔥

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reviewtools/sr_common.py b/reviewtools/sr_common.py
2index 5b2f2ec..d4f74e7 100644
3--- a/reviewtools/sr_common.py
4+++ b/reviewtools/sr_common.py
5@@ -398,12 +398,6 @@ class SnapReview(ReviewBase):
6 self.snap = SnapContainer(fn)
7 except ContainerException as e:
8 error(str(e))
9- # TODO: update code to directly use self.snap.xxx instead of assigning here
10- self.pkg_filename = self.snap.filename
11- self.unpack_dir = self.snap.unpack_dir
12- self.pkg_files = self.snap.get_files_list(abs=True)
13- self.pkg_bin_files = self.snap.get_compiled_binaries_list(abs=True)
14- self.tmp_dir = self.snap.tmp_dir
15
16 try:
17 self.snap_yaml = self.snap.get_file_as_yaml(
18@@ -512,12 +506,6 @@ class SnapReview(ReviewBase):
19 hdr, entries = unsquashfs_lln_parse(out)
20 return hdr, entries
21
22- # Since coverage is looked at via the testsuite and the testsuite mocks
23- # this out, don't cover this
24- def _get_unpack_dir(self): # pragma: nocover
25- """Get unpack directory"""
26- return self.unpack_dir
27-
28 def _verify_pkgname(self, n):
29 """Verify package name"""
30 # From validSnapName in snapd/snap/validate.go:
31diff --git a/reviewtools/sr_functional.py b/reviewtools/sr_functional.py
32index 6823b8a..32261e8 100644
33--- a/reviewtools/sr_functional.py
34+++ b/reviewtools/sr_functional.py
35@@ -86,8 +86,8 @@ class SnapReviewFunctional(SnapReview):
36
37 def _cmd_nm(self, args): # pragma: nocover
38 """_cmd_nm indirection for unittests"""
39- real_path = os.path.join(self.unpack_dir, args[-1])
40- if real_path not in self.pkg_bin_files:
41+ real_path = os.path.join(self.snap.unpack_dir, args[-1])
42+ if args[-1] not in self.snap.bin_files:
43 return -1, ""
44 args[-1] = real_path
45
46@@ -300,9 +300,11 @@ class SnapReviewFunctional(SnapReview):
47 for p in func_execstack_skipped_pats:
48 skipped_pats.append(re.compile(r"%s" % p))
49
50- for i in self.pkg_bin_files:
51- if has_execstack(i) and not self._in_patterns(skipped_pats, i):
52- bins.append(os.path.relpath(i, self.unpack_dir))
53+ for i in self.snap.bin_files:
54+ if has_execstack(
55+ os.path.join(self.snap.unpack_dir, i)
56+ ) and not self._in_patterns(skipped_pats, i):
57+ bins.append(i)
58
59 if len(bins) > 0:
60 bins.sort()
61@@ -338,7 +340,7 @@ class SnapReviewFunctional(SnapReview):
62
63 for i in self.base_required_dirs:
64 # self.base_required_dirs are absolute paths
65- mp = os.path.join(self.unpack_dir, i[1:])
66+ mp = os.path.join(self.snap.unpack_dir, i[1:])
67 if not os.path.isdir(mp):
68 missing.append(i)
69
70diff --git a/reviewtools/sr_lint.py b/reviewtools/sr_lint.py
71index 6df02e1..f5bc8ae 100644
72--- a/reviewtools/sr_lint.py
73+++ b/reviewtools/sr_lint.py
74@@ -111,14 +111,14 @@ class SnapReviewLint(SnapReview):
75
76 def check_valid_hook(self):
77 """Check valid hook"""
78- hooks = glob.glob("%s/meta/hooks/*" % self._get_unpack_dir())
79+ hooks = glob.glob("%s/meta/hooks/*" % self.snap.unpack_dir)
80 if len(hooks) == 0:
81 return
82
83 unknown = []
84 for fn in hooks:
85 hook = os.path.basename(fn)
86- rel = os.path.relpath(fn, self._get_unpack_dir())
87+ rel = os.path.relpath(fn, self.snap.unpack_dir)
88 t = "info"
89 n = self._get_check_name("hook_executable", app=hook)
90 s = "OK"
91@@ -198,8 +198,7 @@ class SnapReviewLint(SnapReview):
92 t = "info"
93 n = self._get_check_name("icon_exists")
94 s = "OK"
95- fn = os.path.join(self._get_unpack_dir(), self.snap_yaml["icon"])
96- if fn not in self.pkg_files:
97+ if self.snap_yaml["icon"] not in self.snap.files:
98 t = "error"
99 s = "icon entry '%s' does not exist" % self.snap_yaml["icon"]
100 self._add_result(t, n, s)
101@@ -415,8 +414,7 @@ class SnapReviewLint(SnapReview):
102 ):
103 val = val.lstrip("/")
104
105- fn = os.path.join(self._get_unpack_dir(), os.path.normpath(val))
106- if fn not in self.pkg_files:
107+ if os.path.normpath(val) not in self.snap.files:
108 t = "error"
109 s = "%s does not exist" % (self.snap_yaml["apps"][app][key])
110 self._add_result(t, n, s)
111@@ -486,8 +484,7 @@ class SnapReviewLint(SnapReview):
112 ):
113 val = val.lstrip("/")
114
115- fn = os.path.join(self._get_unpack_dir(), os.path.normpath(val))
116- if fn not in self.pkg_files:
117+ if os.path.normpath(val) not in self.snap.files:
118 nonexistent.append(val)
119
120 if len(nonexistent) != 0:
121@@ -1353,8 +1350,8 @@ class SnapReviewLint(SnapReview):
122 n = self._get_check_name("external_symlinks")
123 s = "OK"
124 links = find_external_symlinks(
125- self._get_unpack_dir(),
126- self.pkg_files,
127+ self.snap.unpack_dir,
128+ [os.path.join(self.snap.unpack_dir, f) for f in self.snap.files],
129 self.snap_yaml["name"],
130 prefix_ok=prefix_ok,
131 )
132@@ -1378,11 +1375,11 @@ class SnapReviewLint(SnapReview):
133
134 # look for compiled code
135 x_binaries = []
136- for i in self.pkg_bin_files:
137+ for i in self.snap.bin_files:
138 # .pyc files are arch-independent
139 if i.endswith(".pyc"):
140 continue
141- x_binaries.append(os.path.relpath(i, self._get_unpack_dir()))
142+ x_binaries.append(i)
143 if len(x_binaries) > 0:
144 x_binaries.sort()
145 # gadget snap is specified with 'all' but has binaries. Don't complain
146@@ -1410,7 +1407,7 @@ class SnapReviewLint(SnapReview):
147 t = "info"
148 n = self._get_check_name("architecture_specified_needed", extra=arch)
149 s = "OK"
150- if len(self.pkg_bin_files) == 0:
151+ if len(self.snap.bin_files) == 0:
152 # This should be a warning but it causes friction for uploads
153 t = "info"
154 s = "Could not find compiled binaries for architecture '%s'" % arch
155@@ -1423,10 +1420,10 @@ class SnapReviewLint(SnapReview):
156 s = "OK"
157 found = []
158 for d in self.vcs_files:
159- entries = glob.glob("%s/%s" % (self._get_unpack_dir(), d))
160+ entries = glob.glob("%s/%s" % (self.snap.unpack_dir, d))
161 if len(entries) > 0:
162 for i in entries:
163- found.append(os.path.relpath(i, self.unpack_dir))
164+ found.append(os.path.relpath(i, self.snap.unpack_dir))
165 if len(found) > 0:
166 t = "warn"
167 s = "found VCS files in package: %s" % ", ".join(found)
168@@ -1439,11 +1436,11 @@ class SnapReviewLint(SnapReview):
169 s = "OK"
170 found = []
171
172- for f in self.pkg_files:
173+ for f in self.snap.files:
174 fn = os.path.basename(f)
175 for d in self.iffy_files:
176 if re.search(r"%s" % d, fn):
177- found.append(os.path.relpath(f, self.unpack_dir))
178+ found.append(f)
179
180 if len(found) > 0:
181 t = "warn"
182@@ -1839,14 +1836,14 @@ class SnapReviewLint(SnapReview):
183 # consider snap-controlled paths that symlink outside of the snap
184 # (${SNAP}/ is in the read-only area, so it is fine).
185 if fn.startswith("${SNAP}/"):
186- return True, os.path.join(self._get_unpack_dir(), fn.split("/", 1)[1])
187+ return True, os.path.join(self.snap.unpack_dir, fn.split("/", 1)[1])
188
189 # As a special consideration to not break existing snaps, allow
190 # /snap/<snap name>/.... People should use ${SNAP}/ instead since
191 # /snap is not portable (eg, Fedora puts this in /var/lib/snap
192 # instead of /snap), but '${SNAP}' wasn't always available.
193 if fn.startswith("/snap/%s/current/" % self.snap_yaml["name"]):
194- return True, os.path.join(self._get_unpack_dir(), fn.split("/", 4)[4])
195+ return True, os.path.join(self.snap.unpack_dir, fn.split("/", 4)[4])
196
197 return False, None
198 elif fn.startswith("snap."):
199@@ -2017,8 +2014,7 @@ class SnapReviewLint(SnapReview):
200 s = "OK"
201
202 has_desktop_files = False
203- for f in self.pkg_files:
204- fn = os.path.relpath(f, self._get_unpack_dir())
205+ for fn in self.snap.files:
206 if fn.startswith("meta/gui/") and fn.endswith(".desktop"):
207 try:
208 self._verify_desktop_file(fn)
209@@ -3049,16 +3045,14 @@ class SnapReviewLint(SnapReview):
210
211 def check_valid_icon_sets(self):
212 """Check valid icon sets"""
213- icons = glob.glob(
214- "%s/meta/gui/icons/**" % self._get_unpack_dir(), recursive=True
215- )
216+ icons = glob.glob("%s/meta/gui/icons/**" % self.snap.unpack_dir, recursive=True)
217 bad_names = []
218 unsnap_names = []
219 toobig_names = []
220 wrongext_names = []
221 count = 0
222 for fn in icons:
223- rel = os.path.relpath(fn, self._get_unpack_dir())
224+ rel = os.path.relpath(fn, self.snap.unpack_dir)
225 if rel != shlex.quote(rel):
226 bad_names.append(rel)
227 continue
228diff --git a/reviewtools/sr_security.py b/reviewtools/sr_security.py
229index eb2d202..5bc49b2 100644
230--- a/reviewtools/sr_security.py
231+++ b/reviewtools/sr_security.py
232@@ -187,7 +187,7 @@ class SnapReviewSecurity(SnapReview):
233
234 def check_squashfs_resquash(self):
235 """Check resquash of squashfs"""
236- fn = os.path.abspath(self.pkg_filename)
237+ fn = os.path.abspath(self.snap.filename)
238
239 # Verify squashfs has no fragments. If it does, it will not resquash
240 # properly (LP: #1576763). This stat output for fragments has been
241@@ -267,7 +267,8 @@ class SnapReviewSecurity(SnapReview):
242 self._add_result(t, n, s)
243 return
244
245- tmpdir = self.tmp_dir # this is autocleaned
246+ # TODO: either use SnapContainer for the test itself or use other tmp directory
247+ tmpdir = self.snap.tmp_dir # this is autocleaned
248 tmp_unpack = os.path.join(tmpdir, "squashfs-root")
249 tmp_repack = os.path.join(tmpdir, "repack.snap")
250 fakeroot_env = os.path.join(tmpdir, "fakeroot.env")
251diff --git a/reviewtools/sr_tests.py b/reviewtools/sr_tests.py
252index eaea513..1b5f93d 100644
253--- a/reviewtools/sr_tests.py
254+++ b/reviewtools/sr_tests.py
255@@ -26,7 +26,6 @@ TEST_SNAP_YAML = ""
256 TEST_SNAP_MANIFEST_YAML = ""
257 TEST_PKGFMT_TYPE = "snap"
258 TEST_PKGFMT_VERSION = "16.04"
259-TEST_UNPACK_DIR = "/fake"
260 TEST_UNSQUASHFS_LLN_HDR = ""
261 TEST_UNSQUASHFS_LLN_ENTRIES = ("", None)
262 TEST_CMD_NM = (0, "")
263@@ -62,11 +61,6 @@ def _pkgfmt_type(self):
264 return TEST_PKGFMT_TYPE
265
266
267-def __get_unpack_dir(self):
268- """Pretend we found the unpack dir"""
269- return TEST_UNPACK_DIR
270-
271-
272 def _unsquashfs_lln(self, fn):
273 """Pretend we ran unsquashfs -lln fn"""
274 return (TEST_UNSQUASHFS_LLN_HDR, TEST_UNSQUASHFS_LLN_ENTRIES)
275@@ -93,9 +87,6 @@ def create_patches():
276 )
277 # sr_common
278 patches.append(
279- patch("reviewtools.sr_common.SnapReview._get_unpack_dir", __get_unpack_dir)
280- )
281- patches.append(
282 patch("reviewtools.sr_common.SnapReview._unsquashfs_lln", _unsquashfs_lln)
283 )
284
285@@ -184,10 +175,6 @@ class TestSnapReview(TestCase):
286 TEST_PKGFMT_TYPE = t
287 TEST_PKGFMT_VERSION = v
288
289- def set_test_unpack_dir(self, d):
290- global TEST_UNPACK_DIR
291- TEST_UNPACK_DIR = d
292-
293 def set_test_unsquashfs_lln(self, hdr, entries):
294 global TEST_UNSQUASHFS_LLN_HDR
295 global TEST_UNSQUASHFS_LLN_ENTRIES
296@@ -216,8 +203,6 @@ class TestSnapReview(TestCase):
297 TEST_PKGFMT_TYPE = "snap"
298 global TEST_PKGFMT_VERSION
299 TEST_PKGFMT_VERSION = "16.04"
300- global TEST_UNPACK_DIR
301- TEST_UNPACK_DIR = "/fake"
302 global TEST_UNSQUASHFS_LLN_HDR
303 TEST_UNSQUASHFS_LLN_HDR = ""
304 global TEST_UNSQUASHFS_LLN_ENTRIES
305diff --git a/reviewtools/tests/schemas/test_schema_snap.py b/reviewtools/tests/schemas/test_schema_snap.py
306index 59cf0f7..d4e2b29 100644
307--- a/reviewtools/tests/schemas/test_schema_snap.py
308+++ b/reviewtools/tests/schemas/test_schema_snap.py
309@@ -283,4 +283,3 @@ class TestSchemaSnap(TestSchemaBase):
310 with self.subTest(value=value):
311 error = error.replace("{value}", str(value)) if error else error
312 self._test_value("assumes", value, error)
313-
314diff --git a/reviewtools/tests/test_sr_functional.py b/reviewtools/tests/test_sr_functional.py
315index 2e2e3d5..8935fbc 100644
316--- a/reviewtools/tests/test_sr_functional.py
317+++ b/reviewtools/tests/test_sr_functional.py
318@@ -53,7 +53,6 @@ class TestSnapReviewFunctional(sr_tests.TestSnapReview):
319 self.set_test_unsquashfs_lln(hdr, entries)
320
321 def _set_default_state(self):
322- self.set_test_unpack_dir = "/nonexistent"
323 lln = """drwxr-xr-x 0/0 215 2020-03-23 14:23 squashfs-root
324 drwxr-xr-x 0/0 73 2020-03-23 14:23 squashfs-root/bin
325 -rwxr-xr-x 0/0 43416 2020-03-23 14:23 squashfs-root/bin/cat
326@@ -1375,7 +1374,7 @@ class TestSnapReviewFunctionalNoMock(TestCase):
327
328 package = utils.make_snap2(output_dir=output_dir)
329 c = SnapReviewFunctional(package)
330- c.pkg_bin_files = [fn]
331+ c.snap._unpack_dir = output_dir
332 c.check_execstack()
333 report = c.review_report
334 expected_counts = {"info": None, "warn": 1, "error": 0}
335@@ -1415,7 +1414,7 @@ confinement: devmode
336 """
337 package = utils.make_snap2(output_dir=output_dir, yaml=yaml)
338 c = SnapReviewFunctional(package)
339- c.pkg_bin_files = [fn]
340+ c.snap._unpack_dir = output_dir
341 c.check_execstack()
342 report = c.review_report
343 expected_counts = {"info": 1, "warn": 0, "error": 0}
344@@ -1447,7 +1446,7 @@ confinement: devmode
345 cmd(["execstack", "--set-execstack", fn])
346 package = utils.make_snap2(name="test-override", output_dir=output_dir)
347 c = SnapReviewFunctional(package)
348- c.pkg_bin_files = [fn]
349+ c.snap._unpack_dir = output_dir
350
351 # update overrides for our snap
352 from reviewtools.overrides import func_execstack_overrides
353@@ -1494,7 +1493,7 @@ type: os
354 """
355 package = utils.make_snap2(output_dir=output_dir, yaml=yaml)
356 c = SnapReviewFunctional(package)
357- c.pkg_bin_files = [fn]
358+ c.snap._unpack_dir = output_dir
359 c.check_execstack()
360 report = c.review_report
361 expected_counts = {"info": 0, "warn": 0, "error": 0}
362@@ -1508,7 +1507,7 @@ type: os
363
364 package = utils.make_snap2(output_dir=self.mkdtemp())
365 c = SnapReviewFunctional(package)
366- c.pkg_bin_files = ["path/to/nonexistent/file"]
367+ c._bin_files = ["path/to/nonexistent/file"]
368 c.check_execstack()
369 report = c.review_report
370 expected_counts = {"info": 1, "warn": 0, "error": 0}
371@@ -1543,7 +1542,6 @@ type: os
372 ]
373 output_dir = self.mkdtemp()
374
375- pkg_bin_files = []
376 for f in test_files:
377 dir = os.path.join(output_dir, os.path.dirname(f))
378 if not os.path.exists(dir):
379@@ -1552,11 +1550,10 @@ type: os
380 shutil.copyfile("/bin/ls", fn)
381 # create a /bin/ls with executable stack
382 cmd(["execstack", "--set-execstack", fn])
383- pkg_bin_files.append(fn)
384
385 package = utils.make_snap2(output_dir=output_dir)
386 c = SnapReviewFunctional(package)
387- c.pkg_bin_files = pkg_bin_files
388+ c.snap._unpack_dir = output_dir
389 c.check_execstack()
390 report = c.review_report
391 expected_counts = {"info": 1, "warn": 0, "error": 0}
392@@ -1574,7 +1571,6 @@ type: os
393 test_files = ["hasexecstack.bin", "usr/lib/klibc/bin/cat"]
394 output_dir = self.mkdtemp()
395
396- pkg_bin_files = []
397 for f in test_files:
398 dir = os.path.join(output_dir, os.path.dirname(f))
399 if not os.path.exists(dir):
400@@ -1583,11 +1579,10 @@ type: os
401 shutil.copyfile("/bin/ls", fn)
402 # create a /bin/ls with executable stack
403 cmd(["execstack", "--set-execstack", fn])
404- pkg_bin_files.append(fn)
405
406 package = utils.make_snap2(output_dir=output_dir)
407 c = SnapReviewFunctional(package)
408- c.pkg_bin_files = pkg_bin_files
409+ c.snap._unpack_dir = output_dir
410 c.check_execstack()
411 report = c.review_report
412 expected_counts = {"info": None, "warn": 1, "error": 0}
413diff --git a/reviewtools/tests/test_sr_lint.py b/reviewtools/tests/test_sr_lint.py
414index 7107d65..9a413f6 100644
415--- a/reviewtools/tests/test_sr_lint.py
416+++ b/reviewtools/tests/test_sr_lint.py
417@@ -312,9 +312,8 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
418 """Test check_icon()"""
419 self.set_test_snap_yaml("icon", "someicon")
420 self.set_test_snap_yaml("type", "gadget")
421- self.set_test_unpack_dir = "/nonexistent"
422 c = SnapReviewLint(self.test_name)
423- c.pkg_files.append(os.path.join(c._get_unpack_dir(), "someicon"))
424+ c.snap._files = c.snap.files + ["someicon"]
425 c.check_icon()
426 r = c.review_report
427 expected_counts = {"info": 4, "warn": 0, "error": 0}
428@@ -323,9 +322,8 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
429 def test_check_icon_no_gadget(self):
430 """Test check_icon() - no gadget"""
431 self.set_test_snap_yaml("icon", "someicon")
432- self.set_test_unpack_dir = "/nonexistent"
433 c = SnapReviewLint(self.test_name)
434- c.pkg_files.append(os.path.join(c._get_unpack_dir(), "someicon"))
435+ c.snap._files = c.snap.files + ["someicon"]
436 c.check_icon()
437 r = c.review_report
438 expected_counts = {"info": None, "warn": 1, "error": 0}
439@@ -356,7 +354,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
440 self.set_test_snap_yaml("icon", "/foo/bar/someicon")
441 self.set_test_snap_yaml("type", "gadget")
442 c = SnapReviewLint(self.test_name)
443- c.pkg_files.append("/foo/bar/someicon")
444+ c.snap._files = c.snap.files + ["/foo/bar/someicon"]
445 c.check_icon()
446 r = c.review_report
447 expected_counts = {"info": None, "warn": 0, "error": 1}
448@@ -366,9 +364,8 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
449 """Test check_icon() - canonical path"""
450 self.set_test_snap_yaml("icon", "../foo/someicon")
451 self.set_test_snap_yaml("type", "gadget")
452- self.set_test_unpack_dir = "/nonexistent"
453 c = SnapReviewLint(self.test_name)
454- c.pkg_files.append(os.path.join(c._get_unpack_dir(), "../foo/someicon"))
455+ c.snap._files = c.snap.files + ["../foo/someicon"]
456 c.check_icon()
457 r = c.review_report
458 expected_counts = {"info": None, "warn": 0, "error": 1}
459@@ -378,10 +375,8 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
460 """Test check_icon() - missing icon"""
461 self.set_test_snap_yaml("icon", "someicon")
462 self.set_test_snap_yaml("type", "gadget")
463- self.set_test_unpack_dir = "/nonexistent"
464 c = SnapReviewLint(self.test_name)
465- # since the icon isn't in c.pkg_files, don't add it for this test
466- # c.pkg_files.append(os.path.join(c._get_unpack_dir(), 'someicon'))
467+ # since the icon isn't in c.snap.files, don't add it for this test
468 c.check_icon()
469 r = c.review_report
470 expected_counts = {"info": None, "warn": 0, "error": 1}
471@@ -839,7 +834,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
472 cmd = "bin/foo"
473 self.set_test_snap_yaml("apps", {"foo": {"command": cmd}})
474 c = SnapReviewLint(self.test_name)
475- c.pkg_files.append(os.path.join("/fake", cmd))
476+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
477 c.check_apps_command()
478 r = c.review_report
479 expected_counts = {"info": 1, "warn": 0, "error": 0}
480@@ -850,7 +845,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
481 cmd = "bin/foo"
482 self.set_test_snap_yaml("apps", {"foo": {"command": "./" + cmd}})
483 c = SnapReviewLint(self.test_name)
484- c.pkg_files.append(os.path.join("/fake", cmd))
485+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
486 c.check_apps_command()
487 r = c.review_report
488 expected_counts = {"info": 1, "warn": 0, "error": 0}
489@@ -861,7 +856,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
490 cmd = "/bin/foo"
491 self.set_test_snap_yaml("apps", {"foo": {"command": cmd}})
492 c = SnapReviewLint(self.test_name)
493- c.pkg_files.append("/fake" + cmd)
494+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
495 c.check_apps_command()
496 r = c.review_report
497 expected_counts = {"info": 0, "warn": 0, "error": 1}
498@@ -873,7 +868,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
499 self.set_test_snap_yaml("apps", {"foo": {"command": cmd}})
500 self.set_test_snap_yaml("base", "nix-base")
501 c = SnapReviewLint(self.test_name)
502- c.pkg_files.append("/fake" + cmd)
503+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
504 c.check_apps_command()
505 r = c.review_report
506 expected_counts = {"info": 1, "warn": 0, "error": 0}
507@@ -921,7 +916,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
508 cmd = "bin/foo"
509 self.set_test_snap_yaml("apps", {"foo": {"command": "%s -c bar" % cmd}})
510 c = SnapReviewLint(self.test_name)
511- c.pkg_files.append(os.path.join("/fake", cmd))
512+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
513 c.check_apps_command()
514 r = c.review_report
515 expected_counts = {"info": 1, "warn": 0, "error": 0}
516@@ -932,7 +927,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
517 cmd = "bin/foo bar"
518 self.set_test_snap_yaml("apps", {"foo": {"command": "'%s'" % cmd}})
519 c = SnapReviewLint(self.test_name)
520- c.pkg_files.append(os.path.join("/fake", cmd))
521+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
522 c.check_apps_command()
523 r = c.review_report
524 expected_counts = {"info": 1, "warn": 0, "error": 0}
525@@ -943,7 +938,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
526 cmd = "bin/foo bar"
527 self.set_test_snap_yaml("apps", {"foo": {"command": "'%s' -c foo" % cmd}})
528 c = SnapReviewLint(self.test_name)
529- c.pkg_files.append(os.path.join("/fake", cmd))
530+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
531 c.check_apps_command()
532 r = c.review_report
533 expected_counts = {"info": 1, "warn": 0, "error": 0}
534@@ -972,7 +967,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
535 cmd = "bin/foo"
536 self.set_test_snap_yaml("apps", {"foo": {"command-chain": [cmd]}})
537 c = SnapReviewLint(self.test_name)
538- c.pkg_files.append(os.path.join("/fake", cmd))
539+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
540 c.check_apps_command_chain()
541 r = c.review_report
542 expected_counts = {"info": 1, "warn": 0, "error": 0}
543@@ -983,7 +978,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
544 cmd = "/bin/foo"
545 self.set_test_snap_yaml("apps", {"foo": {"command-chain": [cmd]}})
546 c = SnapReviewLint(self.test_name)
547- c.pkg_files.append("/fake" + cmd)
548+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
549 c.check_apps_command_chain()
550 r = c.review_report
551 expected_counts = {"info": 0, "warn": 0, "error": 1}
552@@ -995,7 +990,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
553 self.set_test_snap_yaml("apps", {"foo": {"command-chain": [cmd]}})
554 self.set_test_snap_yaml("base", "nix-base")
555 c = SnapReviewLint(self.test_name)
556- c.pkg_files.append("/fake" + cmd)
557+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
558 c.check_apps_command_chain()
559 r = c.review_report
560 expected_counts = {"info": 1, "warn": 0, "error": 0}
561@@ -1006,7 +1001,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
562 cmd = "bin/foo"
563 self.set_test_snap_yaml("apps", {"foo": {"command-chain": ["./" + cmd]}})
564 c = SnapReviewLint(self.test_name)
565- c.pkg_files.append(os.path.join("/fake", cmd))
566+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
567 c.check_apps_command_chain()
568 r = c.review_report
569 expected_counts = {"info": 1, "warn": 0, "error": 0}
570@@ -1072,7 +1067,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
571 cmd = "bin/foo"
572 self.set_test_snap_yaml("apps", {"foo": {"command-chain": ["%s -c bar" % cmd]}})
573 c = SnapReviewLint(self.test_name)
574- c.pkg_files.append(os.path.join("/fake", cmd))
575+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
576 c.check_apps_command_chain()
577 r = c.review_report
578 expected_counts = {"info": 1, "warn": 0, "error": 0}
579@@ -1083,7 +1078,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
580 cmd = "bin/foo bar"
581 self.set_test_snap_yaml("apps", {"foo": {"command-chain": ["'%s'" % cmd]}})
582 c = SnapReviewLint(self.test_name)
583- c.pkg_files.append(os.path.join("/fake", cmd))
584+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
585 c.check_apps_command_chain()
586 r = c.review_report
587 expected_counts = {"info": 1, "warn": 0, "error": 0}
588@@ -1096,7 +1091,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
589 "apps", {"foo": {"command-chain": ["'%s' -c foo" % cmd]}}
590 )
591 c = SnapReviewLint(self.test_name)
592- c.pkg_files.append(os.path.join("/fake", cmd))
593+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
594 c.check_apps_command_chain()
595 r = c.review_report
596 expected_counts = {"info": 1, "warn": 0, "error": 0}
597@@ -1127,7 +1122,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
598 cmd = "bin/foo"
599 self.set_test_snap_yaml("hooks", {"foo": {"command-chain": [cmd]}})
600 c = SnapReviewLint(self.test_name)
601- c.pkg_files.append(os.path.join("/fake", cmd))
602+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
603 c.check_hooks_command_chain()
604 r = c.review_report
605 expected_counts = {"info": 1, "warn": 0, "error": 0}
606@@ -1138,7 +1133,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
607 cmd = "bin/foo"
608 self.set_test_snap_yaml("hooks", {"foo": {}})
609 c = SnapReviewLint(self.test_name)
610- c.pkg_files.append(os.path.join("/fake", cmd))
611+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
612 c.check_hooks_command_chain()
613 r = c.review_report
614 expected_counts = {"info": 0, "warn": 0, "error": 0}
615@@ -1149,7 +1144,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
616 cmd = "bin/foo"
617 self.set_test_snap_yaml("apps", {"foo": {"completer": cmd}})
618 c = SnapReviewLint(self.test_name)
619- c.pkg_files.append(os.path.join("/fake", cmd))
620+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
621 c.check_apps_completer()
622 r = c.review_report
623 expected_counts = {"info": 1, "warn": 0, "error": 0}
624@@ -1160,7 +1155,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
625 cmd = "bin/foo"
626 self.set_test_snap_yaml("apps", {"foo": {"completer": "./" + cmd}})
627 c = SnapReviewLint(self.test_name)
628- c.pkg_files.append(os.path.join("/fake", cmd))
629+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
630 c.check_apps_completer()
631 r = c.review_report
632 expected_counts = {"info": 1, "warn": 0, "error": 0}
633@@ -1208,7 +1203,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
634 cmd = "bin/foo"
635 self.set_test_snap_yaml("apps", {"foo": {"stop-command": cmd}})
636 c = SnapReviewLint(self.test_name)
637- c.pkg_files.append(os.path.join("/fake", cmd))
638+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
639 c.check_apps_stop_command()
640 r = c.review_report
641 expected_counts = {"info": 1, "warn": 0, "error": 0}
642@@ -1256,7 +1251,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
643 cmd = "bin/foo"
644 self.set_test_snap_yaml("apps", {"foo": {"post-stop-command": cmd}})
645 c = SnapReviewLint(self.test_name)
646- c.pkg_files.append(os.path.join("/fake", cmd))
647+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
648 c.check_apps_post_stop_command()
649 r = c.review_report
650 expected_counts = {"info": 1, "warn": 0, "error": 0}
651@@ -1304,7 +1299,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
652 cmd = "bin/foo"
653 self.set_test_snap_yaml("apps", {"foo": {"reload-command": cmd}})
654 c = SnapReviewLint(self.test_name)
655- c.pkg_files.append(os.path.join("/fake", cmd))
656+ c.snap._files = c.snap.files + [cmd.lstrip("/")]
657 c.check_apps_reload_command()
658 r = c.review_report
659 expected_counts = {"info": 1, "warn": 0, "error": 0}
660@@ -5786,6 +5781,7 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
661 def test__verify_icon_path(self):
662 """Test _verify_icon_path()"""
663 c = SnapReviewLint(self.test_name)
664+ unpack_dir = c.snap.unpack_dir
665
666 invalid = [
667 "/foo/../bar",
668@@ -5815,14 +5811,14 @@ class TestSnapReviewLint(sr_tests.TestSnapReview):
669 ("foo", None),
670 ("foo.png", None),
671 ("foo.svg", None),
672- ("${SNAP}/foo.png", "/fake/foo.png"),
673- ("${SNAP}/foo.svg", "/fake/foo.svg"),
674- ("${SNAP}/foo.ico", "/fake/foo.ico"),
675- ("${SNAP}/foo", "/fake/foo"),
676- ("/snap/foo/current/foo.png", "/fake/foo.png"),
677- ("/snap/foo/current/foo.svg", "/fake/foo.svg"),
678- ("/snap/foo/current/foo.ico", "/fake/foo.ico"),
679- ("/snap/foo/current/foo", "/fake/foo"),
680+ ("${SNAP}/foo.png", "%s/foo.png" % unpack_dir),
681+ ("${SNAP}/foo.svg", "%s/foo.svg" % unpack_dir),
682+ ("${SNAP}/foo.ico", "%s/foo.ico" % unpack_dir),
683+ ("${SNAP}/foo", "%s/foo" % unpack_dir),
684+ ("/snap/foo/current/foo.png", "%s/foo.png" % unpack_dir),
685+ ("/snap/foo/current/foo.svg", "%s/foo.svg" % unpack_dir),
686+ ("/snap/foo/current/foo.ico", "%s/foo.ico" % unpack_dir),
687+ ("/snap/foo/current/foo", "%s/foo" % unpack_dir),
688 ("snap.foo.foo.png", None),
689 ("snap.foo.bar.svg", None),
690 ("snap.foo.bar.ico", None),

Subscribers

People subscribed via source and target branches