* [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: bin/, tests/scripts/
@ 2022-12-31 11:31 Arthur Zamarin
0 siblings, 0 replies; only message in thread
From: Arthur Zamarin @ 2022-12-31 11:31 UTC (permalink / raw
To: gentoo-commits
commit: c219e33c3cb40dceb5b3796e00dbd25b3c9dcf8a
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 31 11:19:02 2022 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 31 11:31:23 2022 +0000
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=c219e33c
test_pkgcheck_replay: fix test_replay_pipe_stdin from sdist
We don't ship `bin/` in the sdist, so we are unable to run the script
`bin/pkgcheck` from the sdist. Instead, use monkey-patching and `tool`
to run with stdin `pkgcheck replay`.
Bug: https://bugs.gentoo.org/888896
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
bin/pkgcheck | 1 -
tests/scripts/test_pkgcheck_replay.py | 58 +++++++++++++++++------------------
2 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/bin/pkgcheck b/bin/pkgcheck
deleted file mode 120000
index 78f990ec..00000000
--- a/bin/pkgcheck
+++ /dev/null
@@ -1 +0,0 @@
-../src/pkgcheck/scripts/__init__.py
\ No newline at end of file
diff --git a/tests/scripts/test_pkgcheck_replay.py b/tests/scripts/test_pkgcheck_replay.py
index c2aeda66..b6b7d606 100644
--- 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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-31 11:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-31 11:31 [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: bin/, tests/scripts/ Arthur Zamarin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox