#36 Misc changes to testing how the changelog is generated in the plugin
Merged 4 years ago by pingou. Opened 4 years ago by nphilipp.
fedora-infra/ nphilipp/rpmautospec master--changelog-foo  into  master

@@ -11,10 +11,7 @@ 

  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)

@@ -1,6 +1,6 @@ 

- import io

  import os

  import shutil

+ from subprocess import check_output

  import tarfile

  import tempfile

  from unittest.mock import MagicMock
@@ -34,14 +34,14 @@ 

  

      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 @@ 

          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 @@ 

                      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}")
@@ -87,7 +87,6 @@ 

  

          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"""
@@ -122,7 +121,7 @@ 

                      "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"]
@@ -158,6 +157,17 @@ 

                      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

                  )

no initial comment

1 new commit added

  • Don't expect the autospec_cb() test to fail
4 years ago

Build failed.

I have the same issue locally as zuul has, ie:

>               assert check_output(unprocessed_cmd + ["--qf", "%{release}\n"]) == check_output(
                    expected_cmd + ["--qf", "%{release}\n"]
                )
E               AssertionError: assert b'7.fc32\n' == b'7.fc31\n'

I think I figured out why this fails. The %dist is supplied by your system, and Nils is running Fedora 32 already, while Zuul is on 31 :-)

If we define the dist macro, it will work:

                unprocessed_cmd = ["rpm", "--define", "%dist .fc32", "--specfile", unprocessed_spec_file_path]
                expected_cmd = ["rpm", "--define", "%dist .fc32", "--specfile", expected_spec_file_path]

5 new commits added

  • Don't expect the autospec_cb() test to fail
  • Semantically verify processed spec file
  • Adjust number of mocked builds
  • Update tests for changes in test spec file
  • Use a template for %autorel that RPM can parse
4 years ago

Build succeeded.

Pull-Request has been merged by pingou

4 years ago