From 73c863c3ea1df5a5d464a45047263822d59d3277 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mar 27 2020 16:32:04 +0000 Subject: [PATCH 1/5] Use a template for %autorel that RPM can parse This will have to be augmented to be in line with `doc/examples/autorel-function-hdr.txt`, but will do for the time being. Signed-off-by: Nils Philippsen --- diff --git a/koji_plugin/rpmautospec_plugin.py b/koji_plugin/rpmautospec_plugin.py index fb17749..f7486e8 100644 --- a/koji_plugin/rpmautospec_plugin.py +++ b/koji_plugin/rpmautospec_plugin.py @@ -11,10 +11,7 @@ from rpmautospec.changelog import produce_changelog from rpmautospec.misc import koji_init from rpmautospec.release import holistic_heuristic_algo -autorel_template = """%global function autorel() {{ - return {autorel} -}} -""" +autorel_template = """%define autorel {autorel}""" autorel_re = re.compile(r"^\s*(?i:Release)\s*:\s+%(?:autorel(?:\s|$)|\{autorel[^\}]*\})") changelog_re = re.compile(r"^%changelog(?:\s.*)?$", re.IGNORECASE) From 7d3e8ac882062e6677248a53fe36f8fbf5c99a0d Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mar 27 2020 16:35:36 +0000 Subject: [PATCH 2/5] Update tests for changes in test spec file We've changed the spec file and documentation to not use braces per default, let the tests reflect that. Signed-off-by: Nils Philippsen --- diff --git a/tests/koji_plugin/test_rpmautospec_plugin.py b/tests/koji_plugin/test_rpmautospec_plugin.py index 6ba7f8b..7c03edc 100644 --- a/tests/koji_plugin/test_rpmautospec_plugin.py +++ b/tests/koji_plugin/test_rpmautospec_plugin.py @@ -34,14 +34,14 @@ class TestRpmautospecPlugin: autorel_autochangelog_cases = [ (autorel_case, autochangelog_case) - for autorel_case in ("unchanged", "without braces") + for autorel_case in ("unchanged", "with braces") for autochangelog_case in ( "unchanged", "changelog case insensitive", "changelog trailing garbage", "line in between", "trailing line", - "without braces", + "with braces", ) ] @@ -62,8 +62,8 @@ class TestRpmautospecPlugin: with open(spec_file_path, "r") as orig, open(spec_file_path + ".new", "w") as new: for line in orig: if line.startswith("Release:") and autorel_case != "unchanged": - if autorel_case == "without braces": - print("Release: %autorel", file=new) + if autorel_case == "with braces": + print("Release: %{autorel}", file=new) else: raise ValueError(f"Unknown autorel_case: {autorel_case}") elif line.strip() == "%changelog" and autochangelog_case != "unchanged": @@ -72,13 +72,13 @@ class TestRpmautospecPlugin: elif autochangelog_case == "changelog trailing garbage": print("%changelog with trailing garbage yes this works", file=new) elif autochangelog_case == "line in between": - print("%changelog\n\n%{autochangelog}", file=new) + print("%changelog\n\n%autochangelog", file=new) break elif autochangelog_case == "trailing line": - print("%changelog\n%{autochangelog}\n", file=new) + print("%changelog\n%autochangelog\n", file=new) break - elif autochangelog_case == "without braces": - print("%changelog\n%autochangelog", file=new) + elif autochangelog_case == "with braces": + print("%changelog\n%{autochangelog}", file=new) break else: raise ValueError(f"Unknown autochangelog_case: {autochangelog_case}") From e4a9d29fd713bea883cc041c5cccb316141fbab1 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mar 27 2020 16:37:03 +0000 Subject: [PATCH 3/5] Adjust number of mocked builds Signed-off-by: Nils Philippsen --- diff --git a/tests/koji_plugin/test_rpmautospec_plugin.py b/tests/koji_plugin/test_rpmautospec_plugin.py index 7c03edc..181db51 100644 --- a/tests/koji_plugin/test_rpmautospec_plugin.py +++ b/tests/koji_plugin/test_rpmautospec_plugin.py @@ -122,7 +122,7 @@ class TestRpmautospecPlugin: "release": f"{x}.fc32", "version": "0", } - for x in range(2, 14) + for x in range(2, 7) ] koji_session.listBuilds.return_value = builds args = ["postSCMCheckout"] From 4341afe56d4b823f0c251d7610b6b58d1e58d325 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mar 30 2020 08:35:56 +0000 Subject: [PATCH 4/5] Semantically verify processed spec file Rather than comparing the processed spec file byte-per-byte with what we expect, use rpm to evaluate their release and changelog and compare them. Signed-off-by: Nils Philippsen --- diff --git a/tests/koji_plugin/test_rpmautospec_plugin.py b/tests/koji_plugin/test_rpmautospec_plugin.py index 181db51..63f8256 100644 --- a/tests/koji_plugin/test_rpmautospec_plugin.py +++ b/tests/koji_plugin/test_rpmautospec_plugin.py @@ -1,6 +1,6 @@ -import io import os import shutil +from subprocess import check_output import tarfile import tempfile from unittest.mock import MagicMock @@ -158,6 +158,17 @@ class TestRpmautospecPlugin: expected_spec_file_path = tmpspec.name self.fuzz_spec_file(expected_spec_file_path, autorel_case, autochangelog_case) - assert list(io.open(unprocessed_spec_file_path)) == list( - io.open(expected_spec_file_path) + rpm_cmd = ["rpm", "--define", "dist .fc32", "--specfile"] + + unprocessed_cmd = rpm_cmd + [unprocessed_spec_file_path] + expected_cmd = rpm_cmd + [expected_spec_file_path] + + q_release = ["--qf", "%{release}\n"] + assert check_output(unprocessed_cmd + q_release) == check_output( + expected_cmd + q_release + ) + + q_changelog = ["--changelog"] + assert check_output(unprocessed_cmd + q_changelog) == check_output( + expected_cmd + q_changelog ) From 9efda58fbd528ecf31c9cdd27342ca30dc7a8e81 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mar 30 2020 08:35:56 +0000 Subject: [PATCH 5/5] Don't expect the autospec_cb() test to fail Signed-off-by: Nils Philippsen --- diff --git a/tests/koji_plugin/test_rpmautospec_plugin.py b/tests/koji_plugin/test_rpmautospec_plugin.py index 63f8256..5faf7c1 100644 --- a/tests/koji_plugin/test_rpmautospec_plugin.py +++ b/tests/koji_plugin/test_rpmautospec_plugin.py @@ -87,7 +87,6 @@ class TestRpmautospecPlugin: os.rename(spec_file_path + ".new", spec_file_path) - @pytest.mark.xfail @pytest.mark.parametrize("autorel_case,autochangelog_case", autorel_autochangelog_cases) def test_autospec_cb(self, autorel_case, autochangelog_case): """Test the autospec_cb() function"""