From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E2EFA15838C for ; Fri, 26 Jan 2024 20:22:35 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8069DE29FE; Fri, 26 Jan 2024 20:22:34 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4643EE29FE for ; Fri, 26 Jan 2024 20:22:34 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1F9573433C5 for ; Fri, 26 Jan 2024 20:22:33 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AF47413AA for ; Fri, 26 Jan 2024 20:22:31 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1706300435.97df81b07a9dd8ae9b1b90b260f3c1533ef02ea7.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgdev:main commit in: tests/scripts/ X-VCS-Repository: proj/pkgcore/pkgdev X-VCS-Files: tests/scripts/test_pkgdev_bugs.py tests/scripts/test_pkgdev_commit.py tests/scripts/test_pkgdev_manifest.py tests/scripts/test_pkgdev_mask.py tests/scripts/test_pkgdev_push.py tests/scripts/test_pkgdev_showkw.py X-VCS-Directories: tests/scripts/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: 97df81b07a9dd8ae9b1b90b260f3c1533ef02ea7 X-VCS-Branch: main Date: Fri, 26 Jan 2024 20:22:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 8d8448b4-c723-4add-9e6c-e94debfc3cd7 X-Archives-Hash: a3687c61e7902bc51ae4e01b654e2b08 commit: 97df81b07a9dd8ae9b1b90b260f3c1533ef02ea7 Author: Arthur Zamarin gentoo org> AuthorDate: Fri Jan 26 20:20:35 2024 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Fri Jan 26 20:20:35 2024 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=97df81b0 reformat with black 24 Signed-off-by: Arthur Zamarin gentoo.org> tests/scripts/test_pkgdev_bugs.py | 3 +- tests/scripts/test_pkgdev_commit.py | 171 ++++++++++++++++++++++------------ tests/scripts/test_pkgdev_manifest.py | 12 ++- tests/scripts/test_pkgdev_mask.py | 130 +++++++++++++++++--------- tests/scripts/test_pkgdev_push.py | 36 ++++--- tests/scripts/test_pkgdev_showkw.py | 49 ++++++---- 6 files changed, 258 insertions(+), 143 deletions(-) diff --git a/tests/scripts/test_pkgdev_bugs.py b/tests/scripts/test_pkgdev_bugs.py index 641e5f0..3a61a89 100644 --- a/tests/scripts/test_pkgdev_bugs.py +++ b/tests/scripts/test_pkgdev_bugs.py @@ -51,8 +51,7 @@ class BugsSession: def __enter__(self): return self - def __exit__(self, *_args): - ... + def __exit__(self, *_args): ... def read(self): return json.dumps({"id": next(self.counter)}).encode("utf-8") diff --git a/tests/scripts/test_pkgdev_commit.py b/tests/scripts/test_pkgdev_commit.py index b2ec4be..ff93db8 100644 --- a/tests/scripts/test_pkgdev_commit.py +++ b/tests/scripts/test_pkgdev_commit.py @@ -194,8 +194,10 @@ class TestPkgdevCommit: def test_empty_repo(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location, commit=True) - with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( - git_repo.path + with ( + patch("sys.argv", self.args), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), ): self.script() assert excinfo.value.code == 2 @@ -212,9 +214,11 @@ class TestPkgdevCommit: with open(path, "w") as f: f.write("commit1") - with patch("sys.argv", self.args + ["-u", "-F", path]), pytest.raises( - SystemExit - ) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["-u", "-F", path]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) @@ -222,9 +226,12 @@ class TestPkgdevCommit: repo.create_ebuild("cat/pkg-1") git_repo.add_all("cat/pkg-1", commit=False) - with os_environ(GIT_EDITOR="sed -i '1s/1/2/'"), patch( - "sys.argv", self.args + ["-u", "-t", path] - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + os_environ(GIT_EDITOR="sed -i '1s/1/2/'"), + patch("sys.argv", self.args + ["-u", "-t", path]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) @@ -251,9 +258,11 @@ class TestPkgdevCommit: for i, opt in enumerate(["-M", "--message-template"], 1): repo.create_ebuild(f"cat/pkg-{i}") git_repo.add_all(f"cat/pkg-{i}", commit=False) - with patch("sys.argv", self.args + ["-u", opt, path]), pytest.raises( - SystemExit - ) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["-u", opt, path]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) @@ -274,9 +283,11 @@ class TestPkgdevCommit: for i, opt in enumerate(["-M", "--message-template"], 3): repo.create_ebuild(f"cat/pkg-{i}") git_repo.add_all(f"cat/pkg-{i}", commit=False) - with patch("sys.argv", self.args + ["-u", opt, path]), pytest.raises( - SystemExit - ) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["-u", opt, path]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) @@ -289,9 +300,11 @@ class TestPkgdevCommit: for i, opt in enumerate(["-M", "--message-template"], 5): repo.create_ebuild(f"cat/pkg-{i}") git_repo.add_all(f"cat/pkg-{i}", commit=False) - with patch("sys.argv", self.args + ["-u", opt, path]), pytest.raises( - SystemExit - ) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["-u", opt, path]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 2 out, err = capsys.readouterr() @@ -305,9 +318,11 @@ class TestPkgdevCommit: with open(ebuild_path, "a+") as f: f.write("# comment\n") - with patch("sys.argv", self.args + ["-u", "-m", "msg"]), pytest.raises( - SystemExit - ) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["-u", "-m", "msg"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -323,9 +338,11 @@ class TestPkgdevCommit: with open(ebuild_path, "a+") as f: f.write("# comment\n") - with patch("sys.argv", self.args + ["-u", "-m", "prefix: msg"]), pytest.raises( - SystemExit - ) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["-u", "-m", "prefix: msg"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -341,9 +358,12 @@ class TestPkgdevCommit: with open(ebuild_path, "a+") as f: f.write("# comment\n") - with os_environ(GIT_EDITOR="sed -i '1s/$/commit/'"), patch( - "sys.argv", self.args + ["-u"] - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + os_environ(GIT_EDITOR="sed -i '1s/$/commit/'"), + patch("sys.argv", self.args + ["-u"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -358,9 +378,11 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") def commit(): - with patch("sys.argv", self.args + ["-a", "-m", "msg"]), pytest.raises( - SystemExit - ) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["-a", "-m", "msg"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -441,9 +463,12 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") def commit(): - with os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), patch( - "sys.argv", self.args + ["-a"] - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), + patch("sys.argv", self.args + ["-a"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -592,9 +617,12 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") def commit(): - with os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), patch( - "sys.argv", self.args + ["-a"] - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), + patch("sys.argv", self.args + ["-a"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -670,9 +698,12 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") def commit(): - with os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), patch( - "sys.argv", self.args + ["-a"] - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), + patch("sys.argv", self.args + ["-a"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -859,9 +890,12 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") def commit(args): - with os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), patch( - "sys.argv", self.args + args - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"), + patch("sys.argv", self.args + args), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() @@ -886,8 +920,10 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") def commit(args): - with patch("sys.argv", self.args + args), pytest.raises(SystemExit) as excinfo, chdir( - git_repo.path + with ( + patch("sys.argv", self.args + args), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), ): self.script() assert excinfo.value.code == 0 @@ -928,8 +964,10 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") def commit(args): - with patch("sys.argv", self.args + args), pytest.raises(SystemExit) as excinfo, chdir( - git_repo.path + with ( + patch("sys.argv", self.args + args), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), ): self.script() assert excinfo.value.code == 0 @@ -1006,8 +1044,10 @@ class TestPkgdevCommit: for i, opt in enumerate(["-s", "--scan"], 1): repo.create_ebuild(f"cat/pkg-{i}") git_repo.add_all(f"cat/pkg-{i}", commit=False) - with patch("sys.argv", self.args + [opt]), pytest.raises(SystemExit) as excinfo, chdir( - git_repo.path + with ( + patch("sys.argv", self.args + [opt]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), ): self.script() assert excinfo.value.code == 0 @@ -1024,8 +1064,10 @@ class TestPkgdevCommit: # verify staged changes via `pkgcheck scan` before creating commit repo.create_ebuild("cat/pkg-1", license="") git_repo.add_all("cat/pkg-1", commit=False) - with patch("sys.argv", self.args + ["--scan"]), pytest.raises(SystemExit) as excinfo, chdir( - git_repo.path + with ( + patch("sys.argv", self.args + ["--scan"]), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), ): self.script() assert excinfo.value.code == 1 @@ -1043,9 +1085,12 @@ class TestPkgdevCommit: ) # ignore failures to create the commit - with patch("sys.argv", self.args + ["--scan", "--ask"]), patch( - "sys.stdin", StringIO("y\n") - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", self.args + ["--scan", "--ask"]), + patch("sys.stdin", StringIO("y\n")), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() assert excinfo.value.code == 0 @@ -1066,9 +1111,11 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") repo.create_ebuild("cat/pkg-1", license="") git_repo.add_all("cat/pkg-1", commit=False) - with patch( - "sys.argv", ["pkgdev", "commit", "--config", config_file] + self.scan_args - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", ["pkgdev", "commit", "--config", config_file] + self.scan_args), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() out, err = capsys.readouterr() assert excinfo.value.code == 1 @@ -1092,9 +1139,11 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") repo.create_ebuild("cat/pkg-1", license="") git_repo.add_all("cat/pkg-1", commit=False) - with patch( - "sys.argv", ["pkgdev", "commit", "--config", config_file] + self.scan_args - ), pytest.raises(SystemExit) as excinfo, chdir(git_repo.path): + with ( + patch("sys.argv", ["pkgdev", "commit", "--config", config_file] + self.scan_args), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), + ): self.script() out, err = capsys.readouterr() assert excinfo.value.code == 1 @@ -1107,8 +1156,10 @@ class TestPkgdevCommit: git_repo.add_all("cat/pkg-0") repo.create_ebuild("cat/pkg-1", eapi="-1") git_repo.add_all("cat/pkg-1", commit=False) - with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( - git_repo.path + with ( + patch("sys.argv", self.args), + pytest.raises(SystemExit) as excinfo, + chdir(git_repo.path), ): self.script() assert excinfo.value.code == 1 diff --git a/tests/scripts/test_pkgdev_manifest.py b/tests/scripts/test_pkgdev_manifest.py index e7cfcaf..d6bb34d 100644 --- a/tests/scripts/test_pkgdev_manifest.py +++ b/tests/scripts/test_pkgdev_manifest.py @@ -178,8 +178,10 @@ class TestPkgdevManifest: def test_good_manifest(self, capsys, repo): repo.create_ebuild("cat/pkg-0") - with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( - repo.location + with ( + patch("sys.argv", self.args), + pytest.raises(SystemExit) as excinfo, + chdir(repo.location), ): self.script() assert excinfo.value.code == 0 @@ -189,8 +191,10 @@ class TestPkgdevManifest: def test_bad_manifest(self, capsys, repo): repo.create_ebuild("cat/pkg-0") repo.create_ebuild("cat/pkg-1", eapi="-1") - with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( - repo.location + with ( + patch("sys.argv", self.args), + pytest.raises(SystemExit) as excinfo, + chdir(repo.location), ): self.script() assert excinfo.value.code == 1 diff --git a/tests/scripts/test_pkgdev_mask.py b/tests/scripts/test_pkgdev_mask.py index c7195fe..d723535 100644 --- a/tests/scripts/test_pkgdev_mask.py +++ b/tests/scripts/test_pkgdev_mask.py @@ -121,55 +121,76 @@ class TestPkgdevMask: assert self.profile.masks == frozenset() def test_nonexistent_editor(self, capsys): - with os_environ("VISUAL", EDITOR="12345"), patch( - "sys.argv", self.args + ["cat/pkg"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="12345"), + patch("sys.argv", self.args + ["cat/pkg"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() out, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: nonexistent editor: '12345'" def test_nonexistent_visual(self, capsys): - with os_environ("EDITOR", VISUAL="12345"), patch( - "sys.argv", self.args + ["cat/pkg"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("EDITOR", VISUAL="12345"), + patch("sys.argv", self.args + ["cat/pkg"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() out, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: nonexistent editor: '12345'" def test_failed_editor(self, capsys): - with os_environ("VISUAL", EDITOR="sed -i 's///'"), patch( - "sys.argv", self.args + ["cat/pkg"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i 's///'"), + patch("sys.argv", self.args + ["cat/pkg"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() out, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: failed writing mask comment" def test_empty_mask_comment(self, capsys): - with os_environ("VISUAL", EDITOR="sed -i 's/#/#/'"), patch( - "sys.argv", self.args + ["cat/pkg"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i 's/#/#/'"), + patch("sys.argv", self.args + ["cat/pkg"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() out, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: empty mask comment" def test_mask_cwd(self): - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path, "cat/pkg")): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path, "cat/pkg")), + ): self.script() assert self.profile.masks == frozenset([atom_cls("cat/pkg")]) def test_mask_target(self): - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args + ["cat/pkg"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args + ["cat/pkg"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() assert self.profile.masks == frozenset([atom_cls("cat/pkg")]) def test_mask_ebuild_path(self): - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args + ["cat/pkg/pkg-0.ebuild"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args + ["cat/pkg/pkg-0.ebuild"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() assert self.profile.masks == frozenset([atom_cls("=cat/pkg-0")]) @@ -184,9 +205,12 @@ class TestPkgdevMask: ) ) - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args + ["=cat/pkg-0"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args + ["=cat/pkg-0"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() assert self.profile.masks == frozenset([atom_cls("cat/masked"), atom_cls("=cat/pkg-0")]) @@ -209,9 +233,12 @@ class TestPkgdevMask: ) ) - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args + ["=cat/pkg-0"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args + ["=cat/pkg-0"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() _, err = capsys.readouterr() assert "invalid mask entry header, lineno 9" in err @@ -238,9 +265,12 @@ class TestPkgdevMask: ) ) - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args + ["=cat/pkg-0"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args + ["=cat/pkg-0"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() _, err = capsys.readouterr() assert "pkgdev mask: error: invalid author, lineno 5" in err @@ -248,9 +278,12 @@ class TestPkgdevMask: def test_last_rites(self): for rflag in ("-r", "--rites"): for args in ([rflag], [rflag, "14"]): - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args + ["cat/pkg"] + args - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args + ["cat/pkg"] + args), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() days = 30 if len(args) == 1 else int(args[1]) @@ -271,12 +304,13 @@ class TestPkgdevMask: def test_last_rites_with_email(self, tmp_path): output_file = tmp_path / "mail.txt" for rflag in ("-r", "--rites"): - with os_environ( - "VISUAL", EDITOR="sed -i '1s/$/mask comment/'", MAILER=f"> {output_file} echo" - ), patch("sys.argv", self.args + ["cat/pkg", rflag, "--email"]), pytest.raises( - SystemExit - ), chdir( - pjoin(self.repo.path) + with ( + os_environ( + "VISUAL", EDITOR="sed -i '1s/$/mask comment/'", MAILER=f"> {output_file} echo" + ), + patch("sys.argv", self.args + ["cat/pkg", rflag, "--email"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), ): self.script() out = output_file.read_text() @@ -287,9 +321,12 @@ class TestPkgdevMask: @pytest.mark.skipif(sys.platform == "darwin", reason="no xdg-email on mac os") def test_last_email_bad_mailer(self, capsys): for rflag in ("-r", "--rites"): - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'", MAILER="false"), patch( - "sys.argv", self.args + ["cat/pkg", rflag, "--email"] - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'", MAILER="false"), + patch("sys.argv", self.args + ["cat/pkg", rflag, "--email"]), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() _, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: failed opening email composer" @@ -304,9 +341,12 @@ class TestPkgdevMask: args = [] for bug_num in bug_nums: args += [bflag, bug_num] - with os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), patch( - "sys.argv", self.args + ["cat/pkg"] + args - ), pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): + with ( + os_environ("VISUAL", EDITOR="sed -i '1s/$/mask comment/'"), + patch("sys.argv", self.args + ["cat/pkg"] + args), + pytest.raises(SystemExit), + chdir(pjoin(self.repo.path)), + ): self.script() assert self.masks_path.read_text() == textwrap.dedent( diff --git a/tests/scripts/test_pkgdev_push.py b/tests/scripts/test_pkgdev_push.py index fb4faa3..a84c175 100644 --- a/tests/scripts/test_pkgdev_push.py +++ b/tests/scripts/test_pkgdev_push.py @@ -90,8 +90,10 @@ class TestPkgdevPush: self.child_repo.create_ebuild("cat/pkg-1") self.child_git_repo.add_all("cat/pkg-1") - with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( - self.child_git_repo.path + with ( + patch("sys.argv", self.args), + pytest.raises(SystemExit) as excinfo, + chdir(self.child_git_repo.path), ): self.script() assert excinfo.value.code == 0 @@ -101,8 +103,10 @@ class TestPkgdevPush: self.child_git_repo.add_all("cat/pkg-1") # failed scans don't push commits - with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( - self.child_git_repo.path + with ( + patch("sys.argv", self.args), + pytest.raises(SystemExit) as excinfo, + chdir(self.child_git_repo.path), ): self.script() assert excinfo.value.code == 1 @@ -119,9 +123,12 @@ class TestPkgdevPush: ) # but failures can be ignored to push anyway - with patch("sys.argv", self.args + ["--ask"]), patch( - "sys.stdin", StringIO("y\n") - ), pytest.raises(SystemExit) as excinfo, chdir(self.child_git_repo.path): + with ( + patch("sys.argv", self.args + ["--ask"]), + patch("sys.stdin", StringIO("y\n")), + pytest.raises(SystemExit) as excinfo, + chdir(self.child_git_repo.path), + ): self.script() assert excinfo.value.code == 0 @@ -133,17 +140,22 @@ class TestPkgdevPush: self.child_git_repo.add_all("cat/pkg-1") # scans with warnings ask for confirmation before pushing with "--ask" - with patch("sys.argv", self.args + ["--ask"]), patch( - "sys.stdin", StringIO("n\n") - ), pytest.raises(SystemExit) as excinfo, chdir(self.child_git_repo.path): + with ( + patch("sys.argv", self.args + ["--ask"]), + patch("sys.stdin", StringIO("n\n")), + pytest.raises(SystemExit) as excinfo, + chdir(self.child_git_repo.path), + ): self.script() assert excinfo.value.code == 1 out, err = capsys.readouterr() assert "EmptyFile" in out # but without "--ask" it still pushes - with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( - self.child_git_repo.path + with ( + patch("sys.argv", self.args), + pytest.raises(SystemExit) as excinfo, + chdir(self.child_git_repo.path), ): self.script() assert excinfo.value.code == 0 diff --git a/tests/scripts/test_pkgdev_showkw.py b/tests/scripts/test_pkgdev_showkw.py index c30a4f0..8dadb5d 100644 --- a/tests/scripts/test_pkgdev_showkw.py +++ b/tests/scripts/test_pkgdev_showkw.py @@ -86,9 +86,10 @@ class TestPkgdevShowkw: return repo def _run_and_parse(self, capsys, *args): - with patch("sys.argv", [*self.base_args, "--format", "presto", *args]), pytest.raises( - SystemExit - ) as excinfo: + with ( + patch("sys.argv", [*self.base_args, "--format", "presto", *args]), + pytest.raises(SystemExit) as excinfo, + ): self.script() assert excinfo.value.code is None out, err = capsys.readouterr() @@ -103,9 +104,10 @@ class TestPkgdevShowkw: def test_match(self, capsys, make_repo): repo = self._create_repo(make_repo) repo.create_ebuild("foo/bar-0") - with patch("sys.argv", [*self.base_args, "-r", repo.location, "foo/bar"]), pytest.raises( - SystemExit - ) as excinfo: + with ( + patch("sys.argv", [*self.base_args, "-r", repo.location, "foo/bar"]), + pytest.raises(SystemExit) as excinfo, + ): self.script() assert excinfo.value.code is None out, err = capsys.readouterr() @@ -115,9 +117,10 @@ class TestPkgdevShowkw: def test_match_short_name(self, capsys, make_repo): repo = self._create_repo(make_repo) repo.create_ebuild("foo/bar-0") - with patch("sys.argv", [*self.base_args, "-r", repo.location, "bar"]), pytest.raises( - SystemExit - ) as excinfo: + with ( + patch("sys.argv", [*self.base_args, "-r", repo.location, "bar"]), + pytest.raises(SystemExit) as excinfo, + ): self.script() assert excinfo.value.code is None out, err = capsys.readouterr() @@ -127,9 +130,11 @@ class TestPkgdevShowkw: def test_match_cwd_repo(self, capsys, make_repo): repo = self._create_repo(make_repo) repo.create_ebuild("foo/bar-0") - with patch("sys.argv", [*self.base_args, "foo/bar"]), pytest.raises( - SystemExit - ) as excinfo, chdir(repo.location): + with ( + patch("sys.argv", [*self.base_args, "foo/bar"]), + pytest.raises(SystemExit) as excinfo, + chdir(repo.location), + ): self.script() assert excinfo.value.code is None out, err = capsys.readouterr() @@ -139,8 +144,10 @@ class TestPkgdevShowkw: def test_match_cwd_pkg(self, capsys, make_repo): repo = self._create_repo(make_repo) repo.create_ebuild("foo/bar-0") - with patch("sys.argv", self.base_args), pytest.raises(SystemExit) as excinfo, chdir( - repo.location + "/foo/bar" + with ( + patch("sys.argv", self.base_args), + pytest.raises(SystemExit) as excinfo, + chdir(repo.location + "/foo/bar"), ): self.script() assert excinfo.value.code is None @@ -149,9 +156,10 @@ class TestPkgdevShowkw: def test_no_matches(self, capsys, make_repo): repo = self._create_repo(make_repo) - with patch("sys.argv", [*self.base_args, "-r", repo.location, "foo/bar"]), pytest.raises( - SystemExit - ) as excinfo: + with ( + patch("sys.argv", [*self.base_args, "-r", repo.location, "foo/bar"]), + pytest.raises(SystemExit) as excinfo, + ): self.script() assert excinfo.value.code == 1 out, err = capsys.readouterr() @@ -212,9 +220,10 @@ class TestPkgdevShowkw: repo = self._create_repo(make_repo) repo.create_ebuild("foo/bar-0", keywords=("amd64", "~ia64", "~mips", "~x86")) repo.create_ebuild("foo/bar-1", keywords=("~amd64", "~ia64", "~mips", "x86")) - with patch( - "sys.argv", [*self.base_args, "-r", repo.location, "foo/bar", "--collapse", arg] - ), pytest.raises(SystemExit) as excinfo: + with ( + patch("sys.argv", [*self.base_args, "-r", repo.location, "foo/bar", "--collapse", arg]), + pytest.raises(SystemExit) as excinfo, + ): self.script() out, err = capsys.readouterr() assert excinfo.value.code is None