Gentoo Archives: gentoo-commits

From: Arthur Zamarin <arthurzam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: bin/, tests/scripts/
Date: Sat, 31 Dec 2022 11:31:49
Message-Id: 1672486283.c219e33c3cb40dceb5b3796e00dbd25b3c9dcf8a.arthurzam@gentoo
1 commit: c219e33c3cb40dceb5b3796e00dbd25b3c9dcf8a
2 Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
3 AuthorDate: Sat Dec 31 11:19:02 2022 +0000
4 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
5 CommitDate: Sat Dec 31 11:31:23 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=c219e33c
7
8 test_pkgcheck_replay: fix test_replay_pipe_stdin from sdist
9
10 We don't ship `bin/` in the sdist, so we are unable to run the script
11 `bin/pkgcheck` from the sdist. Instead, use monkey-patching and `tool`
12 to run with stdin `pkgcheck replay`.
13
14 Bug: https://bugs.gentoo.org/888896
15 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
16
17 bin/pkgcheck | 1 -
18 tests/scripts/test_pkgcheck_replay.py | 58 +++++++++++++++++------------------
19 2 files changed, 29 insertions(+), 30 deletions(-)
20
21 diff --git a/bin/pkgcheck b/bin/pkgcheck
22 deleted file mode 120000
23 index 78f990ec..00000000
24 --- a/bin/pkgcheck
25 +++ /dev/null
26 @@ -1 +0,0 @@
27 -../src/pkgcheck/scripts/__init__.py
28 \ No newline at end of file
29
30 diff --git a/tests/scripts/test_pkgcheck_replay.py b/tests/scripts/test_pkgcheck_replay.py
31 index c2aeda66..b6b7d606 100644
32 --- a/tests/scripts/test_pkgcheck_replay.py
33 +++ b/tests/scripts/test_pkgcheck_replay.py
34 @@ -1,20 +1,18 @@
35 -import os
36 -import subprocess
37 import tempfile
38 from functools import partial
39 from unittest.mock import patch
40
41 import pytest
42 +from snakeoil.formatters import PlainTextFormatter
43 +
44 from pkgcheck import __title__ as project
45 from pkgcheck.checks.profiles import ProfileWarning
46 from pkgcheck.reporters import JsonStream
47 from pkgcheck.scripts import run
48 -from snakeoil.formatters import PlainTextFormatter
49
50
51 class TestPkgcheckReplay:
52 -
53 - script = partial(run, project)
54 + script = staticmethod(partial(run, project))
55
56 @pytest.fixture(autouse=True)
57 def _setup(self, testconfig):
58 @@ -33,11 +31,11 @@ class TestPkgcheckReplay:
59
60 def test_replay(self, capsys):
61 result = ProfileWarning("profile warning: foo")
62 - with tempfile.NamedTemporaryFile() as f:
63 - out = PlainTextFormatter(f)
64 + with tempfile.NamedTemporaryFile() as file:
65 + out = PlainTextFormatter(file)
66 with JsonStream(out) as reporter:
67 reporter.report(result)
68 - with patch("sys.argv", self.args + ["-R", "StrReporter", f.name]):
69 + with patch("sys.argv", self.args + ["-R", "StrReporter", file.name]):
70 with pytest.raises(SystemExit) as excinfo:
71 self.script()
72 out, err = capsys.readouterr()
73 @@ -47,13 +45,13 @@ class TestPkgcheckReplay:
74
75 def test_corrupted_resuts(self, capsys):
76 result = ProfileWarning("profile warning: foo")
77 - with tempfile.NamedTemporaryFile() as f:
78 - out = PlainTextFormatter(f)
79 + with tempfile.NamedTemporaryFile() as file:
80 + out = PlainTextFormatter(file)
81 with JsonStream(out) as reporter:
82 reporter.report(result)
83 - f.write(b"corrupted")
84 - f.seek(0)
85 - with patch("sys.argv", self.args + ["-R", "StrReporter", f.name]):
86 + file.write(b"corrupted")
87 + file.seek(0)
88 + with patch("sys.argv", self.args + ["-R", "StrReporter", file.name]):
89 with pytest.raises(SystemExit) as excinfo:
90 self.script()
91 out, err = capsys.readouterr()
92 @@ -61,26 +59,28 @@ class TestPkgcheckReplay:
93 assert excinfo.value.code == 2
94
95 def test_invalid_file(self, capsys):
96 - with tempfile.NamedTemporaryFile(mode="wt") as f:
97 - f.write("invalid file")
98 - f.seek(0)
99 - with patch("sys.argv", self.args + ["-R", "StrReporter", f.name]):
100 + with tempfile.NamedTemporaryFile(mode="wt") as file:
101 + file.write("invalid file")
102 + file.seek(0)
103 + with patch("sys.argv", self.args + ["-R", "StrReporter", file.name]):
104 with pytest.raises(SystemExit) as excinfo:
105 self.script()
106 out, err = capsys.readouterr()
107 assert err.strip() == "pkgcheck replay: error: invalid or unsupported replay file"
108 assert excinfo.value.code == 2
109
110 - def test_replay_pipe_stdin(self):
111 - script = pytest.REPO_ROOT / "bin/pkgcheck"
112 - result = ProfileWarning("profile warning: foo")
113 - with tempfile.NamedTemporaryFile() as f:
114 - out = PlainTextFormatter(f)
115 + def test_replay_pipe_stdin(self, capsys):
116 + with tempfile.NamedTemporaryFile() as file:
117 + out = PlainTextFormatter(file)
118 with JsonStream(out) as reporter:
119 - reporter.report(result)
120 - f.seek(0)
121 - p = subprocess.run(
122 - [script, "replay", "-R", "StrReporter", "-"], stdin=f, stdout=subprocess.PIPE
123 - )
124 - assert p.stdout.decode() == "profile warning: foo\n"
125 - assert p.returncode == 0
126 + reporter.report(ProfileWarning("profile warning: foo"))
127 + file.seek(0)
128 +
129 + with open(file.name) as stdin, patch("sys.stdin", stdin), patch(
130 + "sys.argv", [*self.args, "-R", "StrReporter", "-"]
131 + ), pytest.raises(SystemExit) as excinfo:
132 + self.script()
133 + out, err = capsys.readouterr()
134 + assert not err
135 + assert out == "profile warning: foo\n"
136 + assert excinfo.value.code == 0