* [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/data/repos/network/MetadataUrlCheck/RedirectedUrl/, ...
@ 2022-10-17 7:48 Arthur Zamarin
0 siblings, 0 replies; only message in thread
From: Arthur Zamarin @ 2022-10-17 7:48 UTC (permalink / raw
To: gentoo-commits
commit: 8ef7ab63c0fbd294b37e851bce709336a1bd6e5a
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 07:23:21 2022 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 07:45:33 2022 +0000
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=8ef7ab63
network: fix results misattributed with same URL
When a URL is collected from multiple different attributes, the results
weren't updating the selected attribute, which resulted in wrong report.
Resolves: https://github.com/pkgcore/pkgcheck/issues/403
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
src/pkgcheck/checks/network.py | 12 ++++++----
.../MetadataUrlCheck/RedirectedUrl/expected.json | 2 ++
.../MetadataUrlCheck/RedirectedUrl/metadata.xml | 2 ++
.../MetadataUrlCheck/RedirectedUrl/responses.py | 28 ++++++++++++++++------
4 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/src/pkgcheck/checks/network.py b/src/pkgcheck/checks/network.py
index cfe76687..cad8e536 100644
--- a/src/pkgcheck/checks/network.py
+++ b/src/pkgcheck/checks/network.py
@@ -167,7 +167,7 @@ class _UrlCheck(NetworkCheck):
result = DeadUrl(attr, url, str(e), pkg=pkg)
return result
- def task_done(self, pkg, future):
+ def task_done(self, pkg, attr, future):
"""Determine the result of a given URL verification task."""
exc = future.exception()
if exc is not None:
@@ -180,8 +180,10 @@ class _UrlCheck(NetworkCheck):
result = future.result()
if result is not None:
if pkg is not None:
- # recreate result object with different pkg target
- result = result._create(**result._attrs, pkg=pkg)
+ # recreate result object with different pkg target and attr
+ attrs = result._attrs.copy()
+ attrs['attr'] = attr
+ result = result._create(**attrs, pkg=pkg)
self.results_q.put([result])
def _get_urls(self, pkg):
@@ -198,10 +200,10 @@ class _UrlCheck(NetworkCheck):
future = futures.get(url)
if future is None:
future = executor.submit(func, attr, url, **kwargs)
- future.add_done_callback(partial(self.task_done, None))
+ future.add_done_callback(partial(self.task_done, None, None))
futures[url] = future
else:
- future.add_done_callback(partial(self.task_done, kwargs['pkg']))
+ future.add_done_callback(partial(self.task_done, kwargs['pkg'], attr))
def schedule(self, pkg, executor, futures):
"""Schedule verification methods to run in separate threads for all flagged URLs."""
diff --git a/testdata/data/repos/network/MetadataUrlCheck/RedirectedUrl/expected.json b/testdata/data/repos/network/MetadataUrlCheck/RedirectedUrl/expected.json
index 789b87d2..ef65eafc 100644
--- a/testdata/data/repos/network/MetadataUrlCheck/RedirectedUrl/expected.json
+++ b/testdata/data/repos/network/MetadataUrlCheck/RedirectedUrl/expected.json
@@ -1 +1,3 @@
{"__class__": "RedirectedUrl", "category": "MetadataUrlCheck", "package": "RedirectedUrl", "version": "0", "attr": "metadata.xml: changelog", "url": "https://github.com/pkgcore/pkgcheck/changelog", "new_url": "https://github.com/pkgcore/pkgcheck/news"}
+{"__class__": "RedirectedUrl", "category": "MetadataUrlCheck", "package": "RedirectedUrl", "version": "0", "attr": "metadata.xml: remote-id", "url": "https://github.com/pkgcore/pkgcheck", "new_url": "https://github.com/pkgcore/pkgcheck/"}
+{"__class__": "RedirectedUrl", "category": "MetadataUrlCheck", "package": "RedirectedUrl", "version": "0", "attr": "metadata.xml: doc", "url": "https://github.com/pkgcore/pkgcheck", "new_url": "https://github.com/pkgcore/pkgcheck/"}
diff --git a/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/metadata.xml b/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/metadata.xml
index 429b3b6b..97b42470 100644
--- a/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/metadata.xml
+++ b/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/metadata.xml
@@ -2,6 +2,8 @@
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<upstream>
+ <remote-id type="github">pkgcore/pkgcheck</remote-id>
+ <doc>https://github.com/pkgcore/pkgcheck</doc>
<changelog>https://github.com/pkgcore/pkgcheck/changelog</changelog>
</upstream>
</pkgmetadata>
diff --git a/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/responses.py b/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/responses.py
index 560443ee..0c4e3565 100644
--- a/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/responses.py
+++ b/testdata/repos/network/MetadataUrlCheck/RedirectedUrl/responses.py
@@ -9,11 +9,25 @@ r_hist.url = 'https://github.com/pkgcore/pkgcheck/changelog'
r_hist.headers = {'location': 'https://github.com/pkgcore/pkgcheck/news'}
r_hist.raw = io.StringIO()
-r = Response()
-r.status_code = 200
-r.reason = 'OK'
-r.url = 'https://github.com/pkgcore/pkgcheck/changelog'
-r.raw = io.StringIO()
-r.history = [r_hist]
+r1 = Response()
+r1.status_code = 200
+r1.reason = 'OK'
+r1.url = 'https://github.com/pkgcore/pkgcheck/changelog'
+r1.raw = io.StringIO()
+r1.history = [r_hist]
-responses = [r]
+r_hist = Response()
+r_hist.status_code = 301
+r_hist.reason = 'Moved Permanently'
+r_hist.url = 'https://github.com/pkgcore/pkgcheck'
+r_hist.headers = {'location': 'https://github.com/pkgcore/pkgcheck/'}
+r_hist.raw = io.StringIO()
+
+r2 = Response()
+r2.status_code = 301
+r2.reason = 'OK'
+r2.url = 'https://github.com/pkgcore/pkgcheck'
+r2.raw = io.StringIO()
+r2.history = [r_hist]
+
+responses = [r1, r2]
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-17 7:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-17 7:48 [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/data/repos/network/MetadataUrlCheck/RedirectedUrl/, Arthur Zamarin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox