forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev-util/pkgcheck: fix missing bin/ for replay test
Closes: https://bugs.gentoo.org/888896 Signed-off-by: Arthur Zamarin <[email protected]>
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
dev-util/pkgcheck/files/pkgcheck-0.10.20-fix-replay-bin.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
test_pkgcheck_replay: fix test_replay_pipe_stdin from sdist | ||
|
||
Bug: https://bugs.gentoo.org/888896 | ||
Signed-off-by: Arthur Zamarin <[email protected]> | ||
--- a/tests/scripts/test_pkgcheck_replay.py | ||
+++ b/tests/scripts/test_pkgcheck_replay.py | ||
@@ -1,20 +1,18 @@ | ||
-import os | ||
-import subprocess | ||
import tempfile | ||
from functools import partial | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
+from snakeoil.formatters import PlainTextFormatter | ||
+ | ||
from pkgcheck import __title__ as project | ||
from pkgcheck.checks.profiles import ProfileWarning | ||
from pkgcheck.reporters import JsonStream | ||
from pkgcheck.scripts import run | ||
-from snakeoil.formatters import PlainTextFormatter | ||
|
||
|
||
class TestPkgcheckReplay: | ||
- | ||
- script = partial(run, project) | ||
+ script = staticmethod(partial(run, project)) | ||
|
||
@pytest.fixture(autouse=True) | ||
def _setup(self, testconfig): | ||
@@ -33,11 +31,11 @@ class TestPkgcheckReplay: | ||
|
||
def test_replay(self, capsys): | ||
result = ProfileWarning("profile warning: foo") | ||
- with tempfile.NamedTemporaryFile() as f: | ||
- out = PlainTextFormatter(f) | ||
+ with tempfile.NamedTemporaryFile() as file: | ||
+ out = PlainTextFormatter(file) | ||
with JsonStream(out) as reporter: | ||
reporter.report(result) | ||
- with patch("sys.argv", self.args + ["-R", "StrReporter", f.name]): | ||
+ with patch("sys.argv", self.args + ["-R", "StrReporter", file.name]): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
out, err = capsys.readouterr() | ||
@@ -47,13 +45,13 @@ class TestPkgcheckReplay: | ||
|
||
def test_corrupted_resuts(self, capsys): | ||
result = ProfileWarning("profile warning: foo") | ||
- with tempfile.NamedTemporaryFile() as f: | ||
- out = PlainTextFormatter(f) | ||
+ with tempfile.NamedTemporaryFile() as file: | ||
+ out = PlainTextFormatter(file) | ||
with JsonStream(out) as reporter: | ||
reporter.report(result) | ||
- f.write(b"corrupted") | ||
- f.seek(0) | ||
- with patch("sys.argv", self.args + ["-R", "StrReporter", f.name]): | ||
+ file.write(b"corrupted") | ||
+ file.seek(0) | ||
+ with patch("sys.argv", self.args + ["-R", "StrReporter", file.name]): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
out, err = capsys.readouterr() | ||
@@ -61,26 +59,28 @@ class TestPkgcheckReplay: | ||
assert excinfo.value.code == 2 | ||
|
||
def test_invalid_file(self, capsys): | ||
- with tempfile.NamedTemporaryFile(mode="wt") as f: | ||
- f.write("invalid file") | ||
- f.seek(0) | ||
- with patch("sys.argv", self.args + ["-R", "StrReporter", f.name]): | ||
+ with tempfile.NamedTemporaryFile(mode="wt") as file: | ||
+ file.write("invalid file") | ||
+ file.seek(0) | ||
+ with patch("sys.argv", self.args + ["-R", "StrReporter", file.name]): | ||
with pytest.raises(SystemExit) as excinfo: | ||
self.script() | ||
out, err = capsys.readouterr() | ||
assert err.strip() == "pkgcheck replay: error: invalid or unsupported replay file" | ||
assert excinfo.value.code == 2 | ||
|
||
- def test_replay_pipe_stdin(self): | ||
- script = pytest.REPO_ROOT / "bin/pkgcheck" | ||
- result = ProfileWarning("profile warning: foo") | ||
- with tempfile.NamedTemporaryFile() as f: | ||
- out = PlainTextFormatter(f) | ||
+ def test_replay_pipe_stdin(self, capsys): | ||
+ with tempfile.NamedTemporaryFile() as file: | ||
+ out = PlainTextFormatter(file) | ||
with JsonStream(out) as reporter: | ||
- reporter.report(result) | ||
- f.seek(0) | ||
- p = subprocess.run( | ||
- [script, "replay", "-R", "StrReporter", "-"], stdin=f, stdout=subprocess.PIPE | ||
- ) | ||
- assert p.stdout.decode() == "profile warning: foo\n" | ||
- assert p.returncode == 0 | ||
+ reporter.report(ProfileWarning("profile warning: foo")) | ||
+ file.seek(0) | ||
+ | ||
+ with open(file.name) as stdin, patch("sys.stdin", stdin), patch( | ||
+ "sys.argv", [*self.args, "-R", "StrReporter", "-"] | ||
+ ), pytest.raises(SystemExit) as excinfo: | ||
+ self.script() | ||
+ out, err = capsys.readouterr() | ||
+ assert not err | ||
+ assert out == "profile warning: foo\n" | ||
+ assert excinfo.value.code == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters