From 895f5ec3c2a760b8b8b129191e948efc1ebeb575 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Sat, 4 Mar 2023 16:53:29 +0200 Subject: format using black Signed-off-by: Arthur Zamarin --- tests/conftest.py | 2 +- tests/scripts/test_cli.py | 89 ++- tests/scripts/test_pkgdev.py | 13 +- tests/scripts/test_pkgdev_bugs.py | 87 ++- tests/scripts/test_pkgdev_commit.py | 1329 +++++++++++++++++---------------- tests/scripts/test_pkgdev_manifest.py | 149 ++-- tests/scripts/test_pkgdev_mask.py | 349 +++++---- tests/scripts/test_pkgdev_push.py | 116 +-- tests/scripts/test_pkgdev_showkw.py | 194 ++--- tests/test_git.py | 15 +- tests/test_mangle.py | 47 +- 11 files changed, 1241 insertions(+), 1149 deletions(-) (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index 1a56652..dc42ba5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,7 @@ from pkgdev.cli import Tool from pkgdev.scripts import pkgdev from snakeoil.cli import arghparse -pytest_plugins = ['pkgcore'] +pytest_plugins = ["pkgcore"] @pytest.fixture(scope="session") diff --git a/tests/scripts/test_cli.py b/tests/scripts/test_cli.py index 752f36d..6b54a39 100644 --- a/tests/scripts/test_cli.py +++ b/tests/scripts/test_cli.py @@ -6,11 +6,10 @@ from snakeoil.cli import arghparse class TestConfigFileParser: - @pytest.fixture(autouse=True) def _create_argparser(self, tmp_path): - self.config_file = str(tmp_path / 'config') - self.parser = arghparse.ArgumentParser(prog='pkgdev cli_test') + self.config_file = str(tmp_path / "config") + self.parser = arghparse.ArgumentParser(prog="pkgdev cli_test") self.namespace = arghparse.Namespace() self.config_parser = cli.ConfigFileParser(self.parser) @@ -22,69 +21,85 @@ class TestConfigFileParser: def test_ignored_configs(self): # nonexistent config files are ignored - config = self.config_parser.parse_config(('foo', 'bar')) + config = self.config_parser.parse_config(("foo", "bar")) assert config.sections() == [] def test_bad_config_format_no_section(self, capsys): - with open(self.config_file, 'w') as f: - f.write('foobar\n') + with open(self.config_file, "w") as f: + f.write("foobar\n") with pytest.raises(SystemExit) as excinfo: self.config_parser.parse_config((self.config_file,)) out, err = capsys.readouterr() assert not out - assert 'parsing config file failed: File contains no section headers' in err + assert "parsing config file failed: File contains no section headers" in err assert self.config_file in err assert excinfo.value.code == 2 def test_bad_config_format(self, capsys): - with open(self.config_file, 'w') as f: - f.write(textwrap.dedent(""" - [DEFAULT] - foobar - """)) + with open(self.config_file, "w") as f: + f.write( + textwrap.dedent( + """ + [DEFAULT] + foobar + """ + ) + ) with pytest.raises(SystemExit) as excinfo: self.config_parser.parse_config((self.config_file,)) out, err = capsys.readouterr() assert not out - assert 'parsing config file failed: Source contains parsing errors' in err + assert "parsing config file failed: Source contains parsing errors" in err assert excinfo.value.code == 2 def test_nonexistent_config_options(self, capsys): """Nonexistent parser arguments don't cause errors.""" - with open(self.config_file, 'w') as f: - f.write(textwrap.dedent(""" - [DEFAULT] - cli_test.foo=bar - """)) + with open(self.config_file, "w") as f: + f.write( + textwrap.dedent( + """ + [DEFAULT] + cli_test.foo=bar + """ + ) + ) with pytest.raises(SystemExit) as excinfo: self.config_parser.parse_config_options(None, configs=(self.config_file,)) out, err = capsys.readouterr() assert not out - assert 'failed loading config: unknown arguments: --foo=bar' in err + assert "failed loading config: unknown arguments: --foo=bar" in err assert excinfo.value.code == 2 def test_config_options_other_prog(self): - self.parser.add_argument('--foo') - with open(self.config_file, 'w') as f: - f.write(textwrap.dedent(""" - [DEFAULT] - other.foo=bar - """)) - namespace = self.parser.parse_args(['--foo', 'foo']) - assert namespace.foo == 'foo' + self.parser.add_argument("--foo") + with open(self.config_file, "w") as f: + f.write( + textwrap.dedent( + """ + [DEFAULT] + other.foo=bar + """ + ) + ) + namespace = self.parser.parse_args(["--foo", "foo"]) + assert namespace.foo == "foo" # config args don't override not matching namespace attrs namespace = self.config_parser.parse_config_options(namespace, configs=[self.config_file]) - assert namespace.foo == 'foo' + assert namespace.foo == "foo" def test_config_options(self): - self.parser.add_argument('--foo') - with open(self.config_file, 'w') as f: - f.write(textwrap.dedent(""" - [DEFAULT] - cli_test.foo=bar - """)) - namespace = self.parser.parse_args(['--foo', 'foo']) - assert namespace.foo == 'foo' + self.parser.add_argument("--foo") + with open(self.config_file, "w") as f: + f.write( + textwrap.dedent( + """ + [DEFAULT] + cli_test.foo=bar + """ + ) + ) + namespace = self.parser.parse_args(["--foo", "foo"]) + assert namespace.foo == "foo" # config args override matching namespace attrs namespace = self.config_parser.parse_config_options(namespace, configs=[self.config_file]) - assert namespace.foo == 'bar' + assert namespace.foo == "bar" diff --git a/tests/scripts/test_pkgdev.py b/tests/scripts/test_pkgdev.py index 7a64c17..6aa25f8 100644 --- a/tests/scripts/test_pkgdev.py +++ b/tests/scripts/test_pkgdev.py @@ -12,27 +12,27 @@ def test_script_run(capsys): """Test regular code path for running scripts.""" script = partial(run, project) - with patch(f'{project}.scripts.import_module') as import_module: + with patch(f"{project}.scripts.import_module") as import_module: import_module.side_effect = ImportError("baz module doesn't exist") # default error path when script import fails - with patch('sys.argv', [project]): + with patch("sys.argv", [project]): with pytest.raises(SystemExit) as excinfo: script() assert excinfo.value.code == 1 out, err = capsys.readouterr() - err = err.strip().split('\n') + err = err.strip().split("\n") assert len(err) == 3 assert err[0] == "Failed importing: baz module doesn't exist!" assert err[1].startswith(f"Verify that {project} and its deps") assert err[2] == "Add --debug to the commandline for a traceback." # running with --debug should raise an ImportError when there are issues - with patch('sys.argv', [project, '--debug']): + with patch("sys.argv", [project, "--debug"]): with pytest.raises(ImportError): script() out, err = capsys.readouterr() - err = err.strip().split('\n') + err = err.strip().split("\n") assert len(err) == 2 assert err[0] == "Failed importing: baz module doesn't exist!" assert err[1].startswith(f"Verify that {project} and its deps") @@ -41,11 +41,10 @@ def test_script_run(capsys): class TestPkgdev: - script = staticmethod(partial(run, project)) def test_version(self, capsys): - with patch('sys.argv', [project, '--version']): + with patch("sys.argv", [project, "--version"]): with pytest.raises(SystemExit) as excinfo: self.script() assert excinfo.value.code == 0 diff --git a/tests/scripts/test_pkgdev_bugs.py b/tests/scripts/test_pkgdev_bugs.py index f23051e..708ff39 100644 --- a/tests/scripts/test_pkgdev_bugs.py +++ b/tests/scripts/test_pkgdev_bugs.py @@ -13,29 +13,34 @@ from pkgdev.scripts import pkgdev_bugs as bugs from snakeoil.formatters import PlainTextFormatter from snakeoil.osutils import pjoin + def mk_pkg(repo, cpvstr, maintainers, **kwargs): kwargs.setdefault("KEYWORDS", ["~amd64"]) pkgdir = os.path.dirname(repo.create_ebuild(cpvstr, **kwargs)) # stub metadata - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent(f"""\ - - - - - {' '.join(f'{maintainer}@gentoo.org' for maintainer in maintainers)} - - - """)) + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + f"""\ + + + + + {' '.join(f'{maintainer}@gentoo.org' for maintainer in maintainers)} + + + """ + ) + ) def mk_repo(repo): - mk_pkg(repo, 'cat/u-0', ['dev1']) - mk_pkg(repo, 'cat/z-0', [], RDEPEND=['cat/u', 'cat/x']) - mk_pkg(repo, 'cat/v-0', ['dev2'], RDEPEND='cat/x') - mk_pkg(repo, 'cat/y-0', ['dev1'], RDEPEND=['cat/z', 'cat/v']) - mk_pkg(repo, 'cat/x-0', ['dev3'], RDEPEND='cat/y') - mk_pkg(repo, 'cat/w-0', ['dev3'], RDEPEND='cat/x') + mk_pkg(repo, "cat/u-0", ["dev1"]) + mk_pkg(repo, "cat/z-0", [], RDEPEND=["cat/u", "cat/x"]) + mk_pkg(repo, "cat/v-0", ["dev2"], RDEPEND="cat/x") + mk_pkg(repo, "cat/y-0", ["dev1"], RDEPEND=["cat/z", "cat/v"]) + mk_pkg(repo, "cat/x-0", ["dev3"], RDEPEND="cat/y") + mk_pkg(repo, "cat/w-0", ["dev3"], RDEPEND="cat/x") class BugsSession: @@ -50,7 +55,7 @@ class BugsSession: ... def read(self): - return json.dumps({'id': next(self.counter)}).encode('utf-8') + return json.dumps({"id": next(self.counter)}).encode("utf-8") def __call__(self, request, *_args, **_kwargs): self.calls.append(json.loads(request.data)) @@ -61,44 +66,44 @@ class TestBugFiling: def test_bug_filing(self, repo): mk_repo(repo) session = BugsSession() - pkg = max(repo.itermatch(atom('=cat/u-0'))) - with patch('pkgdev.scripts.pkgdev_bugs.urllib.urlopen', session): - bugs.GraphNode(((pkg, {'*'}), )).file_bug("API", frozenset()) + pkg = max(repo.itermatch(atom("=cat/u-0"))) + with patch("pkgdev.scripts.pkgdev_bugs.urllib.urlopen", session): + bugs.GraphNode(((pkg, {"*"}),)).file_bug("API", frozenset()) assert len(session.calls) == 1 call = session.calls[0] - assert call['Bugzilla_api_key'] == 'API' - assert call['summary'] == 'cat/u-0: stablereq' - assert call['assigned_to'] == 'dev1@gentoo.org' - assert not call['cc'] - assert call['cf_stabilisation_atoms'] == '=cat/u-0 *' - assert not call['depends_on'] + assert call["Bugzilla_api_key"] == "API" + assert call["summary"] == "cat/u-0: stablereq" + assert call["assigned_to"] == "dev1@gentoo.org" + assert not call["cc"] + assert call["cf_stabilisation_atoms"] == "=cat/u-0 *" + assert not call["depends_on"] def test_bug_filing_maintainer_needed(self, repo): mk_repo(repo) session = BugsSession() - pkg = max(repo.itermatch(atom('=cat/z-0'))) - with patch('pkgdev.scripts.pkgdev_bugs.urllib.urlopen', session): - bugs.GraphNode(((pkg, {'*'}), )).file_bug("API", frozenset()) + pkg = max(repo.itermatch(atom("=cat/z-0"))) + with patch("pkgdev.scripts.pkgdev_bugs.urllib.urlopen", session): + bugs.GraphNode(((pkg, {"*"}),)).file_bug("API", frozenset()) assert len(session.calls) == 1 call = session.calls[0] - assert call['assigned_to'] == 'maintainer-needed@gentoo.org' - assert not call['cc'] + assert call["assigned_to"] == "maintainer-needed@gentoo.org" + assert not call["cc"] def test_bug_filing_multiple_pkgs(self, repo): mk_repo(repo) session = BugsSession() - pkgX = max(repo.itermatch(atom('=cat/x-0'))) - pkgY = max(repo.itermatch(atom('=cat/y-0'))) - pkgZ = max(repo.itermatch(atom('=cat/z-0'))) + pkgX = max(repo.itermatch(atom("=cat/x-0"))) + pkgY = max(repo.itermatch(atom("=cat/y-0"))) + pkgZ = max(repo.itermatch(atom("=cat/z-0"))) dep = bugs.GraphNode((), 2) - node = bugs.GraphNode(((pkgX, {'*'}), (pkgY, {'*'}), (pkgZ, {'*'}))) + node = bugs.GraphNode(((pkgX, {"*"}), (pkgY, {"*"}), (pkgZ, {"*"}))) node.edges.add(dep) - with patch('pkgdev.scripts.pkgdev_bugs.urllib.urlopen', session): + with patch("pkgdev.scripts.pkgdev_bugs.urllib.urlopen", session): node.file_bug("API", frozenset()) assert len(session.calls) == 1 call = session.calls[0] - assert call['summary'] == 'cat/x-0, cat/y-0, cat/z-0: stablereq' - assert call['assigned_to'] == 'dev3@gentoo.org' - assert call['cc'] == ['dev1@gentoo.org'] - assert call['cf_stabilisation_atoms'] == '=cat/x-0 *\n=cat/y-0 *\n=cat/z-0 *' - assert call['depends_on'] == [2] + assert call["summary"] == "cat/x-0, cat/y-0, cat/z-0: stablereq" + assert call["assigned_to"] == "dev3@gentoo.org" + assert call["cc"] == ["dev1@gentoo.org"] + assert call["cf_stabilisation_atoms"] == "=cat/x-0 *\n=cat/y-0 *\n=cat/z-0 *" + assert call["depends_on"] == [2] diff --git a/tests/scripts/test_pkgdev_commit.py b/tests/scripts/test_pkgdev_commit.py index 7ca9c0d..4655f5f 100644 --- a/tests/scripts/test_pkgdev_commit.py +++ b/tests/scripts/test_pkgdev_commit.py @@ -14,1029 +14,1084 @@ from snakeoil.osutils import pjoin class TestPkgdevCommitParseArgs: - def test_non_repo_cwd(self, capsys, tool): with pytest.raises(SystemExit) as excinfo: - tool.parse_args(['commit']) + tool.parse_args(["commit"]) assert excinfo.value.code == 2 out, err = capsys.readouterr() - assert err.strip() == 'pkgdev commit: error: not in ebuild repo' + assert err.strip() == "pkgdev commit: error: not in ebuild repo" def test_bad_repo_cwd(self, make_repo, capsys, tool): - repo = make_repo(masters=('nonexistent',)) - with pytest.raises(SystemExit) as excinfo, \ - chdir(repo.location): - tool.parse_args(['commit']) + repo = make_repo(masters=("nonexistent",)) + with pytest.raises(SystemExit) as excinfo, chdir(repo.location): + tool.parse_args(["commit"]) assert excinfo.value.code == 2 out, err = capsys.readouterr() - assert err.strip().startswith('pkgdev commit: error: repo init failed') + assert err.strip().startswith("pkgdev commit: error: repo init failed") def test_non_git_repo_cwd(self, repo, capsys, tool): - with pytest.raises(SystemExit) as excinfo, \ - chdir(repo.location): - tool.parse_args(['commit']) + with pytest.raises(SystemExit) as excinfo, chdir(repo.location): + tool.parse_args(["commit"]) assert excinfo.value.code == 2 out, err = capsys.readouterr() - assert err.strip() == 'pkgdev commit: error: not in git repo' + assert err.strip() == "pkgdev commit: error: not in git repo" def test_non_ebuild_git_repo_cwd(self, make_repo, git_repo, capsys, tool): - os.mkdir(pjoin(git_repo.path, 'repo')) - repo = make_repo(pjoin(git_repo.path, 'repo')) - with pytest.raises(SystemExit) as excinfo, \ - chdir(repo.location): - tool.parse_args(['commit']) + os.mkdir(pjoin(git_repo.path, "repo")) + repo = make_repo(pjoin(git_repo.path, "repo")) + with pytest.raises(SystemExit) as excinfo, chdir(repo.location): + tool.parse_args(["commit"]) assert excinfo.value.code == 2 out, err = capsys.readouterr() - assert err.strip() == 'pkgdev commit: error: not in ebuild git repo' + assert err.strip() == "pkgdev commit: error: not in ebuild git repo" def test_commit_signing(self, repo, make_git_repo, tool): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0', commit=False) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0", commit=False) # signed commits aren't enabled by default with chdir(repo.location): - options, _ = tool.parse_args(['commit', '-u']) - assert '--signoff' not in options.commit_args - assert '--gpg-sign' not in options.commit_args + options, _ = tool.parse_args(["commit", "-u"]) + assert "--signoff" not in options.commit_args + assert "--gpg-sign" not in options.commit_args - options, _ = tool.parse_args(['commit', '-u', '--signoff']) - assert '--signoff' in options.commit_args - assert '--gpg-sign' not in options.commit_args + options, _ = tool.parse_args(["commit", "-u", "--signoff"]) + assert "--signoff" in options.commit_args + assert "--gpg-sign" not in options.commit_args # signed commits enabled by layout.conf setting - with open(pjoin(git_repo.path, 'metadata/layout.conf'), 'a+') as f: - f.write('sign-commits = true\n') + with open(pjoin(git_repo.path, "metadata/layout.conf"), "a+") as f: + f.write("sign-commits = true\n") with chdir(repo.location): - options, _ = tool.parse_args(['commit', '-u']) - assert '--signoff' not in options.commit_args - assert '--gpg-sign' in options.commit_args + options, _ = tool.parse_args(["commit", "-u"]) + assert "--signoff" not in options.commit_args + assert "--gpg-sign" in options.commit_args - options, _ = tool.parse_args(['commit', '-u', '--signoff']) - assert '--signoff' in options.commit_args - assert '--gpg-sign' in options.commit_args + options, _ = tool.parse_args(["commit", "-u", "--signoff"]) + assert "--signoff" in options.commit_args + assert "--gpg-sign" in options.commit_args def test_git_commit_args(self, repo, make_git_repo, tool): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0', commit=False) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0", commit=False) with chdir(repo.location): for opt, expected in ( - ('-n', '--dry-run'), - ('--dry-run', '--dry-run'), - ('-v', '-v'), - ('--verbose', '-v'), - ('-e', '--edit'), - ('--edit', '--edit'), - ): - options, _ = tool.parse_args(['commit', opt]) + ("-n", "--dry-run"), + ("--dry-run", "--dry-run"), + ("-v", "-v"), + ("--verbose", "-v"), + ("-e", "--edit"), + ("--edit", "--edit"), + ): + options, _ = tool.parse_args(["commit", opt]) assert expected in options.commit_args def test_git_commit_args_passthrough(self, repo, make_git_repo, tool): """Unknown arguments for ``pkgdev commit`` are passed to ``git commit``.""" git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0', commit=False) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0", commit=False) with chdir(repo.location): - for opt in ('--author="A U Thor "', '-p'): - options, _ = tool.parse_args(['commit', opt]) + for opt in ('--author="A U Thor "', "-p"): + options, _ = tool.parse_args(["commit", opt]) assert options.commit_args == [opt] def test_scan_args(self, repo, make_git_repo, tool): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0', commit=False) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0", commit=False) # pkgcheck isn't run in verbose mode by default with chdir(repo.location): - options, _ = tool.parse_args(['commit']) - assert '-v' not in options.scan_args + options, _ = tool.parse_args(["commit"]) + assert "-v" not in options.scan_args # verbosity level is passed down to pkgcheck with chdir(repo.location): - options, _ = tool.parse_args(['commit', '-v']) - assert '-v' in options.scan_args + options, _ = tool.parse_args(["commit", "-v"]) + assert "-v" in options.scan_args def test_commit_tags(self, capsys, repo, make_git_repo, tool): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0', commit=False) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0", commit=False) with chdir(repo.location): # bug IDs - for opt in ('-b', '--bug'): - options, _ = tool.parse_args(['commit', opt, '1']) - assert options.footer == {('Bug', 'https://bugs.gentoo.org/1')} + for opt in ("-b", "--bug"): + options, _ = tool.parse_args(["commit", opt, "1"]) + assert options.footer == {("Bug", "https://bugs.gentoo.org/1")} # bug URLs - for opt in ('-b', '--bug'): - options, _ = tool.parse_args(['commit', opt, 'https://bugs.gentoo.org/2']) - assert options.footer == {('Bug', 'https://bugs.gentoo.org/2')} + for opt in ("-b", "--bug"): + options, _ = tool.parse_args(["commit", opt, "https://bugs.gentoo.org/2"]) + assert options.footer == {("Bug", "https://bugs.gentoo.org/2")} # bug IDs - for opt in ('-c', '--closes'): - options, _ = tool.parse_args(['commit', opt, '1']) - assert options.footer == {('Closes', 'https://bugs.gentoo.org/1')} + for opt in ("-c", "--closes"): + options, _ = tool.parse_args(["commit", opt, "1"]) + assert options.footer == {("Closes", "https://bugs.gentoo.org/1")} # bug URLs - for opt in ('-c', '--closes'): - options, _ = tool.parse_args(['commit', opt, 'https://bugs.gentoo.org/2']) - assert options.footer == {('Closes', 'https://bugs.gentoo.org/2')} + for opt in ("-c", "--closes"): + options, _ = tool.parse_args(["commit", opt, "https://bugs.gentoo.org/2"]) + assert options.footer == {("Closes", "https://bugs.gentoo.org/2")} # bad URL - for opt in ('-b', '-c'): + for opt in ("-b", "-c"): with pytest.raises(SystemExit) as excinfo: - tool.parse_args(['commit', opt, 'bugs.gentoo.org/1']) + tool.parse_args(["commit", opt, "bugs.gentoo.org/1"]) assert excinfo.value.code == 2 out, err = capsys.readouterr() assert not out - assert 'invalid URL: bugs.gentoo.org/1' in err + assert "invalid URL: bugs.gentoo.org/1" in err # generic tags - for opt in ('-T', '--tag'): + for opt in ("-T", "--tag"): for value, expected in ( - ('tag:value', ('Tag', 'value')), - ('tag:multiple values', ('Tag', 'multiple values')), - ('tag:multiple:values', ('Tag', 'multiple:values')), - ): - options, _ = tool.parse_args(['commit', opt, value]) + ("tag:value", ("Tag", "value")), + ("tag:multiple values", ("Tag", "multiple values")), + ("tag:multiple:values", ("Tag", "multiple:values")), + ): + options, _ = tool.parse_args(["commit", opt, value]) assert options.footer == {expected} # bad tags - for opt in ('-T', '--tag'): - for value in ('', ':', 'tag:', ':value', 'tag'): + for opt in ("-T", "--tag"): + for value in ("", ":", "tag:", ":value", "tag"): with pytest.raises(SystemExit) as excinfo: - tool.parse_args(['commit', opt, value]) + tool.parse_args(["commit", opt, value]) assert excinfo.value.code == 2 out, err = capsys.readouterr() assert not out - assert 'invalid commit tag' in err + assert "invalid commit tag" in err class TestPkgdevCommit: - - script = staticmethod(partial(run, 'pkgdev')) + script = staticmethod(partial(run, "pkgdev")) @pytest.fixture(autouse=True) def _setup(self, tmp_path): self.cache_dir = str(tmp_path) - self.scan_args = ['--pkgcheck-scan', f'--config no --cache-dir {self.cache_dir}'] + self.scan_args = ["--pkgcheck-scan", f"--config no --cache-dir {self.cache_dir}"] # args for running pkgdev like a script - self.args = ['pkgdev', 'commit', '--config', 'no'] + self.scan_args + self.args = ["pkgdev", "commit", "--config", "no"] + self.scan_args 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 out, err = capsys.readouterr() assert not out - assert err.strip() == 'pkgdev commit: error: no staged changes exist' + assert err.strip() == "pkgdev commit: error: no staged changes exist" def test_git_message_opts(self, repo, make_git_repo, tmp_path): """Verify message-related options are passed through to `git commit`.""" git_repo = make_git_repo(repo.location, commit=True) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0', commit=False) - path = str(tmp_path / 'msg') - 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): + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0", commit=False) + path = str(tmp_path / "msg") + 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): self.script() assert excinfo.value.code == 0 - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == ['commit1'] - - 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): + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == ["commit1"] + + 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): self.script() assert excinfo.value.code == 0 - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == ['commit2'] + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == ["commit2"] def test_message_template(self, capsys, repo, make_git_repo, tmp_path): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') - path = str(tmp_path / 'msg') + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") + path = str(tmp_path / "msg") # auto-generate prefix - with open(path, 'w') as f: - f.write(textwrap.dedent("""\ - *: summary - - body - """)) - - 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 open(path, "w") as f: + f.write( + textwrap.dedent( + """\ + *: summary + + body + """ + ) + ) + + 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): self.script() assert excinfo.value.code == 0 - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == ['cat/pkg: summary', '', 'body'] + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == ["cat/pkg: summary", "", "body"] # override prefix - with open(path, 'w') as f: - f.write(textwrap.dedent("""\ - prefix: summary - - body - """)) - - 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 open(path, "w") as f: + f.write( + textwrap.dedent( + """\ + prefix: summary + + body + """ + ) + ) + + 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): self.script() assert excinfo.value.code == 0 - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == ['prefix: summary', '', 'body'] + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == ["prefix: summary", "", "body"] # empty message - with open(path, 'w') as f: - f.write('') - - 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 open(path, "w") as f: + f.write("") + + 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): self.script() assert excinfo.value.code == 2 out, err = capsys.readouterr() assert not out - assert err.strip().startswith('pkgdev commit: error: empty message template') + assert err.strip().startswith("pkgdev commit: error: empty message template") def test_custom_unprefixed_message(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - ebuild_path = repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') - 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): + ebuild_path = repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") + 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): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() - assert err == out == '' + assert err == out == "" - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == ['cat/pkg: msg'] + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == ["cat/pkg: msg"] def test_custom_prefixed_message(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - ebuild_path = repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') - 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): + ebuild_path = repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") + 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): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() - assert err == out == '' + assert err == out == "" - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == ['prefix: msg'] + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == ["prefix: msg"] def test_edited_commit_message(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - ebuild_path = repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') - 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): + ebuild_path = repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") + 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): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() - assert err == out == '' + assert err == out == "" - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == ['cat/pkg: commit'] + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == ["cat/pkg: commit"] def test_generated_commit_prefixes(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") + 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() - assert err == out == '' - message = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) + assert err == out == "" + message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) return message[0] # single package change - repo.create_ebuild('cat/newpkg-0') - assert commit().startswith('cat/newpkg: ') + repo.create_ebuild("cat/newpkg-0") + assert commit().startswith("cat/newpkg: ") # multiple package changes in the same category - repo.create_ebuild('cat/newpkg-1') - repo.create_ebuild('cat/pkg-1') - assert commit().startswith('cat/*: ') + repo.create_ebuild("cat/newpkg-1") + repo.create_ebuild("cat/pkg-1") + assert commit().startswith("cat/*: ") # multiple package changes in various categories - repo.create_ebuild('cat/newpkg-2') - repo.create_ebuild('cat/pkg-2') - repo.create_ebuild('newcat/newpkg-1') - assert commit().startswith('*/*: ') + repo.create_ebuild("cat/newpkg-2") + repo.create_ebuild("cat/pkg-2") + repo.create_ebuild("newcat/newpkg-1") + assert commit().startswith("*/*: ") # single eclass change - with open(pjoin(repo.location, 'eclass', 'foo.eclass'), 'a+') as f: - f.write('# comment\n') - assert commit().startswith('foo.eclass: ') + with open(pjoin(repo.location, "eclass", "foo.eclass"), "a+") as f: + f.write("# comment\n") + assert commit().startswith("foo.eclass: ") # multiple eclass changes - for eclass in ('foo.eclass', 'bar.eclass'): - with open(pjoin(repo.location, 'eclass', eclass), 'a+') as f: - f.write('# comment\n') - assert commit().startswith('eclass: ') + for eclass in ("foo.eclass", "bar.eclass"): + with open(pjoin(repo.location, "eclass", eclass), "a+") as f: + f.write("# comment\n") + assert commit().startswith("eclass: ") # single profiles/package.mask change - with open(pjoin(repo.location, 'profiles', 'package.mask'), 'a+') as f: - f.write('# comment\n') - assert commit().startswith('profiles: ') + with open(pjoin(repo.location, "profiles", "package.mask"), "a+") as f: + f.write("# comment\n") + assert commit().startswith("profiles: ") - amd64 = pjoin(repo.location, 'profiles', 'arch', 'amd64') + amd64 = pjoin(repo.location, "profiles", "arch", "amd64") os.makedirs(amd64) - arm64 = pjoin(repo.location, 'profiles', 'arch', 'arm64') + arm64 = pjoin(repo.location, "profiles", "arch", "arm64") os.makedirs(arm64) # multiple profiles file changes in the same subdir - for file in ('package.mask', 'package.mask'): - with open(pjoin(amd64, file), 'a+') as f: - f.write('# comment\n') - assert commit().startswith('profiles/arch/amd64: ') + for file in ("package.mask", "package.mask"): + with open(pjoin(amd64, file), "a+") as f: + f.write("# comment\n") + assert commit().startswith("profiles/arch/amd64: ") # multiple profiles file changes in different subdirs for path in (amd64, arm64): - with open(pjoin(path, 'package.use'), 'a+') as f: - f.write('# comment\n') - assert commit().startswith('profiles/arch: ') + with open(pjoin(path, "package.use"), "a+") as f: + f.write("# comment\n") + assert commit().startswith("profiles/arch: ") # single repo root file change - with open(pjoin(repo.location, 'skel.ebuild'), 'a+') as f: - f.write('# comment\n') - assert commit().startswith('skel.ebuild: ') + with open(pjoin(repo.location, "skel.ebuild"), "a+") as f: + f.write("# comment\n") + assert commit().startswith("skel.ebuild: ") # multiple repo root file change (no commit message prefix) - for file in ('skel.ebuild', 'header.txt'): - with open(pjoin(repo.location, file), 'a+') as f: - f.write('# comment\n') - assert commit() == 'msg' + for file in ("skel.ebuild", "header.txt"): + with open(pjoin(repo.location, file), "a+") as f: + f.write("# comment\n") + assert commit() == "msg" # treewide changes (no commit message prefix) - repo.create_ebuild('foo/bar-1') - with open(pjoin(repo.location, 'eclass', 'foo.eclass'), 'a+') as f: - f.write('# comment\n') - with open(pjoin(repo.location, 'profiles', 'package.mask'), 'a+') as f: - f.write('# comment\n') - assert commit() == 'msg' + repo.create_ebuild("foo/bar-1") + with open(pjoin(repo.location, "eclass", "foo.eclass"), "a+") as f: + f.write("# comment\n") + with open(pjoin(repo.location, "profiles", "package.mask"), "a+") as f: + f.write("# comment\n") + assert commit() == "msg" def test_generated_commit_summaries(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") + 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() - assert err == out == '' - message = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) + assert err == out == "" + message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) return message[0] # initial package import - repo.create_ebuild('cat/newpkg-0') - assert commit() == 'cat/newpkg: new package, add 0' + repo.create_ebuild("cat/newpkg-0") + assert commit() == "cat/newpkg: new package, add 0" # initial package import, overflowed title truncated for i in range(10): - repo.create_ebuild(f'cat/newpkg2-{i}.0.0') - assert commit() == 'cat/newpkg2: new package' + repo.create_ebuild(f"cat/newpkg2-{i}.0.0") + assert commit() == "cat/newpkg2: new package" # single addition - repo.create_ebuild('cat/pkg-1') - assert commit() == 'cat/pkg: add 1' + repo.create_ebuild("cat/pkg-1") + assert commit() == "cat/pkg: add 1" # multiple additions - repo.create_ebuild('cat/pkg-2') - repo.create_ebuild('cat/pkg-3', eapi=6) - repo.create_ebuild('cat/pkg-4', eapi=6) - assert commit() == 'cat/pkg: add 2, 3, 4' + repo.create_ebuild("cat/pkg-2") + repo.create_ebuild("cat/pkg-3", eapi=6) + repo.create_ebuild("cat/pkg-4", eapi=6) + assert commit() == "cat/pkg: add 2, 3, 4" # revbump updating EAPI - repo.create_ebuild('cat/pkg-4-r1', eapi=7) - assert commit() == 'cat/pkg: update EAPI 6 -> 7' + repo.create_ebuild("cat/pkg-4-r1", eapi=7) + assert commit() == "cat/pkg: update EAPI 6 -> 7" # single rename with no revisions git_repo.move( - pjoin(git_repo.path, 'cat/pkg/pkg-4.ebuild'), - pjoin(git_repo.path, 'cat/pkg/pkg-5.ebuild'), - commit=False + pjoin(git_repo.path, "cat/pkg/pkg-4.ebuild"), + pjoin(git_repo.path, "cat/pkg/pkg-5.ebuild"), + commit=False, ) - assert commit() == 'cat/pkg: add 5, drop 4' + assert commit() == "cat/pkg: add 5, drop 4" # bump EAPI for multiple versions, same summary - repo.create_ebuild('cat/pkg-6', eapi='6') - git_repo.add_all('cat/pkg-6') - repo.create_ebuild('cat/pkg-3', eapi='7') - repo.create_ebuild('cat/pkg-6', eapi='7') - assert commit() == 'cat/pkg: update EAPI 6 -> 7' + repo.create_ebuild("cat/pkg-6", eapi="6") + git_repo.add_all("cat/pkg-6") + repo.create_ebuild("cat/pkg-3", eapi="7") + repo.create_ebuild("cat/pkg-6", eapi="7") + assert commit() == "cat/pkg: update EAPI 6 -> 7" # update description - repo.create_ebuild('cat/pkg-7') - git_repo.add_all('cat/pkg-7') - repo.create_ebuild('cat/pkg-7', description='something') - assert commit() == 'cat/pkg: update DESCRIPTION' + repo.create_ebuild("cat/pkg-7") + git_repo.add_all("cat/pkg-7") + repo.create_ebuild("cat/pkg-7", description="something") + assert commit() == "cat/pkg: update DESCRIPTION" # update description & homepage - repo.create_ebuild('cat/pkg-7', description='another something', homepage='https://gentoo.org') - assert commit() == 'cat/pkg: update DESCRIPTION, HOMEPAGE' + repo.create_ebuild( + "cat/pkg-7", description="another something", homepage="https://gentoo.org" + ) + assert commit() == "cat/pkg: update DESCRIPTION, HOMEPAGE" # update string_targets (USE_RUBY) - os.mkdir(pjoin(repo.location, 'profiles', 'desc')) - with open(pjoin(repo.path, 'profiles', 'desc', 'ruby_targets.desc'), 'w') as file: - file.write('\n'.join(f'ruby{ver} - stub' for ver in range(27, 40))) - repo.create_ebuild('cat/pkg-8', use_ruby='ruby27') - git_repo.add_all('cat/pkg-8') - repo.create_ebuild('cat/pkg-8', use_ruby='ruby27 ruby30') - assert commit() == 'cat/pkg: enable ruby30' - repo.create_ebuild('cat/pkg-8', use_ruby='ruby30') - assert commit() == 'cat/pkg: disable ruby27' - repo.create_ebuild('cat/pkg-8', use_ruby=' '.join(f'ruby{i}' for i in range(30, 40))) - assert commit() == 'cat/pkg: update USE_RUBY support' + os.mkdir(pjoin(repo.location, "profiles", "desc")) + with open(pjoin(repo.path, "profiles", "desc", "ruby_targets.desc"), "w") as file: + file.write("\n".join(f"ruby{ver} - stub" for ver in range(27, 40))) + repo.create_ebuild("cat/pkg-8", use_ruby="ruby27") + git_repo.add_all("cat/pkg-8") + repo.create_ebuild("cat/pkg-8", use_ruby="ruby27 ruby30") + assert commit() == "cat/pkg: enable ruby30" + repo.create_ebuild("cat/pkg-8", use_ruby="ruby30") + assert commit() == "cat/pkg: disable ruby27" + repo.create_ebuild("cat/pkg-8", use_ruby=" ".join(f"ruby{i}" for i in range(30, 40))) + assert commit() == "cat/pkg: update USE_RUBY support" # update array_targets (PYTHON_COMPAT) - with open(pjoin(repo.path, 'profiles', 'desc', 'python_targets.desc'), 'w') as file: - file.write('\n'.join(f'python3_{ver} - stub' for ver in (10, 11))) - repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_8 python3_9 )') - git_repo.add_all('cat/pkg-9') - repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{8..10} )') - assert commit() == 'cat/pkg: enable py3.10' - repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{9..10} )') - assert commit() == 'cat/pkg: disable py3.8' - repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{10..11} )') - assert commit() == 'cat/pkg: enable py3.11' - + with open(pjoin(repo.path, "profiles", "desc", "python_targets.desc"), "w") as file: + file.write("\n".join(f"python3_{ver} - stub" for ver in (10, 11))) + repo.create_ebuild("cat/pkg-9", data="PYTHON_COMPAT=( python3_8 python3_9 )") + git_repo.add_all("cat/pkg-9") + repo.create_ebuild("cat/pkg-9", data="PYTHON_COMPAT=( python3_{8..10} )") + assert commit() == "cat/pkg: enable py3.10" + repo.create_ebuild("cat/pkg-9", data="PYTHON_COMPAT=( python3_{9..10} )") + assert commit() == "cat/pkg: disable py3.8" + repo.create_ebuild("cat/pkg-9", data="PYTHON_COMPAT=( python3_{10..11} )") + assert commit() == "cat/pkg: enable py3.11" # multiple ebuild modifications don't get a generated summary - repo.create_ebuild('cat/pkg-5', keywords=['~amd64']) - repo.create_ebuild('cat/pkg-6', keywords=['~amd64']) - assert commit() == 'cat/pkg: summary' + repo.create_ebuild("cat/pkg-5", keywords=["~amd64"]) + repo.create_ebuild("cat/pkg-6", keywords=["~amd64"]) + assert commit() == "cat/pkg: summary" # large number of additions in a single commit for v in range(10000, 10010): - repo.create_ebuild(f'cat/pkg-{v}') - assert commit() == 'cat/pkg: add versions' + repo.create_ebuild(f"cat/pkg-{v}") + assert commit() == "cat/pkg: add versions" # create Manifest - with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'w') as file: - file.write('DIST pkg-3.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n') - assert commit() == 'cat/pkg: update Manifest' + with open(pjoin(git_repo.path, "cat/pkg/Manifest"), "w") as file: + file.write("DIST pkg-3.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n") + assert commit() == "cat/pkg: update Manifest" # update Manifest - with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'a+') as file: - file.write('DIST pkg-2.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n') - assert commit() == 'cat/pkg: update Manifest' + with open(pjoin(git_repo.path, "cat/pkg/Manifest"), "a+") as file: + file.write("DIST pkg-2.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n") + assert commit() == "cat/pkg: update Manifest" # remove Manifest - os.remove(pjoin(git_repo.path, 'cat/pkg/Manifest')) - assert commit() == 'cat/pkg: update Manifest' + os.remove(pjoin(git_repo.path, "cat/pkg/Manifest")) + assert commit() == "cat/pkg: update Manifest" # single removals - os.remove(pjoin(git_repo.path, 'cat/pkg/pkg-4-r1.ebuild')) - assert commit() == 'cat/pkg: drop 4-r1' - os.remove(pjoin(git_repo.path, 'cat/pkg/pkg-3.ebuild')) - assert commit() == 'cat/pkg: drop 3' + os.remove(pjoin(git_repo.path, "cat/pkg/pkg-4-r1.ebuild")) + assert commit() == "cat/pkg: drop 4-r1" + os.remove(pjoin(git_repo.path, "cat/pkg/pkg-3.ebuild")) + assert commit() == "cat/pkg: drop 3" # multiple removal - os.remove(pjoin(git_repo.path, 'cat/pkg/pkg-2.ebuild')) - os.remove(pjoin(git_repo.path, 'cat/pkg/pkg-1.ebuild')) - assert commit() == 'cat/pkg: drop 1, 2' + os.remove(pjoin(git_repo.path, "cat/pkg/pkg-2.ebuild")) + os.remove(pjoin(git_repo.path, "cat/pkg/pkg-1.ebuild")) + assert commit() == "cat/pkg: drop 1, 2" # large number of removals in a single commit for v in range(10000, 10010): - os.remove(pjoin(git_repo.path, f'cat/pkg/pkg-{v}.ebuild')) - assert commit() == 'cat/pkg: drop versions' + os.remove(pjoin(git_repo.path, f"cat/pkg/pkg-{v}.ebuild")) + assert commit() == "cat/pkg: drop versions" # package rename - shutil.copytree(pjoin(git_repo.path, 'cat/pkg'), pjoin(git_repo.path, 'newcat/pkg')) - shutil.rmtree(pjoin(git_repo.path, 'cat/pkg')) - assert commit() == 'newcat/pkg: rename cat/pkg' + shutil.copytree(pjoin(git_repo.path, "cat/pkg"), pjoin(git_repo.path, "newcat/pkg")) + shutil.rmtree(pjoin(git_repo.path, "cat/pkg")) + assert commit() == "newcat/pkg: rename cat/pkg" # treeclean - shutil.rmtree(pjoin(git_repo.path, 'newcat/pkg')) - assert commit() == 'newcat/pkg: treeclean' + shutil.rmtree(pjoin(git_repo.path, "newcat/pkg")) + assert commit() == "newcat/pkg: treeclean" def test_generated_commit_summaries_keywords(self, capsys, make_repo, make_git_repo): - repo = make_repo(arches=['amd64', 'arm64', 'ia64', 'x86']) + repo = make_repo(arches=["amd64", "arm64", "ia64", "x86"]) git_repo = make_git_repo(repo.location) - pkgdir = os.path.dirname(repo.create_ebuild('cat/pkg-0')) - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - - """)) - git_repo.add_all('cat/pkg-0') + pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0")) + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + + """ + ) + ) + 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() - assert err == out == '' - message = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) + assert err == out == "" + message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) return message[0] # keyword version - repo.create_ebuild('cat/pkg-0', keywords=['~amd64']) - assert commit() == 'cat/pkg: keyword 0 for ~amd64' + repo.create_ebuild("cat/pkg-0", keywords=["~amd64"]) + assert commit() == "cat/pkg: keyword 0 for ~amd64" # stabilize version - repo.create_ebuild('cat/pkg-0', keywords=['amd64']) - assert commit() == 'cat/pkg: stabilize 0 for amd64' + repo.create_ebuild("cat/pkg-0", keywords=["amd64"]) + assert commit() == "cat/pkg: stabilize 0 for amd64" # destabilize version - repo.create_ebuild('cat/pkg-0', keywords=['~amd64']) - assert commit() == 'cat/pkg: destabilize 0 for ~amd64' + repo.create_ebuild("cat/pkg-0", keywords=["~amd64"]) + assert commit() == "cat/pkg: destabilize 0 for ~amd64" # unkeyword version - repo.create_ebuild('cat/pkg-0') - assert commit() == 'cat/pkg: unkeyword 0 for ~amd64' - - with open(pjoin(repo.location, 'profiles', 'arches.desc'), 'w') as f: - f.write(textwrap.dedent("""\ - amd64 stable - arm64 stable - ia64 testing - x86 stable - """)) - git_repo.add_all('set arches.desc') - - repo.create_ebuild('cat/pkg-0', keywords=['~amd64', '~arm64', '~ia64', '~x86']) - git_repo.add_all('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") + assert commit() == "cat/pkg: unkeyword 0 for ~amd64" + + with open(pjoin(repo.location, "profiles", "arches.desc"), "w") as f: + f.write( + textwrap.dedent( + """\ + amd64 stable + arm64 stable + ia64 testing + x86 stable + """ + ) + ) + git_repo.add_all("set arches.desc") + + repo.create_ebuild("cat/pkg-0", keywords=["~amd64", "~arm64", "~ia64", "~x86"]) + git_repo.add_all("cat/pkg-0") # stabilize version - repo.create_ebuild('cat/pkg-0', keywords=['amd64', '~arm64', '~ia64', '~x86']) - assert commit() == 'cat/pkg: stabilize 0 for amd64' + repo.create_ebuild("cat/pkg-0", keywords=["amd64", "~arm64", "~ia64", "~x86"]) + assert commit() == "cat/pkg: stabilize 0 for amd64" # stabilize version ALLARCHES - repo.create_ebuild('cat/pkg-0', keywords=['amd64', 'arm64', '~ia64', 'x86']) - assert commit() == 'cat/pkg: stabilize 0 for ALLARCHES' + repo.create_ebuild("cat/pkg-0", keywords=["amd64", "arm64", "~ia64", "x86"]) + assert commit() == "cat/pkg: stabilize 0 for ALLARCHES" # stabilize version - repo.create_ebuild('cat/newpkg-0', keywords=['~amd64', '~arm64', '~ia64', '~x86']) - git_repo.add_all('cat/newpkg') - repo.create_ebuild('cat/newpkg-0', keywords=['amd64', 'arm64', '~ia64', 'x86']) - assert commit() == 'cat/newpkg: stabilize 0 for amd64, arm64, x86' + repo.create_ebuild("cat/newpkg-0", keywords=["~amd64", "~arm64", "~ia64", "~x86"]) + git_repo.add_all("cat/newpkg") + repo.create_ebuild("cat/newpkg-0", keywords=["amd64", "arm64", "~ia64", "x86"]) + assert commit() == "cat/newpkg: stabilize 0 for amd64, arm64, x86" def test_metadata_summaries(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - pkgdir = os.path.dirname(repo.create_ebuild('cat/pkg-0')) + pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0")) # stub metadata - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - """)) - git_repo.add_all('cat/pkg-0') + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + """ + ) + ) + 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() - assert err == out == '' - message = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) + assert err == out == "" + message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) return message[0] # add yourself - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - first.last@email.com - First Last - - - """)) - assert commit() == 'cat/pkg: add myself as a maintainer' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + first.last@email.com + First Last + + + """ + ) + ) + assert commit() == "cat/pkg: add myself as a maintainer" # drop yourself - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - """)) - assert commit() == 'cat/pkg: drop myself as a maintainer' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + """ + ) + ) + assert commit() == "cat/pkg: drop myself as a maintainer" # drop to maintainer-needed - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - """)) - assert commit() == 'cat/pkg: drop to maintainer-needed' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + """ + ) + ) + assert commit() == "cat/pkg: drop to maintainer-needed" # add random maintainer - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - """)) - assert commit() == 'cat/pkg: update maintainers' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + """ + ) + ) + assert commit() == "cat/pkg: update maintainers" # add allarches tag - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - - """)) - assert commit() == 'cat/pkg: mark ALLARCHES' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + + """ + ) + ) + assert commit() == "cat/pkg: mark ALLARCHES" # drop allarches tag - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - """)) - assert commit() == 'cat/pkg: drop ALLARCHES' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + """ + ) + ) + assert commit() == "cat/pkg: drop ALLARCHES" # add upstream metadata - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - pkgcore/pkgdev - pkgdev - - - """)) - assert commit() == 'cat/pkg: add github, pypi upstream metadata' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + pkgcore/pkgdev + pkgdev + + + """ + ) + ) + assert commit() == "cat/pkg: add github, pypi upstream metadata" # remove upstream metadata - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - pkgcore/pkgdev - - - """)) - assert commit() == 'cat/pkg: remove pypi upstream metadata' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + pkgcore/pkgdev + + + """ + ) + ) + assert commit() == "cat/pkg: remove pypi upstream metadata" # update upstream metadata - with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: - f.write(textwrap.dedent("""\ - - - - - person@email.com - Person - - - pkgcore/pkgcheck - - - """)) - assert commit() == 'cat/pkg: update upstream metadata' + with open(pjoin(pkgdir, "metadata.xml"), "w") as f: + f.write( + textwrap.dedent( + """\ + + + + + person@email.com + Person + + + pkgcore/pkgcheck + + + """ + ) + ) + assert commit() == "cat/pkg: update upstream metadata" def test_no_summary(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") + 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() - assert err == out == '' - return git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) + assert err == out == "" + return git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) # no commit message content for i in range(10): - with open(pjoin(git_repo.path, f'file-a-{i}'), 'w') as f: - f.write('stub\n') - assert commit(['-a']) == ['summary'] + with open(pjoin(git_repo.path, f"file-a-{i}"), "w") as f: + f.write("stub\n") + assert commit(["-a"]) == ["summary"] # footer exists with no generated summary for i in range(10): - with open(pjoin(git_repo.path, f'file-b-{i}'), 'w') as f: - f.write('stub\n') - assert commit(['-a', '-T', 'tag:value']) == ['summary', '', 'Tag: value'] + with open(pjoin(git_repo.path, f"file-b-{i}"), "w") as f: + f.write("stub\n") + assert commit(["-a", "-T", "tag:value"]) == ["summary", "", "Tag: value"] def test_non_gentoo_file_mangling(self, repo, make_git_repo): git_repo = make_git_repo(repo.location) - ebuild_path = repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') + ebuild_path = repo.create_ebuild("cat/pkg-0") + 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 # append line missing EOF newline to ebuild - with open(ebuild_path, 'a+') as f: - f.write('# comment') + with open(ebuild_path, "a+") as f: + f.write("# comment") # verify file doesn't end with newline with open(ebuild_path) as f: - assert f.read()[-1] != '\n' + assert f.read()[-1] != "\n" # non-gentoo repos aren't mangled by default - commit(['-u', '-m', 'mangling']) + commit(["-u", "-m", "mangling"]) with open(ebuild_path) as f: - assert f.read()[-1] != '\n' + assert f.read()[-1] != "\n" # but they can be forcibly mangled - with open(ebuild_path, 'a+') as f: - f.write('# comment') - commit(['--mangle', '-u', '-m', 'mangling']) + with open(ebuild_path, "a+") as f: + f.write("# comment") + commit(["--mangle", "-u", "-m", "mangling"]) # mangled pre-commit, file now ends with newline with open(ebuild_path) as f: - assert f.read()[-1] == '\n' + assert f.read()[-1] == "\n" # FILESDIR content is ignored even when forced - path = pjoin(os.path.dirname(ebuild_path), 'files', 'pkg.patch') + path = pjoin(os.path.dirname(ebuild_path), "files", "pkg.patch") os.makedirs(os.path.dirname(path)) - with open(path, 'w') as f: - f.write('# comment') + with open(path, "w") as f: + f.write("# comment") # verify file doesn't end with newline with open(path) as f: - assert f.read()[-1] != '\n' + assert f.read()[-1] != "\n" def test_gentoo_file_mangling(self, make_repo, make_git_repo): - repo = make_repo(repo_id='gentoo') + repo = make_repo(repo_id="gentoo") git_repo = make_git_repo(repo.location) - ebuild_path = repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') + ebuild_path = repo.create_ebuild("cat/pkg-0") + 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 # append line missing EOF newline to ebuild - with open(ebuild_path, 'a+') as f: - f.write('# comment') + with open(ebuild_path, "a+") as f: + f.write("# comment") # verify file doesn't end with newline with open(ebuild_path) as f: - assert f.read()[-1] != '\n' + assert f.read()[-1] != "\n" # gentoo repos are mangled by default - commit(['-n', '-u', '-m', 'mangling']) + commit(["-n", "-u", "-m", "mangling"]) with open(ebuild_path) as f: - assert f.read()[-1] == '\n' + assert f.read()[-1] == "\n" # FILESDIR content is ignored - path = pjoin(os.path.dirname(ebuild_path), 'files', 'pkg.patch') + path = pjoin(os.path.dirname(ebuild_path), "files", "pkg.patch") os.makedirs(os.path.dirname(path)) - with open(path, 'w') as f: - f.write('# comment') + with open(path, "w") as f: + f.write("# comment") # verify file doesn't end with newline with open(path) as f: - assert f.read()[-1] != '\n' + assert f.read()[-1] != "\n" for years, org in ( - ('1999-2020', 'Gentoo Authors'), - ('1999-2020', 'Gentoo Foundation'), - ('2020', 'Gentoo Authors'), - ('2020', 'Gentoo Foundation'), - ): + ("1999-2020", "Gentoo Authors"), + ("1999-2020", "Gentoo Foundation"), + ("2020", "Gentoo Authors"), + ("2020", "Gentoo Foundation"), + ): # munge the copyright header - with open(ebuild_path, 'r+') as f: + with open(ebuild_path, "r+") as f: lines = f.read().splitlines() - lines[0] = f'# Copyright {years} {org}\n' + lines[0] = f"# Copyright {years} {org}\n" f.seek(0) f.truncate() - f.write('\n'.join(lines) + '\n') - commit(['-n', '-u', '-m', 'mangling']) + f.write("\n".join(lines) + "\n") + commit(["-n", "-u", "-m", "mangling"]) # verify the copyright header was updated with open(ebuild_path) as f: lines = f.read().splitlines() mo = copyright_regex.match(lines[0]) - assert mo.group('end') == str(datetime.today().year) - assert mo.group('begin') == years[:4] + '-' - assert mo.group('holder') == 'Gentoo Authors' + assert mo.group("end") == str(datetime.today().year) + assert mo.group("begin") == years[:4] + "-" + assert mo.group("holder") == "Gentoo Authors" for original, expected in ( - ('"arm64 amd64 x86"', 'amd64 arm64 x86'), - ('"arm64 amd64 ~x86"', 'amd64 arm64 ~x86'), - ('"arm64 ~x86 amd64"', 'amd64 arm64 ~x86'), - ('"arm64 ~x86 ~amd64"', '~amd64 arm64 ~x86'), - ('arm64 ~x86 ~amd64', '~amd64 arm64 ~x86'), - ): + ('"arm64 amd64 x86"', "amd64 arm64 x86"), + ('"arm64 amd64 ~x86"', "amd64 arm64 ~x86"), + ('"arm64 ~x86 amd64"', "amd64 arm64 ~x86"), + ('"arm64 ~x86 ~amd64"', "~amd64 arm64 ~x86"), + ("arm64 ~x86 ~amd64", "~amd64 arm64 ~x86"), + ): # munge the keywords - with open(ebuild_path, 'r+') as f: + with open(ebuild_path, "r+") as f: lines = f.read().splitlines() - lines[-1] = f'KEYWORDS={original}' + lines[-1] = f"KEYWORDS={original}" f.seek(0) f.truncate() - f.write('\n'.join(lines) + '\n') - commit(['-n', '-u', '-m', 'mangling']) + f.write("\n".join(lines) + "\n") + commit(["-n", "-u", "-m", "mangling"]) # verify the keywords were updated with open(ebuild_path) as f: lines = f.read().splitlines() mo = keywords_regex.match(lines[-1]) - assert mo.group('keywords') == expected + assert mo.group("keywords") == expected def test_scan(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') - - 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): + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") + + 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 + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() - assert err == out == '' - commit_msg = git_repo.log(['-1', '--pretty=tformat:%B', 'HEAD']) - assert commit_msg == [f'cat/pkg: add {i}'] + assert err == out == "" + commit_msg = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"]) + assert commit_msg == [f"cat/pkg: add {i}"] def test_failed_scan(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") # 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): + 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 + ): self.script() assert excinfo.value.code == 1 out, err = capsys.readouterr() assert not err - assert out == textwrap.dedent("""\ - cat/pkg - MissingLicense: version 1: no license defined - - FAILURES - cat/pkg - MissingLicense: version 1: no license defined - """) + assert out == textwrap.dedent( + """\ + cat/pkg + MissingLicense: version 1: no license defined + + FAILURES + cat/pkg + MissingLicense: version 1: no license defined + """ + ) # 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 def test_config_opts(self, capsys, repo, make_git_repo, tmp_path): - config_file = str(tmp_path / 'config') - with open(config_file, 'w') as f: - f.write(textwrap.dedent(""" - [DEFAULT] - commit.scan= - """)) + config_file = str(tmp_path / "config") + with open(config_file, "w") as f: + f.write( + textwrap.dedent( + """ + [DEFAULT] + commit.scan= + """ + ) + ) git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - 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): + repo.create_ebuild("cat/pkg-0") + 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): self.script() out, err = capsys.readouterr() assert excinfo.value.code == 1 assert not err - assert 'MissingLicense' in out + assert "MissingLicense" in out def test_config_repo_opts(self, capsys, repo, make_git_repo, tmp_path): - config_file = str(tmp_path / 'config') - with open(config_file, 'w') as f: - f.write(textwrap.dedent(""" - [fake] - commit.scan= - """)) + config_file = str(tmp_path / "config") + with open(config_file, "w") as f: + f.write( + textwrap.dedent( + """ + [fake] + commit.scan= + """ + ) + ) git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - 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): + repo.create_ebuild("cat/pkg-0") + 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): self.script() out, err = capsys.readouterr() assert excinfo.value.code == 1 assert not err - assert 'MissingLicense' in out + assert "MissingLicense" in out def test_failed_manifest(self, capsys, repo, make_git_repo): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - 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): + repo.create_ebuild("cat/pkg-0") + 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 + ): self.script() assert excinfo.value.code == 1 out, err = capsys.readouterr() diff --git a/tests/scripts/test_pkgdev_manifest.py b/tests/scripts/test_pkgdev_manifest.py index 2800236..0645be0 100644 --- a/tests/scripts/test_pkgdev_manifest.py +++ b/tests/scripts/test_pkgdev_manifest.py @@ -9,186 +9,185 @@ from snakeoil.osutils import pjoin class TestPkgdevManifestParseArgs: - def test_non_repo_cwd(self, capsys, tool): with pytest.raises(SystemExit) as excinfo: - tool.parse_args(['manifest']) + tool.parse_args(["manifest"]) assert excinfo.value.code == 2 out, err = capsys.readouterr() - assert err.strip() == 'pkgdev manifest: error: not in ebuild repo' + assert err.strip() == "pkgdev manifest: error: not in ebuild repo" def test_repo_cwd(self, repo, capsys, tool): - repo.create_ebuild('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") with chdir(repo.location): - options, _ = tool.parse_args(['manifest']) + options, _ = tool.parse_args(["manifest"]) matches = [x.cpvstr for x in repo.itermatch(options.restriction)] - assert matches == ['cat/pkg-0'] + assert matches == ["cat/pkg-0"] def test_repo_relative_pkg(self, repo, capsys, tool): - repo.create_ebuild('cat/pkg-0') - repo.create_ebuild('cat/newpkg-0') - with chdir(pjoin(repo.location, 'cat/pkg')): - options, _ = tool.parse_args(['manifest', '.']) + repo.create_ebuild("cat/pkg-0") + repo.create_ebuild("cat/newpkg-0") + with chdir(pjoin(repo.location, "cat/pkg")): + options, _ = tool.parse_args(["manifest", "."]) matches = [x.cpvstr for x in repo.itermatch(options.restriction)] - assert matches == ['cat/pkg-0'] + assert matches == ["cat/pkg-0"] def test_repo_relative_category(self, repo, capsys, tool): - repo.create_ebuild('cat/pkg-0') - repo.create_ebuild('cat/newpkg-0') + repo.create_ebuild("cat/pkg-0") + repo.create_ebuild("cat/newpkg-0") - with chdir(pjoin(repo.location, 'cat')): - options, _ = tool.parse_args(['manifest', 'pkg']) + with chdir(pjoin(repo.location, "cat")): + options, _ = tool.parse_args(["manifest", "pkg"]) matches = [x.cpvstr for x in repo.itermatch(options.restriction)] - assert matches == ['cat/pkg-0'] + assert matches == ["cat/pkg-0"] - with chdir(pjoin(repo.location, 'cat')): - options, _ = tool.parse_args(['manifest', '.']) + with chdir(pjoin(repo.location, "cat")): + options, _ = tool.parse_args(["manifest", "."]) matches = [x.cpvstr for x in repo.itermatch(options.restriction)] - assert set(matches) == {'cat/pkg-0', 'cat/newpkg-0'} + assert set(matches) == {"cat/pkg-0", "cat/newpkg-0"} def test_repo_relative_outside(self, tmp_path, repo, capsys, tool): - repo.create_ebuild('cat/pkg-0') - (ebuild := tmp_path / 'pkg.ebuild').touch() + repo.create_ebuild("cat/pkg-0") + (ebuild := tmp_path / "pkg.ebuild").touch() with pytest.raises(SystemExit) as excinfo: with chdir(repo.location): - tool.parse_args(['manifest', str(ebuild)]) + tool.parse_args(["manifest", str(ebuild)]) assert excinfo.value.code == 2 out, err = capsys.readouterr() - assert err.strip() == f"pkgdev manifest: error: {repo.repo_id!r} repo doesn't contain: {str(ebuild)!r}" + assert ( + err.strip() + == f"pkgdev manifest: error: {repo.repo_id!r} repo doesn't contain: {str(ebuild)!r}" + ) def test_dir_target(self, repo, capsys, tool): - repo.create_ebuild('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") with chdir(repo.location): - options, _ = tool.parse_args(['manifest', pjoin(repo.location, 'cat')]) + options, _ = tool.parse_args(["manifest", pjoin(repo.location, "cat")]) matches = [x.cpvstr for x in repo.itermatch(options.restriction)] - assert matches == ['cat/pkg-0'] + assert matches == ["cat/pkg-0"] def test_ebuild_target(self, repo, capsys, tool): - path = repo.create_ebuild('cat/pkg-0') + path = repo.create_ebuild("cat/pkg-0") with chdir(repo.location): - options, _ = tool.parse_args(['manifest', path]) + options, _ = tool.parse_args(["manifest", path]) matches = [x.cpvstr for x in repo.itermatch(options.restriction)] - assert matches == ['cat/pkg-0'] + assert matches == ["cat/pkg-0"] def test_atom_target(self, repo, capsys, tool): - repo.create_ebuild('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") with chdir(repo.location): - options, _ = tool.parse_args(['manifest', 'cat/pkg']) + options, _ = tool.parse_args(["manifest", "cat/pkg"]) matches = [x.cpvstr for x in repo.itermatch(options.restriction)] - assert matches == ['cat/pkg-0'] + assert matches == ["cat/pkg-0"] def test_if_modified_target(self, repo, make_git_repo, tool): def manifest_matches() -> Set[str]: repo.sync() with chdir(repo.location): - options, _ = tool.parse_args(['manifest', '--if-modified']) + options, _ = tool.parse_args(["manifest", "--if-modified"]) return {x.cpvstr for x in repo.itermatch(options.restriction)} git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/oldpkg-0') - git_repo.add_all('cat/oldpkg-0') + repo.create_ebuild("cat/oldpkg-0") + git_repo.add_all("cat/oldpkg-0") # New package - repo.create_ebuild('cat/newpkg-0') - assert manifest_matches() == {'cat/newpkg-0'} - git_repo.add_all('cat/newpkg-0') + repo.create_ebuild("cat/newpkg-0") + assert manifest_matches() == {"cat/newpkg-0"} + git_repo.add_all("cat/newpkg-0") # Untracked file - ebuild_path = repo.create_ebuild('cat/newpkg-1') - assert manifest_matches() == {'cat/newpkg-1'} + ebuild_path = repo.create_ebuild("cat/newpkg-1") + assert manifest_matches() == {"cat/newpkg-1"} # Staged file git_repo.add(ebuild_path, commit=False) - assert manifest_matches() == {'cat/newpkg-1'} + assert manifest_matches() == {"cat/newpkg-1"} # No modified files - git_repo.add_all('cat/newpkg-1') + git_repo.add_all("cat/newpkg-1") assert manifest_matches() == set() # Modified file - ebuild_path = repo.create_ebuild('cat/newpkg-1', eapi=8) - assert manifest_matches() == {'cat/newpkg-1'} - git_repo.add_all('cat/newpkg-1: eapi 8') + ebuild_path = repo.create_ebuild("cat/newpkg-1", eapi=8) + assert manifest_matches() == {"cat/newpkg-1"} + git_repo.add_all("cat/newpkg-1: eapi 8") # Renamed file git_repo.remove(ebuild_path, commit=False) - ebuild_path = repo.create_ebuild('cat/newpkg-2') + ebuild_path = repo.create_ebuild("cat/newpkg-2") git_repo.add(ebuild_path, commit=False) - assert manifest_matches() == {'cat/newpkg-2'} - git_repo.add_all('cat/newpkg-2: rename') + assert manifest_matches() == {"cat/newpkg-2"} + git_repo.add_all("cat/newpkg-2: rename") # Deleted file git_repo.remove(ebuild_path, commit=False) assert manifest_matches() == set() # Deleted package - ebuild_path = repo.create_ebuild('cat/newpkg-0') + ebuild_path = repo.create_ebuild("cat/newpkg-0") git_repo.remove(ebuild_path, commit=False) assert manifest_matches() == set() def test_ignore_fetch_restricted(self, repo, tool): def manifest_matches() -> List[str]: with chdir(repo.location): - options, _ = tool.parse_args(['manifest', '--ignore-fetch-restricted']) + options, _ = tool.parse_args(["manifest", "--ignore-fetch-restricted"]) return [x.cpvstr for x in repo.itermatch(options.restriction)] # No RESTRICT - repo.create_ebuild('cat/pkg-0') - assert manifest_matches() == ['cat/pkg-0'] + repo.create_ebuild("cat/pkg-0") + assert manifest_matches() == ["cat/pkg-0"] # Not fetch RESTRICT - repo.create_ebuild('cat/pkg-0', restrict=('mirror')) - assert manifest_matches() == ['cat/pkg-0'] + repo.create_ebuild("cat/pkg-0", restrict=("mirror")) + assert manifest_matches() == ["cat/pkg-0"] # fetch RESTRICT - repo.create_ebuild('cat/pkg-0', restrict=('fetch')) + repo.create_ebuild("cat/pkg-0", restrict=("fetch")) assert manifest_matches() == [] # Multiple RESTRICT - repo.create_ebuild('cat/pkg-0', restrict=('mirror', 'fetch')) + repo.create_ebuild("cat/pkg-0", restrict=("mirror", "fetch")) assert manifest_matches() == [] def test_non_repo_dir_target(self, tmp_path, repo, capsys, tool): - with pytest.raises(SystemExit) as excinfo, \ - chdir(repo.location): - tool.parse_args(['manifest', str(tmp_path)]) + with pytest.raises(SystemExit) as excinfo, chdir(repo.location): + tool.parse_args(["manifest", str(tmp_path)]) assert excinfo.value.code == 2 out, err = capsys.readouterr() assert err.startswith("pkgdev manifest: error: 'fake' repo doesn't contain:") def test_invalid_atom_target(self, repo, capsys, tool): - with pytest.raises(SystemExit) as excinfo, \ - chdir(repo.location): - tool.parse_args(['manifest', '=cat/pkg']) + with pytest.raises(SystemExit) as excinfo, chdir(repo.location): + tool.parse_args(["manifest", "=cat/pkg"]) assert excinfo.value.code == 2 out, err = capsys.readouterr() assert err.startswith("pkgdev manifest: error: invalid atom: '=cat/pkg'") class TestPkgdevManifest: - - script = staticmethod(partial(run, 'pkgdev')) + script = staticmethod(partial(run, "pkgdev")) @pytest.fixture(autouse=True) def _setup(self): - self.args = ['pkgdev', 'manifest'] + self.args = ["pkgdev", "manifest"] 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): + repo.create_ebuild("cat/pkg-0") + with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( + repo.location + ): self.script() assert excinfo.value.code == 0 out, err = capsys.readouterr() - assert out == err == '' + assert out == err == "" 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): + 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 + ): self.script() assert excinfo.value.code == 1 out, err = capsys.readouterr() diff --git a/tests/scripts/test_pkgdev_mask.py b/tests/scripts/test_pkgdev_mask.py index b5f7344..c7195fe 100644 --- a/tests/scripts/test_pkgdev_mask.py +++ b/tests/scripts/test_pkgdev_mask.py @@ -14,112 +14,103 @@ from snakeoil.osutils import pjoin class TestPkgdevMaskParseArgs: - def test_non_repo_cwd(self, capsys, tool): with pytest.raises(SystemExit): - tool.parse_args(['mask']) + tool.parse_args(["mask"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev mask: error: not in ebuild repo' + assert err.strip() == "pkgdev mask: error: not in ebuild repo" def test_non_git_repo_cwd(self, repo, capsys, tool): - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['mask']) + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["mask"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev mask: error: not in git repo' + assert err.strip() == "pkgdev mask: error: not in git repo" def test_non_ebuild_git_repo_cwd(self, make_repo, git_repo, capsys, tool): - os.mkdir(pjoin(git_repo.path, 'repo')) - repo = make_repo(pjoin(git_repo.path, 'repo')) - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['mask']) + os.mkdir(pjoin(git_repo.path, "repo")) + repo = make_repo(pjoin(git_repo.path, "repo")) + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["mask"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev mask: error: not in ebuild git repo' + assert err.strip() == "pkgdev mask: error: not in ebuild git repo" def test_cwd_target(self, repo, make_git_repo, capsys, tool): git_repo = make_git_repo(repo.location) # empty repo - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['mask']) + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["mask"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev mask: error: not in a package directory' + assert err.strip() == "pkgdev mask: error: not in a package directory" # not in package dir - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['mask']) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["mask"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev mask: error: not in a package directory' + assert err.strip() == "pkgdev mask: error: not in a package directory" # masking CWD package - with chdir(pjoin(repo.location, 'cat/pkg')): - options, _ = tool.parse_args(['mask']) - assert options.atoms == [atom_cls('cat/pkg')] + with chdir(pjoin(repo.location, "cat/pkg")): + options, _ = tool.parse_args(["mask"]) + assert options.atoms == [atom_cls("cat/pkg")] def test_targets(self, repo, make_git_repo, capsys, tool): git_repo = make_git_repo(repo.location) # invalid atom - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['mask', 'pkg']) + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["mask", "pkg"]) out, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: invalid atom: 'pkg'" # nonexistent pkg - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['mask', 'cat/nonexistent']) + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["mask", "cat/nonexistent"]) out, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: no repo matches: 'cat/nonexistent'" # masked pkg - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") with chdir(repo.location): - options, _ = tool.parse_args(['mask', 'cat/pkg']) - assert options.atoms == [atom_cls('cat/pkg')] + options, _ = tool.parse_args(["mask", "cat/pkg"]) + assert options.atoms == [atom_cls("cat/pkg")] def test_email_not_rites(self, repo, make_git_repo, capsys, tool): git_repo = make_git_repo(repo.location) # masked pkg - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0') - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['mask', '--email', 'cat/pkg']) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0") + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["mask", "--email", "cat/pkg"]) _, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: last rites required for email support" class TestPkgdevMask: - - script = staticmethod(partial(run, 'pkgdev')) + script = staticmethod(partial(run, "pkgdev")) @pytest.fixture(autouse=True) def _setup(self, make_repo, make_git_repo): # args for running pkgdev like a script - self.args = ['pkgdev', 'mask'] - self.repo = make_repo(arches=['amd64']) + self.args = ["pkgdev", "mask"] + self.repo = make_repo(arches=["amd64"]) self.git_repo = make_git_repo(self.repo.location) self.today = datetime.now(timezone.utc) # add stub pkg - self.repo.create_ebuild('cat/pkg-0') - self.git_repo.add_all('cat/pkg-0') + self.repo.create_ebuild("cat/pkg-0") + self.git_repo.add_all("cat/pkg-0") # create profile - self.profile_path = pjoin(self.repo.location, 'profiles/arch/amd64') + self.profile_path = pjoin(self.repo.location, "profiles/arch/amd64") os.makedirs(self.profile_path) - with open(pjoin(self.repo.location, 'profiles/profiles.desc'), 'w') as f: - f.write('amd64 arch/amd64 stable\n') + with open(pjoin(self.repo.location, "profiles/profiles.desc"), "w") as f: + f.write("amd64 arch/amd64 stable\n") - self.masks_path = Path(pjoin(self.repo.location, 'profiles/package.mask')) + self.masks_path = Path(pjoin(self.repo.location, "profiles/package.mask")) @property def profile(self): @@ -130,201 +121,207 @@ 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')]) + 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')]) + 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')]) + assert self.profile.masks == frozenset([atom_cls("=cat/pkg-0")]) def test_existing_masks(self): - self.masks_path.write_text(textwrap.dedent("""\ - # Random Dev (2021-03-24) - # masked - cat/masked - """)) - - 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.masks_path.write_text( + textwrap.dedent( + """\ + # Random Dev (2021-03-24) + # masked + cat/masked + """ + ) + ) + + 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')]) + assert self.profile.masks == frozenset([atom_cls("cat/masked"), atom_cls("=cat/pkg-0")]) def test_invalid_header(self, capsys): - self.masks_path.write_text(textwrap.dedent("""\ - # Random Dev (2022-09-09) - # - # Larry the Cow was here - # - # masked - cat/masked - - # Larry the Cow (2022-09-09) - #test - # Larry the Cow wasn't here - cat/masked2 - """)) - - 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.masks_path.write_text( + textwrap.dedent( + """\ + # Random Dev (2022-09-09) + # + # Larry the Cow was here + # + # masked + cat/masked + + # Larry the Cow (2022-09-09) + #test + # Larry the Cow wasn't here + cat/masked2 + """ + ) + ) + + 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 + assert "invalid mask entry header, lineno 9" in err def test_invalid_author(self, capsys): for line in ( - '# Random Dev ', - '# Random Dev 2021-03-24', - '# Random Dev (24-03-2021)', + "# Random Dev ", + "# Random Dev 2021-03-24", + "# Random Dev (24-03-2021)", ): - self.masks_path.write_text(textwrap.dedent(f"""\ - # Random Dev (2021-03-24) - # masked - cat/masked - - {line} - # masked - cat/masked2 - """)) - - 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.masks_path.write_text( + textwrap.dedent( + f"""\ + # Random Dev (2021-03-24) + # masked + cat/masked + + {line} + # masked + cat/masked2 + """ + ) + ) + + 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 + assert "pkgdev mask: error: invalid author, lineno 5" in err 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)): + 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)): self.script() days = 30 if len(args) == 1 else int(args[1]) removal_date = self.today + timedelta(days=days) - today = self.today.strftime('%Y-%m-%d') - removal = removal_date.strftime('%Y-%m-%d') - assert self.masks_path.read_text() == textwrap.dedent(f"""\ - # First Last ({today}) - # mask comment - # Removal: {removal}. - cat/pkg - """) + today = self.today.strftime("%Y-%m-%d") + removal = removal_date.strftime("%Y-%m-%d") + assert self.masks_path.read_text() == textwrap.dedent( + f"""\ + # First Last ({today}) + # mask comment + # Removal: {removal}. + cat/pkg + """ + ) self.masks_path.write_text("") # Reset the contents of package.mask @pytest.mark.skipif(sys.platform == "darwin", reason="no xdg-email on mac os") 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)): + 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) + ): self.script() out = output_file.read_text() - assert 'mailto:gentoo-dev-announce@lists.gentoo.org' in out + assert "mailto:gentoo-dev-announce@lists.gentoo.org" in out self.masks_path.write_text("") # Reset the contents of package.mask @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)): + 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)): self.script() _, err = capsys.readouterr() assert err.strip() == "pkgdev mask: error: failed opening email composer" def test_mask_bugs(self): - today = self.today.strftime('%Y-%m-%d') - for bflag in ('-b', '--bug'): - for (bug_nums, expected) in [ - (['42'], 'Bug #42.'), - (['42', '43'], 'Bugs #42, #43.'), + today = self.today.strftime("%Y-%m-%d") + for bflag in ("-b", "--bug"): + for bug_nums, expected in [ + (["42"], "Bug #42."), + (["42", "43"], "Bugs #42, #43."), ]: 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(f"""\ - # First Last ({today}) - # mask comment - # {expected} - cat/pkg - """) + assert self.masks_path.read_text() == textwrap.dedent( + f"""\ + # First Last ({today}) + # mask comment + # {expected} + cat/pkg + """ + ) self.masks_path.write_text("") # Reset the contents of package.mask def test_mask_bug_bad(self, capsys, tool): - for (arg, expected) in [('-1', 'must be >= 1'), ('foo', 'invalid integer value')]: + for arg, expected in [("-1", "must be >= 1"), ("foo", "invalid integer value")]: with pytest.raises(SystemExit): - tool.parse_args(['mask', '--bug', arg]) + tool.parse_args(["mask", "--bug", arg]) out, err = capsys.readouterr() - assert err.strip() == f'pkgdev mask: error: argument -b/--bug: {expected}' + assert err.strip() == f"pkgdev mask: error: argument -b/--bug: {expected}" diff --git a/tests/scripts/test_pkgdev_push.py b/tests/scripts/test_pkgdev_push.py index bf4fe97..f1f0a0b 100644 --- a/tests/scripts/test_pkgdev_push.py +++ b/tests/scripts/test_pkgdev_push.py @@ -11,114 +11,116 @@ from snakeoil.osutils import pjoin class TestPkgdevPushParseArgs: - def test_non_repo_cwd(self, capsys, tool): with pytest.raises(SystemExit): - tool.parse_args(['push']) + tool.parse_args(["push"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev push: error: not in ebuild repo' + assert err.strip() == "pkgdev push: error: not in ebuild repo" def test_non_git_repo_cwd(self, repo, capsys, tool): - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['push']) + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["push"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev push: error: not in git repo' + assert err.strip() == "pkgdev push: error: not in git repo" def test_non_ebuild_git_repo_cwd(self, make_repo, git_repo, capsys, tool): - os.mkdir(pjoin(git_repo.path, 'repo')) - repo = make_repo(pjoin(git_repo.path, 'repo')) - with pytest.raises(SystemExit), \ - chdir(repo.location): - tool.parse_args(['push']) + os.mkdir(pjoin(git_repo.path, "repo")) + repo = make_repo(pjoin(git_repo.path, "repo")) + with pytest.raises(SystemExit), chdir(repo.location): + tool.parse_args(["push"]) out, err = capsys.readouterr() - assert err.strip() == 'pkgdev push: error: not in ebuild git repo' + assert err.strip() == "pkgdev push: error: not in ebuild git repo" def test_git_push_args_passthrough(self, repo, make_git_repo, tool): """Unknown arguments for ``pkgdev push`` are passed to ``git push``.""" git_repo = make_git_repo(repo.location) with chdir(git_repo.path): - options, _ = tool.parse_args(['push', 'origin', 'main']) - assert options.push_args == ['origin', 'main'] - options, _ = tool.parse_args(['push', '-n', '--signed']) - assert '--dry-run' in options.push_args - assert '--signed' in options.push_args + options, _ = tool.parse_args(["push", "origin", "main"]) + assert options.push_args == ["origin", "main"] + options, _ = tool.parse_args(["push", "-n", "--signed"]) + assert "--dry-run" in options.push_args + assert "--signed" in options.push_args def test_scan_args(self, repo, make_git_repo, tool): git_repo = make_git_repo(repo.location) - repo.create_ebuild('cat/pkg-0') - git_repo.add_all('cat/pkg-0', commit=False) + repo.create_ebuild("cat/pkg-0") + git_repo.add_all("cat/pkg-0", commit=False) # pkgcheck isn't run in verbose mode by default with chdir(repo.location): - options, _ = tool.parse_args(['commit']) - assert '-v' not in options.scan_args + options, _ = tool.parse_args(["commit"]) + assert "-v" not in options.scan_args # verbosity level is passed down to pkgcheck with chdir(repo.location): - options, _ = tool.parse_args(['commit', '-v']) - assert '-v' in options.scan_args + options, _ = tool.parse_args(["commit", "-v"]) + assert "-v" in options.scan_args class TestPkgdevPush: - - script = staticmethod(partial(run, 'pkgdev')) + script = staticmethod(partial(run, "pkgdev")) @pytest.fixture(autouse=True) def _setup(self, tmp_path, make_repo, make_git_repo): - self.cache_dir = str(tmp_path / 'cache') - self.scan_args = ['--config', 'no', '--pkgcheck-scan', f'--config no --cache-dir {self.cache_dir}'] + self.cache_dir = str(tmp_path / "cache") + self.scan_args = [ + "--config", + "no", + "--pkgcheck-scan", + f"--config no --cache-dir {self.cache_dir}", + ] # args for running pkgdev like a script - self.args = ['pkgdev', 'push'] + self.scan_args + self.args = ["pkgdev", "push"] + self.scan_args # initialize parent repo self.parent_git_repo = make_git_repo(bare=True) # initialize child repo - child_repo_path = tmp_path / 'child-repo' + child_repo_path = tmp_path / "child-repo" child_repo_path.mkdir() self.child_git_repo = make_git_repo(str(child_repo_path)) self.child_repo = make_repo(self.child_git_repo.path) - self.child_git_repo.add_all('initial commit') + self.child_git_repo.add_all("initial commit") # create a stub pkg and commit it - self.child_repo.create_ebuild('cat/pkg-0') - self.child_git_repo.add_all('cat/pkg-0') + self.child_repo.create_ebuild("cat/pkg-0") + self.child_git_repo.add_all("cat/pkg-0") # set up parent repo as origin and push to it - self.child_git_repo.run(['git', 'remote', 'add', 'origin', self.parent_git_repo.path]) - self.child_git_repo.run(['git', 'push', '-u', 'origin', 'main']) - self.child_git_repo.run(['git', 'remote', 'set-head', 'origin', 'main']) + self.child_git_repo.run(["git", "remote", "add", "origin", self.parent_git_repo.path]) + self.child_git_repo.run(["git", "push", "-u", "origin", "main"]) + self.child_git_repo.run(["git", "remote", "set-head", "origin", "main"]) def test_push(self, capsys): - self.child_repo.create_ebuild('cat/pkg-1') - self.child_git_repo.add_all('cat/pkg-1') + 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 def test_failed_push(self, capsys): - self.child_repo.create_ebuild('cat/pkg-1', eapi='-1') - self.child_git_repo.add_all('cat/pkg-1') + self.child_repo.create_ebuild("cat/pkg-1", eapi="-1") + 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 out, err = capsys.readouterr() - assert out == textwrap.dedent("""\ - cat/pkg - InvalidEapi: version 1: invalid EAPI '-1' + assert out == textwrap.dedent( + """\ + cat/pkg + InvalidEapi: version 1: invalid EAPI '-1' - FAILURES - cat/pkg - InvalidEapi: version 1: invalid EAPI '-1' - """) + FAILURES + cat/pkg + InvalidEapi: version 1: invalid EAPI '-1' + """ + ) # 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 diff --git a/tests/scripts/test_pkgdev_showkw.py b/tests/scripts/test_pkgdev_showkw.py index c611484..c30a4f0 100644 --- a/tests/scripts/test_pkgdev_showkw.py +++ b/tests/scripts/test_pkgdev_showkw.py @@ -11,123 +11,137 @@ from pkgdev.scripts import run class Profile(NamedTuple): """Profile record used to create profiles in a repository.""" + path: str arch: str - status: str = 'stable' + status: str = "stable" deprecated: bool = False defaults: List[str] = None - eapi: str = '5' + eapi: str = "5" + class TestPkgdevShowkwParseArgs: - args = ('showkw', '--config', 'no') + args = ("showkw", "--config", "no") def test_missing_target(self, capsys, tool): with pytest.raises(SystemExit): tool.parse_args(self.args) captured = capsys.readouterr() assert captured.err.strip() == ( - 'pkgdev showkw: error: missing target argument and not in a supported repo') + "pkgdev showkw: error: missing target argument and not in a supported repo" + ) def test_unknown_arches(self, capsys, tool, make_repo): - repo = make_repo(arches=['amd64']) + repo = make_repo(arches=["amd64"]) with pytest.raises(SystemExit): - tool.parse_args([*self.args, '-a', 'unknown', '-r', repo.location]) + tool.parse_args([*self.args, "-a", "unknown", "-r", repo.location]) captured = capsys.readouterr() assert captured.err.strip() == ( - "pkgdev showkw: error: unknown arch: 'unknown' (choices: amd64)") + "pkgdev showkw: error: unknown arch: 'unknown' (choices: amd64)" + ) def test_no_color(self, tool, make_repo, tmp_path): - repo = make_repo(arches=['amd64']) - repo.create_ebuild('foo/bar-0', keywords=('x86')) + repo = make_repo(arches=["amd64"]) + repo.create_ebuild("foo/bar-0", keywords=("x86")) - (config_file := tmp_path / 'pkgcheck.conf').write_text(textwrap.dedent('''\ + (config_file := tmp_path / "pkgcheck.conf").write_text( + textwrap.dedent( + """\ [DEFAULT] showkw.color = true - ''')) + """ + ) + ) def parse(*args): - options, _ = tool.parse_args(['showkw', '-r', repo.location, 'foo/bar', - '--config', str(config_file), *args]) + options, _ = tool.parse_args( + ["showkw", "-r", repo.location, "foo/bar", "--config", str(config_file), *args] + ) return options - with os_environ('NOCOLOR'): + with os_environ("NOCOLOR"): assert parse().color is True - with os_environ(NOCOLOR='1'): + with os_environ(NOCOLOR="1"): # NOCOLOR overrides config file assert parse().color is False # cmd line option overrides NOCOLOR - assert parse('--color', 'n').color is False - assert parse('--color', 'y').color is True + assert parse("--color", "n").color is False + assert parse("--color", "y").color is True -class TestPkgdevShowkw: - script = staticmethod(partial(run, 'pkgdev')) - base_args = ('pkgdev', 'showkw', '--config', 'n', '--color', 'n') +class TestPkgdevShowkw: + script = staticmethod(partial(run, "pkgdev")) + base_args = ("pkgdev", "showkw", "--config", "n", "--color", "n") def _create_repo(self, make_repo): - repo = make_repo(arches=['amd64', 'ia64', 'mips', 'x86']) - repo.create_profiles([ - Profile('default/linux/amd64', 'amd64'), - Profile('default/linux/x86', 'x86'), - Profile('default/linux/ia64', 'ia64', 'dev'), - Profile('default/linux/mips', 'mips', 'exp'), - ]) + repo = make_repo(arches=["amd64", "ia64", "mips", "x86"]) + repo.create_profiles( + [ + Profile("default/linux/amd64", "amd64"), + Profile("default/linux/x86", "x86"), + Profile("default/linux/ia64", "ia64", "dev"), + Profile("default/linux/mips", "mips", "exp"), + ] + ) 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() assert not err - lines = out.split('\n') - table_columns = [s.strip() for s in lines[1].split('|')][1:] + lines = out.split("\n") + table_columns = [s.strip() for s in lines[1].split("|")][1:] return { ver: dict(zip(table_columns, values)) - for ver, *values in map(lambda s: map(str.strip, s.split('|')), lines[3:-1]) + for ver, *values in map(lambda s: map(str.strip, s.split("|")), lines[3:-1]) } 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: + repo.create_ebuild("foo/bar-0") + 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() assert not err - assert out.split('\n')[0] == "keywords for foo/bar:" + assert out.split("\n")[0] == "keywords for foo/bar:" 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: + repo.create_ebuild("foo/bar-0") + 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() assert not err - assert out.split('\n')[0] == "keywords for foo/bar:" + assert out.split("\n")[0] == "keywords for foo/bar:" 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): + repo.create_ebuild("foo/bar-0") + 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() assert not err - assert out.split('\n')[0] == "keywords for foo/bar:" + assert out.split("\n")[0] == "keywords for foo/bar:" 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'): + repo.create_ebuild("foo/bar-0") + 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 _, err = capsys.readouterr() @@ -135,8 +149,9 @@ 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() @@ -145,57 +160,64 @@ class TestPkgdevShowkw: def test_match_stable(self, capsys, make_repo): repo = self._create_repo(make_repo) - repo.create_ebuild('foo/bar-0', keywords=('~amd64', '~ia64', '~mips', 'x86')) - res = self._run_and_parse(capsys, '-r', repo.location, 'foo/bar', '--stable') - assert set(res.keys()) == {'0'} - assert {'amd64', 'ia64', 'mips', 'x86'} & res['0'].keys() == {'amd64', 'x86'} + repo.create_ebuild("foo/bar-0", keywords=("~amd64", "~ia64", "~mips", "x86")) + res = self._run_and_parse(capsys, "-r", repo.location, "foo/bar", "--stable") + assert set(res.keys()) == {"0"} + assert {"amd64", "ia64", "mips", "x86"} & res["0"].keys() == {"amd64", "x86"} def test_match_unstable(self, capsys, make_repo): repo = self._create_repo(make_repo) - repo.create_ebuild('foo/bar-0', keywords=('~amd64', '~ia64', '~mips', 'x86')) - res = self._run_and_parse(capsys, '-r', repo.location, 'foo/bar', '--unstable') - assert set(res.keys()) == {'0'} - assert {'amd64', 'ia64', 'mips', 'x86'} <= res['0'].keys() + repo.create_ebuild("foo/bar-0", keywords=("~amd64", "~ia64", "~mips", "x86")) + res = self._run_and_parse(capsys, "-r", repo.location, "foo/bar", "--unstable") + assert set(res.keys()) == {"0"} + assert {"amd64", "ia64", "mips", "x86"} <= res["0"].keys() def test_match_specific_arch(self, capsys, make_repo): repo = self._create_repo(make_repo) - repo.create_ebuild('foo/bar-0', keywords=('~amd64', '~ia64', '~mips', 'x86')) - res = self._run_and_parse(capsys, '-r', repo.location, 'foo/bar', '--arch', 'amd64') - assert set(res.keys()) == {'0'} - assert {'amd64', 'ia64', 'mips', 'x86'} & res['0'].keys() == {'amd64'} + repo.create_ebuild("foo/bar-0", keywords=("~amd64", "~ia64", "~mips", "x86")) + res = self._run_and_parse(capsys, "-r", repo.location, "foo/bar", "--arch", "amd64") + assert set(res.keys()) == {"0"} + assert {"amd64", "ia64", "mips", "x86"} & res["0"].keys() == {"amd64"} def test_match_specific_multiple_arch(self, capsys, make_repo): repo = self._create_repo(make_repo) - repo.create_ebuild('foo/bar-0', keywords=('~amd64', '~ia64', '~mips', 'x86')) - res = self._run_and_parse(capsys, '-r', repo.location, 'foo/bar', '--arch', 'amd64,mips') - assert set(res.keys()) == {'0'} - assert {'amd64', 'ia64', 'mips', 'x86'} & res['0'].keys() == {'amd64', 'mips'} + repo.create_ebuild("foo/bar-0", keywords=("~amd64", "~ia64", "~mips", "x86")) + res = self._run_and_parse(capsys, "-r", repo.location, "foo/bar", "--arch", "amd64,mips") + assert set(res.keys()) == {"0"} + assert {"amd64", "ia64", "mips", "x86"} & res["0"].keys() == {"amd64", "mips"} def test_correct_keywords_status(self, capsys, make_repo): 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', '-mips', '~x86')) - repo.create_ebuild('foo/bar-2', keywords=('-*', 'amd64', '-x86'), eapi=8, slot=2) - res = self._run_and_parse(capsys, '-r', repo.location, 'foo/bar') - assert set(res.keys()) == {'0', '1', '2'} - assert dict(amd64='+', ia64='~', mips='~', x86='+', slot='0').items() <= res['0'].items() - assert dict(amd64='~', ia64='o', mips='-', x86='~', slot='0').items() <= res['1'].items() - assert dict(amd64='+', ia64='*', mips='*', x86='-', slot='2', eapi='8').items() <= res['2'].items() - - @pytest.mark.parametrize(('arg', 'expected'), ( - pytest.param('--stable', {'amd64', 'x86'}, id='stable'), - pytest.param('--unstable', {'amd64', 'ia64', 'mips', 'x86'}, id='unstable'), - pytest.param('--only-unstable', {'ia64', 'mips'}, id='only-unstable'), - )) + repo.create_ebuild("foo/bar-0", keywords=("amd64", "~ia64", "~mips", "x86")) + repo.create_ebuild("foo/bar-1", keywords=("~amd64", "-mips", "~x86")) + repo.create_ebuild("foo/bar-2", keywords=("-*", "amd64", "-x86"), eapi=8, slot=2) + res = self._run_and_parse(capsys, "-r", repo.location, "foo/bar") + assert set(res.keys()) == {"0", "1", "2"} + assert dict(amd64="+", ia64="~", mips="~", x86="+", slot="0").items() <= res["0"].items() + assert dict(amd64="~", ia64="o", mips="-", x86="~", slot="0").items() <= res["1"].items() + assert ( + dict(amd64="+", ia64="*", mips="*", x86="-", slot="2", eapi="8").items() + <= res["2"].items() + ) + + @pytest.mark.parametrize( + ("arg", "expected"), + ( + pytest.param("--stable", {"amd64", "x86"}, id="stable"), + pytest.param("--unstable", {"amd64", "ia64", "mips", "x86"}, id="unstable"), + pytest.param("--only-unstable", {"ia64", "mips"}, id="only-unstable"), + ), + ) def test_collapse(self, capsys, make_repo, arg, expected): 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: + 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: self.script() out, err = capsys.readouterr() assert excinfo.value.code is None assert not err - arches = set(out.split('\n')[0].split()) + arches = set(out.split("\n")[0].split()) assert arches == expected diff --git a/tests/test_git.py b/tests/test_git.py index d19189a..d44c929 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -8,20 +8,19 @@ from pkgdev import git class TestGitRun: - def test_git_missing(self): - with patch('subprocess.run') as git_run: + with patch("subprocess.run") as git_run: git_run.side_effect = FileNotFoundError("no such file 'git'") with pytest.raises(UserException, match="no such file 'git'"): - git.run('commit') + git.run("commit") def test_failed_run(self): - with patch('subprocess.run') as git_run: - git_run.side_effect = subprocess.CalledProcessError(1, 'git commit') + with patch("subprocess.run") as git_run: + git_run.side_effect = subprocess.CalledProcessError(1, "git commit") with pytest.raises(git.GitError): - git.run('commit') + git.run("commit") def test_successful_run(self, git_repo): with chdir(git_repo.path): - p = git.run('rev-parse', '--abbrev-ref', 'HEAD', stdout=subprocess.PIPE) - assert p.stdout.strip() == 'main' + p = git.run("rev-parse", "--abbrev-ref", "HEAD", stdout=subprocess.PIPE) + assert p.stdout.strip() == "main" diff --git a/tests/test_mangle.py b/tests/test_mangle.py index 651f8b4..207a3ee 100644 --- a/tests/test_mangle.py +++ b/tests/test_mangle.py @@ -12,63 +12,62 @@ from snakeoil.cli.exceptions import UserException def fake_change(s): - return Change('/repo', 'A', str(s)) + return Change("/repo", "A", str(s)) class TestMangler: - def test_nonexistent_file(self, tmp_path): - path = tmp_path / 'nonexistent' + path = tmp_path / "nonexistent" assert list(Mangler([fake_change(path)])) == [] def test_empty_file(self, tmp_path): - path = tmp_path / 'empty' + path = tmp_path / "empty" path.touch() assert list(Mangler([fake_change(path)])) == [] def test_skipped_file(self, tmp_path): - paths = [(tmp_path / x) for x in ('file', 'file.patch')] + paths = [(tmp_path / x) for x in ("file", "file.patch")] for p in paths: - p.write_text('# comment') + p.write_text("# comment") # skip patch files - skip_regex = re.compile(r'.+\.patch$') + skip_regex = re.compile(r".+\.patch$") mangled_paths = set(Mangler(map(fake_change, paths), skip_regex=skip_regex)) - assert mangled_paths == {str(tmp_path / 'file')} + assert mangled_paths == {str(tmp_path / "file")} for p in paths: - p.write_text('# comment') + p.write_text("# comment") # don't skip any files mangled_paths = set(Mangler(map(fake_change, paths))) assert mangled_paths == set(map(str, paths)) def test_nonmangled_file(self, tmp_path): - path = tmp_path / 'file' - path.write_text('# comment\n') + path = tmp_path / "file" + path.write_text("# comment\n") assert list(Mangler([fake_change(path)])) == [] def test_mangled_file(self, tmp_path): - path = tmp_path / 'file' - path.write_text('# comment') + path = tmp_path / "file" + path.write_text("# comment") assert list(Mangler([fake_change(path)])) == [str(path)] - assert path.read_text() == '# comment\n' + assert path.read_text() == "# comment\n" def test_iterator_exceptions(self, tmp_path): """Test parallelized iterator against unhandled exceptions.""" - path = tmp_path / 'file' - path.write_text('# comment\n') + path = tmp_path / "file" + path.write_text("# comment\n") def _mangle_func(self, data): - raise Exception('func failed') + raise Exception("func failed") - with patch('pkgdev.mangle.Mangler._mangle', _mangle_func): - with pytest.raises(UserException, match='Exception: func failed'): + with patch("pkgdev.mangle.Mangler._mangle", _mangle_func): + with pytest.raises(UserException, match="Exception: func failed"): list(Mangler([fake_change(path)])) def test_sigint_handling(self, tmp_path): """Verify SIGINT is properly handled by the parallelized pipeline.""" - path = tmp_path / 'file' - path.write_text('# comment\n') + path = tmp_path / "file" + path.write_text("# comment\n") def run(queue): """Mangler run in a separate process that gets interrupted.""" @@ -80,10 +79,10 @@ class TestMangler: def sleep(): """Notify testing process then sleep.""" - queue.put('ready') + queue.put("ready") time.sleep(100) - with patch('pkgdev.mangle.Mangler.__iter__') as fake_iter: + with patch("pkgdev.mangle.Mangler.__iter__") as fake_iter: fake_iter.side_effect = partial(sleep) try: iter(Mangler([fake_change(path)])) @@ -93,7 +92,7 @@ class TestMangler: queue.put(None) sys.exit(1) - mp_ctx = multiprocessing.get_context('fork') + mp_ctx = multiprocessing.get_context("fork") queue = mp_ctx.SimpleQueue() p = mp_ctx.Process(target=run, args=(queue,)) p.start() -- cgit v1.2.3-65-gdbad