From 291ca31c68c8564da6f1ad2a6a6157e604cc3a25 Mon Sep 17 00:00:00 2001 From: benoit74 Date: Fri, 16 Feb 2024 08:57:31 +0100 Subject: [PATCH] Fix test for situation where tests are ran outside a Github repo --- tests/test_metadata.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 76f4689..50dec68 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -4,6 +4,7 @@ import pytest from hatch_openzim.metadata import update +from hatch_openzim.utils import DEFAULT_GITHUB_INFO @pytest.fixture @@ -17,6 +18,11 @@ def dynamic_metadata(): ] +@pytest.fixture +def root_folder() -> Path: + return Path(os.path.dirname(os.path.abspath(__file__))).parent + + @pytest.fixture def metadata(dynamic_metadata): return { @@ -25,9 +31,13 @@ def metadata(dynamic_metadata): } -def test_metadata_nominal(metadata): +def git_config_exists(root_folder: Path) -> bool: + return (root_folder / ".git/config").exists() + + +def test_metadata_nominal(metadata, root_folder): update( - root=str(Path(os.path.dirname(os.path.abspath(__file__))).parent), + root=str(root_folder), config={}, metadata=metadata, ) @@ -43,7 +53,11 @@ def test_metadata_nominal(metadata): assert metadata["license"] == {"text": "GPL-3.0-or-later"} assert metadata["urls"] == { "Donate": "https://www.kiwix.org/en/support-us/", - "Homepage": "https://github.com/openzim/hatch-openzim", + "Homepage": ( + "https://github.com/openzim/hatch-openzim" + if git_config_exists(root_folder) + else DEFAULT_GITHUB_INFO.homepage + ), }