def test_srpm_git_no_prefix_patches(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0") api_instance_source_git.up.specfile.spec_content.section( "%package")[10:10] = ( "Patch1: amarillo.patch", "Patch2: citra.patch", "Patch8: malt.patch", ) api_instance_source_git.up.specfile.spec_content.section("%prep")[0:2] = [ "%setup -n %{upstream_name}-%{version}", "%patch1 -p1", "%patch2 -p0", "%patch8 -p1", ] api_instance_source_git.up.specfile.save() create_patch_mixed_history(sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) assert {x.name for x in sg_path.joinpath("fedora").glob("*.patch")} == { "amarillo.patch", "citra.patch", "malt.patch", }
def test_srpm_custom_path(upstream_instance): u, ups = upstream_instance custom_path = "sooooorc.rpm" call_real_packit(parameters=["--debug", "srpm", "--output", custom_path], cwd=u) srpm_path = u.joinpath(custom_path) assert srpm_path.is_file() build_srpm(srpm_path)
def test_srpm_merge_storm(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0") create_merge_commit_in_source_git(sg_path, go_nuts=True) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) branches = subprocess.check_output( ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"], cwd=sg_path).split(b"\n") for b in branches: if b and b.startswith(b"packit-patches-"): break else: raise AssertionError( "packit-patches- branch was not found - this should trigger the linearization" ) assert {x.name for x in sg_path.joinpath("fedora").glob("*.patch")} == { "0001-MERGE-COMMIT.patch", "0002-ugly-merge-commit.patch", }
def test_srpm_add_patch_with_ids(mock_remote_functionality_sourcegit, api_instance_source_git): ref = "0.1.0" sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, ref) create_history_with_patch_ids(sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == { "amarillo.patch", "citra.patch", "malt.patch", } with api_instance_source_git.up.specfile.patches() as patches: assert patches[0].filename == "amarillo.patch" assert patches[0].number == 3 assert patches[1].filename == "citra.patch" assert patches[1].number == 4 assert patches[2].filename == "malt.patch" assert patches[2].number == 100
def test_srpm_git_am(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0") api_instance_source_git.up.specfile.spec_content.section( "%package")[10:10] = ( "Patch1: citra.patch", "Patch2: malt.patch", "Patch8: 0001-m04r-malt.patch", ) autosetup_line = api_instance_source_git.up.specfile.spec_content.section( "%prep")[0] autosetup_line = autosetup_line.replace("-S patch", "-S git_am") api_instance_source_git.up.specfile.spec_content.section( "%prep")[0] = autosetup_line api_instance_source_git.up.specfile.save() create_git_am_style_history(sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) assert {x.name for x in sg_path.joinpath("fedora").glob("*.patch")} == { "citra.patch", "0001-m04r-malt.patch", "malt.patch", }
def test_srpm_git_am(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0") with api_instance_source_git.up.specfile.prep() as prep: prep.autosetup.options.S = "git_am" create_git_am_style_history(sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == { "citra.patch", "0001-m04r-malt.patch", "malt.patch", } run_prep_for_srpm(srpm_path) prep_root = sg_path.joinpath("beerware-0.1.0") assert prep_root.joinpath("malt").read_text() == "Munich\n" assert prep_root.joinpath("hops").read_text() == "Saaz\n"
def test_srpm_merge_storm(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0") create_merge_commit_in_source_git(sg_path, go_nuts=True) # linearization creates a new branch, make some arbitrary moves to verify # we end up in the former branch after the build subprocess.check_call(["git", "checkout", "-B", "test-branch"], cwd=sg_path) subprocess.check_call(["git", "checkout", "main"], cwd=sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) branches = subprocess.check_output( ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"], cwd=sg_path).split(b"\n") for b in branches: if b and b.startswith(b"packit-patches-"): break else: raise AssertionError( "packit-patches- branch was not found - this should trigger the linearization" ) # make sure we are on the main branch assert ("main" == subprocess.check_output( ["git", "branch", "--show-current"], cwd=sg_path).decode().strip()) assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == { "0001-MERGE-COMMIT.patch", "0002-ugly-merge-commit.patch", }
def test_srpm_empty_patch(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0") api_instance_source_git.up.specfile.spec_content.section( "%package")[10:10] = ( "Patch1: amarillo.patch", "Patch2: citra.patch", "Patch5: saaz.patch", "Patch8: malt.patch", ) api_instance_source_git.up.specfile.save() create_history_with_empty_commit(sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) assert {x.name for x in sg_path.joinpath("fedora").glob("*.patch")} == { "amarillo.patch", "citra.patch", "saaz.patch", "malt.patch", } assert sg_path.joinpath("fedora", "saaz.patch").read_text() == ""
def test_create_srpm(upstream_instance, tmp_path): u, ups = upstream_instance with pytest.raises(PackitSRPMException) as exc: ups.create_srpm() # Creating an SRPM failes b/c the source archive is not present. assert "tar.gz: No such file or directory" in str(exc.value) ups.create_archive() srpm = ups.create_srpm() assert srpm.exists() srpm_path = tmp_path.joinpath("custom.src.rpm") ups.prepare_upstream_for_srpm_creation() srpm = ups.create_srpm(srpm_path=srpm_path) r = re.compile(r"^- Development snapshot \(\w{8}\)$") with ups.specfile.sections() as sections: for line in sections.changelog: if r.match(line): break else: assert False, "Didn't find the correct line in the spec file." assert srpm.exists() build_srpm(srpm)
def test_srpm_on_example(example_repo): c = get_test_config() api = get_packit_api( config=c, local_project=LocalProject(working_dir=str(example_repo))) with cwd(example_repo): path = api.create_srpm() assert path.exists() build_srpm(path)
def test_srpm_command_for_path(upstream_or_distgit_path, tmp_path): with cwd(tmp_path): call_real_packit( parameters=["--debug", "srpm", str(upstream_or_distgit_path)]) srpm_path = list(Path.cwd().glob("*.src.rpm"))[0] assert srpm_path.exists() build_srpm(srpm_path)
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git): # TODO: we need a better test case here which will mimic the systemd use case sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path / "fedora") with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref="0.1.0") srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path)
def test_srpm_custom_path(cwd_upstream_or_distgit): custom_path = "sooooorc.rpm" call_real_packit( parameters=["--debug", "srpm", "--output", custom_path], cwd=cwd_upstream_or_distgit, ) srpm_path = cwd_upstream_or_distgit.joinpath(custom_path) assert srpm_path.is_file() build_srpm(srpm_path)
def test_srpm_command_for_path_with_multiple_sources( upstream_and_remote_with_multiple_sources, ): workdir, _ = upstream_and_remote_with_multiple_sources with cwd(workdir): call_real_packit(parameters=["--debug", "srpm", str(workdir)]) srpm_path = list(Path.cwd().glob("*.src.rpm"))[0] assert srpm_path.exists() assert (Path.cwd() / "python-ogr.spec").exists() build_srpm(srpm_path)
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path / "fedora") create_merge_commit_in_source_git(sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref="0.1.0") srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path)
def test_srpm_twice(cwd_upstream_or_distgit): call_real_packit(parameters=["--debug", "srpm"], cwd=cwd_upstream_or_distgit) call_real_packit(parameters=["--debug", "srpm"], cwd=cwd_upstream_or_distgit) # since we build from the 0.1.0, we would get the same SRPM because of '--new 0.1.0' srpm_files = list(cwd_upstream_or_distgit.glob("*.src.rpm")) assert srpm_files[0].exists() build_srpm(srpm_files[0])
def test_srpm_twice(upstream_instance): u, ups = upstream_instance call_real_packit(parameters=["--debug", "srpm"], cwd=u) call_real_packit(parameters=["--debug", "srpm"], cwd=u) # since we build from the 0.1.0, we would get the same SRPM because of '--new 0.1.0' srpm_files = list(u.glob("*.src.rpm")) assert srpm_files[0].exists() build_srpm(srpm_files[0])
def test_create_srpm_git_desc_release(upstream_instance, tmpdir): u, ups = upstream_instance u.joinpath("README").write_text("\nEven better now!\n") subprocess.check_call(["git", "add", "."], cwd=u) subprocess.check_call(["git", "commit", "-m", "More awesome changes"], cwd=u) ups.create_archive() ups.prepare_upstream_for_srpm_creation() srpm = ups.create_srpm() assert srpm.exists() build_srpm(srpm) assert re.match(r".+beer-0.1.0-1.\d+.fc\d{2}.src.rpm$", str(srpm))
def test_srpm_twice_with_custom_name(upstream_instance): u, ups = upstream_instance custom_path = "sooooorc.rpm" call_real_packit(parameters=["--debug", "srpm", "--output", custom_path], cwd=u) srpm_path1 = u.joinpath(custom_path) assert srpm_path1.is_file() build_srpm(srpm_path1) custom_path2 = "sooooorc2.rpm" call_real_packit(parameters=["--debug", "srpm", "--output", custom_path2], cwd=u) srpm_path2 = u.joinpath(custom_path2) assert srpm_path2.is_file() build_srpm(srpm_path2)
def test_srpm_command_no_tags(upstream_and_remote): upstream_cwd, _ = upstream_and_remote # remove the tags tags = subprocess.run(("git", "tag"), cwd=upstream_cwd, stdout=subprocess.PIPE) subprocess.run(["xargs", "git", "tag", "-d"], cwd=upstream_cwd, input=tags.stdout) call_real_packit(parameters=["--debug", "srpm"], cwd=upstream_cwd) srpm_path = list(upstream_cwd.glob("*.src.rpm"))[0] assert srpm_path.exists() build_srpm(srpm_path)
def test_create_srpm(upstream_instance, tmpdir): u, ups = upstream_instance with pytest.raises(PackitException) as exc: ups.create_srpm() assert "Failed to create SRPM." == str(exc.value) ups.create_archive() srpm = ups.create_srpm() assert srpm.exists() srpm_path = Path(tmpdir).joinpath("custom.src.rpm") srpm = ups.create_srpm(srpm_path=srpm_path) assert srpm.exists() build_srpm(srpm)
def test_srpm_patch_non_conseq_indices(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0") api_instance_source_git.up.specfile.spec_content.section( "%package")[10:10] = ( "Patch0: amarillo.patch", "Patch3: citra.patch", "Patch4: saaz.patch", "Patch5: malt.patch", ) api_instance_source_git.up.specfile.save() create_history_with_empty_commit(sg_path) malt = sg_path.joinpath("malt") malt.write_text("Wheat\n") git_add_and_commit(directory=sg_path, message="Weißbier! Summer is coming!") with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) # make sure the patch is inserted AFTER existing patches patches = api_instance_source_git.up.specfile.tags.filter(name="Patch*", valid=None) last_patch = list(patches)[-1] assert last_patch.name == "Patch6" assert (os.path.basename( api_instance_source_git.up.specfile.get_applied_patches()[-1].path) == "0004-Wei-bier-Summer-is-coming.patch") srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) assert {x.name for x in sg_path.joinpath("fedora").glob("*.patch")} == { "amarillo.patch", "citra.patch", "saaz.patch", "malt.patch", "0004-Wei-bier-Summer-is-coming.patch", } assert sg_path.joinpath("fedora", "saaz.patch").read_text() == ""
def test_action_output(upstream_and_remote): upstream_repo_path = upstream_and_remote[0] packit_yaml_path = upstream_repo_path / ".packit.json" packit_yaml_dict = json.loads(packit_yaml_path.read_text()) # http://www.atlaspiv.cz/?page=detail&beer_id=4187 the_line_we_want = "MadCat - Imperial Stout Rum Barrel Aged 20°" packit_yaml_dict["actions"] = { "post-upstream-clone": [f"bash -c 'echo {the_line_we_want}'"] } packit_yaml_path.write_text(json.dumps(packit_yaml_dict)) out = call_real_packit(parameters=["srpm"], cwd=upstream_repo_path, return_output=True) assert f"\n{the_line_we_want}\n" in out.decode() srpm_path = list(upstream_repo_path.glob("*.src.rpm"))[0] assert srpm_path.exists() build_srpm(srpm_path)
def test_create_srpm_git_desc_release(upstream_instance): u, ups = upstream_instance u.joinpath("README").write_text("\nEven better now!\n") subprocess.check_call(["git", "add", "."], cwd=u) subprocess.check_call(["git", "commit", "-m", "More awesome changes"], cwd=u) ups.create_archive() ups.prepare_upstream_for_srpm_creation() srpm = ups.create_srpm() assert srpm.exists() build_srpm(srpm) assert re.match( r".+beer-0.1.0-1\.\d{20}\.\w+\.\d\.g\w{7}\.fc\d{2}.src.rpm$", str(srpm) ) changelog = ups.specfile.spec_content.section("%changelog") assert "- More awesome changes (Packit Test Suite)" in changelog
def test_srpm_twice_with_custom_name(cwd_upstream_or_distgit): custom_path = "sooooorc.rpm" call_real_packit( parameters=["--debug", "srpm", "--output", custom_path], cwd=cwd_upstream_or_distgit, ) srpm_path1 = cwd_upstream_or_distgit.joinpath(custom_path) assert srpm_path1.is_file() build_srpm(srpm_path1) custom_path2 = "sooooorc2.rpm" call_real_packit( parameters=["--debug", "srpm", "--output", custom_path2], cwd=cwd_upstream_or_distgit, ) srpm_path2 = cwd_upstream_or_distgit.joinpath(custom_path2) assert srpm_path2.is_file() build_srpm(srpm_path2)
def test_srpm_patch_non_conseq_indices(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0") with api_instance_source_git.up.specfile.sections() as sections: sections.package[10:10] = ( "Patch0: amarillo.patch", "Patch3: citra.patch", "Patch4: saaz.patch", "Patch5: malt.patch", ) create_history_with_empty_commit(sg_path) malt = sg_path.joinpath("malt") malt.write_text("Wheat\n") git_add_and_commit(directory=sg_path, message="Weißbier! Summer is coming!") with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) # make sure the patch is inserted AFTER existing patches with api_instance_source_git.up.specfile.patches() as patches: last_patch = patches[-1] assert last_patch.number == 6 assert last_patch.filename == "0004-Wei-bier-Summer-is-coming.patch" srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == { "amarillo.patch", "citra.patch", "saaz.patch", "malt.patch", "0004-Wei-bier-Summer-is-coming.patch", } assert sg_path.joinpath(DISTRO_DIR, "saaz.patch").read_text() == ""
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git, ref): sg_path = Path(api_instance_source_git.upstream_local_project.working_dir) mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0") create_merge_commit_in_source_git(sg_path) with cwd(sg_path): api_instance_source_git.create_srpm(upstream_ref=ref) srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0] assert srpm_path.is_file() build_srpm(srpm_path) branches = subprocess.check_output( ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"], cwd=sg_path ).split(b"\n") for b in branches: if b and b.startswith(b"packit-patches-"): raise AssertionError( "packit-patches- branch was found - the history shouldn't have been linearized" ) assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == { "0001-switching-to-amarillo-hops.patch", "0002-actually-let-s-do-citra.patch", }
def test_create_srpm(upstream_instance, tmp_path): u, ups = upstream_instance with pytest.raises(PackitSRPMException) as exc: ups.create_srpm() assert "Bad source" in str(exc.value) ups.create_archive() srpm = ups.create_srpm() assert srpm.exists() srpm_path = tmp_path.joinpath("custom.src.rpm") ups.prepare_upstream_for_srpm_creation() srpm = ups.create_srpm(srpm_path=srpm_path) r = re.compile(r"^- Development snapshot \(\w{8}\)$") for line in ups.specfile.spec_content.section("%changelog"): if r.match(line): break else: assert False, "Didn't find the correct line in the spec file." assert srpm.exists() build_srpm(srpm)
def test_srpm_weird_sources(upstream_and_remote_weird_sources): repo = upstream_and_remote_weird_sources[0] call_real_packit(parameters=["--debug", "srpm"], cwd=repo) srpm_path = list(repo.glob("*.src.rpm"))[0] assert srpm_path.exists() build_srpm(srpm_path)
def test_srpm_spec_not_in_root(upstream_spec_not_in_root): call_real_packit(parameters=["--debug", "srpm"], cwd=upstream_spec_not_in_root[0]) srpm_path = list(upstream_spec_not_in_root[0].glob("*.src.rpm"))[0] assert srpm_path.exists() build_srpm(srpm_path)