From a1ed0b7dbcea240a421d81a64ffa4fd767257d74 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Thu, 2 Oct 2025 18:37:05 +0100 Subject: [PATCH] TST: Add a test for _build --- arch/meson.build | 1 + arch/tests/test_build.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 arch/tests/test_build.py diff --git a/arch/meson.build b/arch/meson.build index 92d4360532..366cd31239 100644 --- a/arch/meson.build +++ b/arch/meson.build @@ -71,6 +71,7 @@ subdir('univariate') subdirs_list = [ '__future__', + '_build', 'bootstrap', 'compat', 'covariance', diff --git a/arch/tests/test_build.py b/arch/tests/test_build.py new file mode 100644 index 0000000000..fc9383a27e --- /dev/null +++ b/arch/tests/test_build.py @@ -0,0 +1,36 @@ +import tempfile + +import pytest + +from arch import __version__, version_tuple + +try: + from arch._build.git_version import get_version, write_version_file + + HAS_SETUPTOOLS_SCM = True +except ImportError: + HAS_SETUPTOOLS_SCM = False + + +@pytest.mark.skipif(not HAS_SETUPTOOLS_SCM, reason="setuptools_scm is not installed") +def test_get_version(): + try: + version, version_fields = get_version() + + assert isinstance(version, str) + assert isinstance(version_fields, tuple) + assert all(isinstance(v, (int, str)) for v in version_fields) + except LookupError: + pytest.skip("No git repository found") + + +@pytest.mark.skipif(not HAS_SETUPTOOLS_SCM, reason="setuptools_scm is not installed") +def test_write_version_file(): + with tempfile.NamedTemporaryFile(delete=False) as tmpfile: + + write_version_file(tmpfile.name, __version__, version_tuple) + with open(tmpfile.name, "r") as f: + content = f.read() + + assert f"__version__ = version = '{__version__}'" in content + assert f"__version_tuple__ = version_tuple = {version_tuple}" in content