Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-specfile for openSUSE:Factory 
checked in at 2023-05-12 20:37:08
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-specfile (Old)
 and      /work/SRC/openSUSE:Factory/.python-specfile.new.1533 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-specfile"

Fri May 12 20:37:08 2023 rev:11 rq:1086542 version:0.17.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-specfile/python-specfile.changes  
2023-04-25 16:44:47.930929305 +0200
+++ 
/work/SRC/openSUSE:Factory/.python-specfile.new.1533/python-specfile.changes    
    2023-05-12 20:40:00.134762606 +0200
@@ -1,0 +2,11 @@
+Thu May 11 12:19:01 UTC 2023 - David Anes <david.a...@suse.com>
+
+- Update to version 0.17.0: 
+  * Added a new guess_packager() function that uses similar
+    heuristics as rpmdev-packager, meaning that the 
+    Specfile.add_changelog_entry() method no longer requires
+    rpmdev-packager to guess the changelog entry author. (#220)
+  * The Specfile.add_changelog_entry() method now uses dates based
+    on UTC instead of the local timezone. (#223)
+
+-------------------------------------------------------------------

Old:
----
  specfile-0.16.0.tar.gz

New:
----
  specfile-0.17.0.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-specfile.spec ++++++
--- /var/tmp/diff_new_pack.7DUmT3/_old  2023-05-12 20:40:00.606765200 +0200
+++ /var/tmp/diff_new_pack.7DUmT3/_new  2023-05-12 20:40:00.614765244 +0200
@@ -18,7 +18,7 @@
 
 %define skip_python38 1
 Name:           python-specfile
-Version:        0.16.0
+Version:        0.17.0
 Release:        0
 Summary:        A library for parsing and manipulating RPM spec files
 License:        MIT
@@ -31,14 +31,13 @@
 BuildRequires:  %{python_module wheel}
 BuildRequires:  python-rpm-macros
 # SECTION test requirements
-BuildRequires:  %{python_module rpm}
+BuildRequires:  git
 BuildRequires:  %{python_module flexmock}
 BuildRequires:  %{python_module pytest}
-BuildRequires:  %{python_module typing-extensions}
+BuildRequires:  %{python_module rpm}
 # /SECTION
 BuildRequires:  fdupes
 Requires:       python-rpm
-Requires:       python-typing-extensions
 
 BuildArch:      noarch
 

++++++ specfile-0.16.0.tar.gz -> specfile-0.17.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/.github/workflows/pypi-publish.yml 
new/specfile-0.17.0/.github/workflows/pypi-publish.yml
--- old/specfile-0.16.0/.github/workflows/pypi-publish.yml      2023-04-20 
18:57:54.000000000 +0200
+++ new/specfile-0.17.0/.github/workflows/pypi-publish.yml      2023-05-11 
11:43:56.000000000 +0200
@@ -10,10 +10,12 @@
 jobs:
   build-n-publish:
     runs-on: ubuntu-latest
+    permissions:
+      id-token: write # for trusted publishing
 
     steps:
       - uses: actions/checkout@v3
-      - uses: actions/setup-python@v2
+      - uses: actions/setup-python@v4
 
       - name: Build a source tarball and a binary wheel
         # https://pypa-build.readthedocs.io
@@ -25,5 +27,4 @@
         # https://github.com/pypa/gh-action-pypi-publish
         uses: pypa/gh-action-pypi-publish@release/v1
         with:
-          password: ${{ secrets.PYPI_API_TOKEN }}
           verbose: true
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/CHANGELOG.md 
new/specfile-0.17.0/CHANGELOG.md
--- old/specfile-0.16.0/CHANGELOG.md    2023-04-20 18:57:54.000000000 +0200
+++ new/specfile-0.17.0/CHANGELOG.md    2023-05-11 11:43:56.000000000 +0200
@@ -1,3 +1,8 @@
+# 0.17.0
+
+- Added a new `guess_packager()` function that uses similar heuristics as 
`rpmdev-packager`, meaning that the `Specfile.add_changelog_entry()` method no 
longer requires `rpmdev-packager` to guess the changelog entry author. (#220)
+- The `Specfile.add_changelog_entry()` method now uses dates based on UTC 
instead of the local timezone. (#223)
+
 # 0.16.0
 
 - Added `Specfile.has_autorelease` property to detect if a spec file uses the 
`%autorelease` macro. (#221)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/Makefile new/specfile-0.17.0/Makefile
--- old/specfile-0.16.0/Makefile        2023-04-20 18:57:54.000000000 +0200
+++ new/specfile-0.17.0/Makefile        2023-05-11 11:43:56.000000000 +0200
@@ -1,12 +1,14 @@
 TEST_IMAGE = specfile-tests
 CONTAINER_ENGINE ?= $(shell command -v podman 2> /dev/null || echo docker)
+COLOR ?= yes
+COV_REPORT ?= --cov=specfile --cov-report=term-missing
 
 TEST_TARGET ?= ./tests/unit ./tests/integration
 
 .PHONY: check install build-test-image check-in-container
 
 check:
-       PYTHONPATH=$(CURDIR) PYTHONDONTWRITEBYTECODE=1 python3 -m pytest 
--verbose --showlocals $(TEST_TARGET) --full-trace
+       PYTHONPATH=$(CURDIR) PYTHONDONTWRITEBYTECODE=1 python3 -m pytest 
--color=$(COLOR) --verbose --showlocals $(TEST_TARGET) $(COV_REPORT) 
--full-trace
 
 install:
        pip3 install --user .
@@ -15,4 +17,9 @@
        $(CONTAINER_ENGINE) build --rm --tag $(TEST_IMAGE) -f 
Containerfile.tests
 
 check-in-container:
-       $(CONTAINER_ENGINE) run --rm -ti -v $(CURDIR):/src:Z -w /src --env 
TEST_TARGET $(TEST_IMAGE) make check
+       $(CONTAINER_ENGINE) run --rm -ti \
+               -v $(CURDIR):/src:Z -w /src \
+               --env TEST_TARGET \
+               --env COLOR \
+               --env COV_REPORT \
+               $(TEST_IMAGE) make check
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/PKG-INFO new/specfile-0.17.0/PKG-INFO
--- old/specfile-0.16.0/PKG-INFO        2023-04-20 18:58:05.934381500 +0200
+++ new/specfile-0.17.0/PKG-INFO        2023-05-11 11:44:06.806230300 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: specfile
-Version: 0.16.0
+Version: 0.17.0
 Summary: A library for parsing and manipulating RPM spec files.
 Home-page: https://github.com/packit/specfile
 Author: Red Hat
@@ -197,7 +197,8 @@
 #### Changelog
 
 ```python
-# adding a new entry, author is determined using rpmdev-packager (if available)
+# adding a new entry, author is automatically determined
+# (using the same heuristics that rpmdev-packager uses) if possible
 specfile.add_changelog_entry('New upstream release 2.1')
 
 # adding a new entry, specifying author and timestamp explicitly
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/README.md 
new/specfile-0.17.0/README.md
--- old/specfile-0.16.0/README.md       2023-04-20 18:57:54.000000000 +0200
+++ new/specfile-0.17.0/README.md       2023-05-11 11:43:56.000000000 +0200
@@ -170,7 +170,8 @@
 #### Changelog
 
 ```python
-# adding a new entry, author is determined using rpmdev-packager (if available)
+# adding a new entry, author is automatically determined
+# (using the same heuristics that rpmdev-packager uses) if possible
 specfile.add_changelog_entry('New upstream release 2.1')
 
 # adding a new entry, specifying author and timestamp explicitly
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/fedora/python-specfile.spec 
new/specfile-0.17.0/fedora/python-specfile.spec
--- old/specfile-0.16.0/fedora/python-specfile.spec     2023-04-20 
18:57:54.000000000 +0200
+++ new/specfile-0.17.0/fedora/python-specfile.spec     2023-05-11 
11:43:56.000000000 +0200
@@ -13,7 +13,7 @@
 
 
 Name:           python-specfile
-Version:        0.16.0
+Version:        0.17.0
 Release:        1%{?dist}
 
 Summary:        A library for parsing and manipulating RPM spec files
@@ -25,6 +25,10 @@
 BuildArch:      noarch
 
 BuildRequires:  python%{python3_pkgversion}-devel
+%if %{with tests}
+# tests/unit/test_guess_packager.py
+BuildRequires:  git-core
+%endif
 
 
 %description
@@ -67,6 +71,9 @@
 
 
 %changelog
+* Thu May 11 2023 Packit Team <he...@packit.dev> - 0.17.0-1
+- New upstream release 0.17.0
+
 * Thu Apr 20 2023 Packit Team <he...@packit.dev> - 0.16.0-1
 - New upstream release 0.16.0
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/files/install-requirements-pip.yaml 
new/specfile-0.17.0/files/install-requirements-pip.yaml
--- old/specfile-0.16.0/files/install-requirements-pip.yaml     2023-04-20 
18:57:54.000000000 +0200
+++ new/specfile-0.17.0/files/install-requirements-pip.yaml     2023-05-11 
11:43:56.000000000 +0200
@@ -3,10 +3,3 @@
   hosts: all
   tasks:
     - include_tasks: tasks/generic-dnf-requirements.yaml
-    - name: Install deps from PyPI
-      pip:
-        name: "{{ item }}"
-      with_items:
-        - rpm-py-installer
-        - typing-extensions
-      become: true
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/specfile-0.16.0/files/tasks/generic-dnf-requirements.yaml 
new/specfile-0.17.0/files/tasks/generic-dnf-requirements.yaml
--- old/specfile-0.16.0/files/tasks/generic-dnf-requirements.yaml       
2023-04-20 18:57:54.000000000 +0200
+++ new/specfile-0.17.0/files/tasks/generic-dnf-requirements.yaml       
2023-05-11 11:43:56.000000000 +0200
@@ -6,5 +6,4 @@
       - git
       - dnf-utils
       - python3-pip
-      - rpmdevtools
   become: true
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/files/tasks/rpm-deps.yaml 
new/specfile-0.17.0/files/tasks/rpm-deps.yaml
--- old/specfile-0.16.0/files/tasks/rpm-deps.yaml       2023-04-20 
18:57:54.000000000 +0200
+++ new/specfile-0.17.0/files/tasks/rpm-deps.yaml       2023-05-11 
11:43:56.000000000 +0200
@@ -1,6 +1,6 @@
 ---
+# Placeholder
 - name: Install runtime RPM dependencies
   dnf:
-    name:
-      - python3-typing-extensions
+    name: []
   become: true
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/files/tasks/rpm-test-deps.yaml 
new/specfile-0.17.0/files/tasks/rpm-test-deps.yaml
--- old/specfile-0.16.0/files/tasks/rpm-test-deps.yaml  2023-04-20 
18:57:54.000000000 +0200
+++ new/specfile-0.17.0/files/tasks/rpm-test-deps.yaml  2023-05-11 
11:43:56.000000000 +0200
@@ -4,4 +4,5 @@
     name:
       - python3-flexmock
       - python3-pytest
+      - python3-pytest-cov
   become: true
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/specfile/changelog.py 
new/specfile-0.17.0/specfile/changelog.py
--- old/specfile-0.16.0/specfile/changelog.py   2023-04-20 18:57:54.000000000 
+0200
+++ new/specfile-0.17.0/specfile/changelog.py   2023-05-11 11:43:56.000000000 
+0200
@@ -4,13 +4,19 @@
 import collections
 import copy
 import datetime
+import getpass
+import os
+import pwd
 import re
+import shutil
+import subprocess
 from typing import List, Optional, SupportsIndex, Union, overload
 
 import rpm
 
 from specfile.exceptions import SpecfileException
 from specfile.formatter import formatted
+from specfile.macros import Macros
 from specfile.sections import Section
 from specfile.utils import EVR
 
@@ -361,3 +367,49 @@
             result.extend(entry.content)
             result.extend(entry._following_lines)
         return result
+
+
+def _getent_name() -> str:
+    username = getpass.getuser()
+    pwd_struct = pwd.getpwnam(username)
+    # Use the plain username if the name field is empty
+    return pwd_struct.pw_gecos or username
+
+
+def guess_packager() -> str:
+    """
+    Guess the name and email of a packager to use for changelog entries.
+    This uses similar logic to rpmdev-packager.
+    The following places are searched for this value (in this order):
+        - $RPM_PACKAGER envvar
+        - %packager macro
+        - git config
+        - Unix username
+
+    Returns:
+        A string to use for the changelog entry author.
+        If nothing was detected, an empty string is returned.
+    """
+    if "RPM_PACKAGER" in os.environ:
+        return os.environ["RPM_PACKAGER"]
+
+    packager = Macros.expand("%packager")
+    if packager != "%packager":
+        return packager
+
+    email: str = ""
+    fullname: str = ""
+
+    if shutil.which("git"):
+        email = subprocess.run(
+            ["git", "config", "user.email"], capture_output=True, text=True
+        ).stdout.strip()
+        fullname = subprocess.run(
+            ["git", "config", "user.name"], capture_output=True, text=True
+        ).stdout.strip()
+    if not fullname:
+        fullname = _getent_name()
+
+    if fullname and email:
+        return f"{fullname} <{email}>"
+    return email or fullname
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/specfile/specfile.py 
new/specfile-0.17.0/specfile/specfile.py
--- old/specfile-0.16.0/specfile/specfile.py    2023-04-20 18:57:54.000000000 
+0200
+++ new/specfile-0.17.0/specfile/specfile.py    2023-05-11 11:43:56.000000000 
+0200
@@ -3,7 +3,6 @@
 
 import datetime
 import re
-import subprocess
 import types
 from dataclasses import dataclass
 from pathlib import Path
@@ -11,7 +10,7 @@
 
 import rpm
 
-from specfile.changelog import Changelog, ChangelogEntry
+from specfile.changelog import Changelog, ChangelogEntry, guess_packager
 from specfile.context_management import ContextManager
 from specfile.exceptions import SourceNumberException, SpecfileException
 from specfile.formatter import formatted
@@ -421,7 +420,7 @@
         Adds a new %changelog entry. Does nothing if there is no %changelog 
section
         or if %autochangelog is being used.
 
-        If not specified, author and e-mail will be determined using 
rpmdev-packager, if available.
+        If not specified, author and e-mail will be automatically determined, 
if possible.
         Timestamp, if not set, will be set to current time (in local timezone).
 
         Args:
@@ -450,12 +449,11 @@
                 if changelog and changelog[-1].extended_timestamp:
                     timestamp = datetime.datetime.now().astimezone()
                 else:
-                    timestamp = datetime.date.today()
+                    timestamp = 
datetime.datetime.now(datetime.timezone.utc).date()
             if author is None:
-                try:
-                    author = 
subprocess.check_output("rpmdev-packager").decode().strip()
-                except (FileNotFoundError, subprocess.CalledProcessError) as e:
-                    raise SpecfileException("Failed to auto-detect author") 
from e
+                author = guess_packager()
+                if not author:
+                    raise SpecfileException("Failed to auto-detect author")
             elif email is not None:
                 author += f" <{email}>"
             if changelog:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/specfile.egg-info/PKG-INFO 
new/specfile-0.17.0/specfile.egg-info/PKG-INFO
--- old/specfile-0.16.0/specfile.egg-info/PKG-INFO      2023-04-20 
18:58:05.000000000 +0200
+++ new/specfile-0.17.0/specfile.egg-info/PKG-INFO      2023-05-11 
11:44:06.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: specfile
-Version: 0.16.0
+Version: 0.17.0
 Summary: A library for parsing and manipulating RPM spec files.
 Home-page: https://github.com/packit/specfile
 Author: Red Hat
@@ -197,7 +197,8 @@
 #### Changelog
 
 ```python
-# adding a new entry, author is determined using rpmdev-packager (if available)
+# adding a new entry, author is automatically determined
+# (using the same heuristics that rpmdev-packager uses) if possible
 specfile.add_changelog_entry('New upstream release 2.1')
 
 # adding a new entry, specifying author and timestamp explicitly
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/specfile.egg-info/SOURCES.txt 
new/specfile-0.17.0/specfile.egg-info/SOURCES.txt
--- old/specfile-0.16.0/specfile.egg-info/SOURCES.txt   2023-04-20 
18:58:05.000000000 +0200
+++ new/specfile-0.17.0/specfile.egg-info/SOURCES.txt   2023-05-11 
11:44:06.000000000 +0200
@@ -134,6 +134,7 @@
 tests/unit/__init__.py
 tests/unit/test_changelog.py
 tests/unit/test_formatter.py
+tests/unit/test_guess_packager.py
 tests/unit/test_macro_definitions.py
 tests/unit/test_macros.py
 tests/unit/test_options.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/tests/full.fmf 
new/specfile-0.17.0/tests/full.fmf
--- old/specfile-0.16.0/tests/full.fmf  2023-04-20 18:57:54.000000000 +0200
+++ new/specfile-0.17.0/tests/full.fmf  2023-05-11 11:43:56.000000000 +0200
@@ -1,8 +1,10 @@
 summary:
   Unit & integration tests
 require:
+  - git-core
   - python3-flexmock
   - python3-pytest
+  - python3-pytest-cov
   - python3-specfile
 adjust:
   - when: "distro == rhel-9 or distro == centos-9 or distro == centos-stream-9"
@@ -12,4 +14,4 @@
 tag:
   - basic
 tier: 1
-test: python3 -m pytest --verbose
+test: python3 -m pytest --verbose --cov=specfile --cov-report=term-missing
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/tests/integration/test_specfile.py 
new/specfile-0.17.0/tests/integration/test_specfile.py
--- old/specfile-0.16.0/tests/integration/test_specfile.py      2023-04-20 
18:57:54.000000000 +0200
+++ new/specfile-0.17.0/tests/integration/test_specfile.py      2023-05-11 
11:43:56.000000000 +0200
@@ -3,12 +3,12 @@
 
 import copy
 import datetime
-import subprocess
 
 import pytest
 import rpm
 from flexmock import flexmock
 
+import specfile.specfile
 from specfile.exceptions import RPMException, SpecfileException
 from specfile.prep import AutopatchMacro, AutosetupMacro, PatchMacro, 
SetupMacro
 from specfile.sections import Section
@@ -111,11 +111,9 @@
 
 
 @pytest.mark.parametrize(
-    "rpmdev_packager_available, entry, author, email, timestamp, evr, result",
+    "entry, author, email, timestamp, evr, result",
     [
-        (False, None, None, None, None, None, None),
         (
-            True,
             "test",
             None,
             None,
@@ -127,7 +125,6 @@
             ),
         ),
         (
-            True,
             "test",
             None,
             None,
@@ -139,7 +136,6 @@
             ),
         ),
         (
-            True,
             "test",
             None,
             None,
@@ -151,7 +147,6 @@
             ),
         ),
         (
-            True,
             "test",
             None,
             None,
@@ -163,7 +158,6 @@
             ),
         ),
         (
-            True,
             "test",
             "Bill Packager",
             None,
@@ -174,7 +168,6 @@
             ),
         ),
         (
-            True,
             "test",
             "Bill Packager",
             "b...@packager.net",
@@ -189,7 +182,6 @@
             ),
         ),
         (
-            True,
             "test",
             "Bill Packager",
             "b...@packager.net",
@@ -204,7 +196,6 @@
             ),
         ),
         (
-            True,
             ["line 1", "line 2"],
             "Bill Packager",
             "b...@packager.net",
@@ -223,7 +214,6 @@
 )
 def test_add_changelog_entry(
     spec_minimal,
-    rpmdev_packager_available,
     entry,
     author,
     email,
@@ -231,22 +221,14 @@
     evr,
     result,
 ):
-    if not rpmdev_packager_available:
-        flexmock(subprocess).should_receive("check_output").with_args(
-            "rpmdev-packager"
-        ).and_raise(FileNotFoundError)
-    elif author is None:
-        flexmock(subprocess).should_receive("check_output").with_args(
-            "rpmdev-packager"
-        ).and_return(b"John Doe <j...@doe.net>")
+    if author is None:
+        
flexmock(specfile.specfile).should_receive("guess_packager").and_return(
+            "John Doe <j...@doe.net>"
+        ).once()
     spec = Specfile(spec_minimal)
-    if not rpmdev_packager_available:
-        with pytest.raises(SpecfileException):
-            spec.add_changelog_entry(entry, author, email, timestamp, evr)
-    else:
-        spec.add_changelog_entry(entry, author, email, timestamp, evr)
-        with spec.sections() as sections:
-            assert sections.changelog[: len(result)] == result
+    spec.add_changelog_entry(entry, author, email, timestamp, evr)
+    with spec.sections() as sections:
+        assert sections.changelog[: len(result)] == result
 
 
 @pytest.mark.parametrize(
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/specfile-0.16.0/tests/unit/test_guess_packager.py 
new/specfile-0.17.0/tests/unit/test_guess_packager.py
--- old/specfile-0.16.0/tests/unit/test_guess_packager.py       1970-01-01 
01:00:00.000000000 +0100
+++ new/specfile-0.17.0/tests/unit/test_guess_packager.py       2023-05-11 
11:43:56.000000000 +0200
@@ -0,0 +1,121 @@
+# Copyright Contributors to the Packit project.
+# SPDX-License-Identifier: MIT
+
+import subprocess
+from pathlib import Path
+
+import pytest
+from flexmock import flexmock
+
+import specfile.changelog
+from specfile.changelog import guess_packager
+from specfile.macros import Macros
+
+
+@pytest.fixture
+def clean_guess_packager(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> 
None:
+    """
+    Ensure a clean environment
+    """
+    # For $RPM_PACKAGER
+    monkeypatch.delenv("RPM_PACKAGER", False)
+    # Make sure git doesn't read existing config
+    monkeypatch.setenv("HOME", "/dev/null")
+    monkeypatch.delenv("XDG_CONFIG_HOME", False)
+    monkeypatch.chdir(tmp_path)
+    # For %packager
+    Macros.remove("packager")
+    # For Unix passwd guessing
+    flexmock(specfile.changelog).should_receive("_getent_name").and_return("")
+
+
+@pytest.fixture
+def set_packager_env(monkeypatch: pytest.MonkeyPatch) -> str:
+    packager = "Patty Packager <pa...@packager.me>"
+    monkeypatch.setenv("RPM_PACKAGER", packager)
+    return packager
+
+
+@pytest.fixture
+def set_packager_git(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> str:
+    packager = "Packager, Patty <packa...@patty.dev>"
+
+    monkeypatch.chdir(tmp_path)
+    subprocess.run(["git", "init", "."], check=True, capture_output=True)
+    subprocess.run(
+        ["git", "config", "user.name", "Packager, Patty"],
+        check=True,
+        capture_output=True,
+    )
+    subprocess.run(
+        ["git", "config", "user.email", "packa...@patty.dev"],
+        check=True,
+        capture_output=True,
+    )
+    return packager
+
+
+@pytest.fixture
+def set_packager_macro() -> str:
+    packager = "Patricia Packager"
+    Macros.define("packager", packager)
+    return packager
+
+
+@pytest.fixture
+def set_packager_passwd() -> str:
+    packager = "Ms. Packager"
+    
flexmock(specfile.changelog).should_receive("_getent_name").and_return(packager)
+    return packager
+
+
+def test_guess_packager_env(clean_guess_packager, set_packager_env):
+    assert guess_packager() == set_packager_env
+
+
+def test_guess_packager_macro(clean_guess_packager, set_packager_macro):
+    assert guess_packager() == set_packager_macro
+
+
+def test_guess_packager_git(clean_guess_packager, set_packager_git):
+    assert guess_packager() == set_packager_git
+
+
+def test_guess_packager_passwd(clean_guess_packager, set_packager_passwd):
+    assert guess_packager() == set_packager_passwd
+
+
+def test_guess_packager_pref1(
+    clean_guess_packager,
+    set_packager_env,
+    set_packager_macro,
+    set_packager_git,
+    set_packager_passwd,
+):
+    assert guess_packager() == set_packager_env
+
+
+def test_guess_packager_pref2(
+    clean_guess_packager, set_packager_macro, set_packager_git, 
set_packager_passwd
+):
+    assert guess_packager() == set_packager_macro
+
+
+def test_guess_packager_pref3(
+    clean_guess_packager, set_packager_git, set_packager_passwd
+):
+    assert guess_packager() == set_packager_git
+
+
+def test_guess_packager_pref4(
+    clean_guess_packager, set_packager_git, set_packager_passwd
+):
+    subprocess.run(["git", "config", "--unset", "user.email"])
+    assert guess_packager() == "Packager, Patty"
+
+
+def test_guess_packager_empty(clean_guess_packager):
+    """
+    The function should return an empty string if it can't detect the packager
+    """
+    assert guess_packager() == ""

Reply via email to