public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/pyproject-rpm-macros] f43: Add basic eval tests
@ 2026-10-13 12:15 
  0 siblings, 0 replies; only message in thread
From:  @ 2026-10-13 12:15 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/pyproject-rpm-macros
            Branch : f43
            Commit : 56853f4750e4332010032c52598e72449d296d98
            Author : Miro Hrončok <miro@hroncok.cz>
            Date   : 2026-10-13T09:30:01+00:00
            Stats  : +87/-0 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/pyproject-rpm-macros/c/56853f4750e4332010032c52598e72449d296d98?branch=f43

            Log:
            Add basic eval tests

Assisted-By: Claude Opus 4.6

---
diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec
index 12f675f..2a92829 100644
--- a/pyproject-rpm-macros.spec
+++ b/pyproject-rpm-macros.spec
@@ -39,6 +39,7 @@ Source:         pyproject_getopt.lua
 Source:         compare_mandata.py
 Source:         test_dependency_overrides.py
 Source:         test_pyproject_buildrequires.py
+Source:         test_pyproject_evals.py
 Source:         test_pyproject_getopt.lua
 Source:         test_pyproject_getopt_consistency.py
 Source:         test_pyproject_getopt_parser.py

diff --git a/test_pyproject_evals.py b/test_pyproject_evals.py
new file mode 100644
index 0000000..78ffdc1
--- /dev/null
+++ b/test_pyproject_evals.py
@@ -0,0 +1,86 @@
+"""Test RPM macro expansion from macros.pyproject.
+
+This test was added late in the pyproject-rpm-macros life cycle and does
+not include all macros.
+
+When there is a regression that can be easily tested here, we'll add it.
+"""
+
+import os
+import subprocess
+from pathlib import Path
+
+import pytest
+
+BASEDIR = Path(__file__).parent
+
+PRELOAD_LUA = (
+    'package.preload["fedora.rpm.pyproject_getopt"]'
+    f' = loadfile("{BASEDIR}/pyproject_getopt.lua")'
+)
+
+
+def rpm_eval(macro_call):
+    """Expand an RPM macro using the local macros.pyproject and Lua files."""
+    r = subprocess.run(
+        [
+            "rpm",
+            f"--macros=/usr/lib/rpm/macros:/usr/lib/rpm/macros.d/macros.*:{BASEDIR}/macros.aaa-pyproject-srpm:{BASEDIR}/macros.pyproject",
+            "--eval",
+            f"%{{lua:{PRELOAD_LUA}}}{macro_call}",
+        ],
+        capture_output=True,
+        text=True,
+        env={**os.environ, "LANG": "C.UTF-8"},
+    )
+    assert r.returncode == 0, f"rpm --eval failed:\n{r.stderr}"
+    return r.stdout.strip()
+
+
+class TestPyprojectExtrasSubpkg:
+    def test_short_options(self):
+        r = rpm_eval("%pyproject_extras_subpkg -n test-pkg -f /dev/null myextra")
+        assert "%package -n test-pkg+myextra" in r
+
+    def test_long_name(self):
+        r = rpm_eval("%pyproject_extras_subpkg --name test-pkg -f /dev/null myextra")
+        assert "%package -n test-pkg+myextra" in r
+
+    def test_multiple_extras(self):
+        r = rpm_eval("%pyproject_extras_subpkg -n test-pkg -f /dev/null extra1 extra2")
+        assert "%package -n test-pkg+extra1" in r
+        assert "%package -n test-pkg+extra2" in r
+
+
+class TestNormalizeName:
+    @pytest.mark.parametrize(
+        "input, expected",
+        [
+            ("Foo_Bar.baz", "foo-bar-baz"),
+            ("UPPER", "upper"),
+            ("already-normalized", "already-normalized"),
+            ("dots...dashes---underscores___mixed", "dots-dashes-underscores-mixed"),
+            ("simple", "simple"),
+        ],
+    )
+    def test_normalize(self, input, expected):
+        assert rpm_eval(f"%__pyproject_normalize_name {input}") == expected
+
+
+@pytest.mark.parametrize(
+    "macro",
+    [
+        "pyproject_files",
+        "_pyproject_modules",
+        "_pyproject_ghost_distinfo",
+    ],
+)
+class TestPathMacros:
+    def test_without_dist_name(self, macro):
+        assert "pyproject-" in rpm_eval(f"%{macro}")
+
+    def test_with_short_dist_name(self, macro):
+        assert rpm_eval(f"%{macro} -D My_Package").endswith("-my-package")
+
+    def test_with_long_dist_name(self, macro):
+        assert rpm_eval(f"%{macro} --dist-name My_Package").endswith("-my-package")

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-13 12:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-13 12:15 [rpms/pyproject-rpm-macros] f43: Add basic eval tests 

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox