This is an automated email from the ASF dual-hosted git repository. sbp pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push: new c1c98bd Add a test framework to the API client script c1c98bd is described below commit c1c98bd8c31353fe932cf5e7fd5353dc35f5afa7 Author: Sean B. Palmer <s...@miscoranda.com> AuthorDate: Fri Jul 4 20:14:27 2025 +0100 Add a test framework to the API client script --- client/atr | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- client/atr.lock | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/client/atr b/client/atr index 19fad3c..08fe208 100755 --- a/client/atr +++ b/client/atr @@ -25,10 +25,11 @@ # "filelock", # "platformdirs", # "pyjwt", +# "pytest>=8.4.1", # "strictyaml", # ] # [tool.uv] -# exclude-newer = "2025-07-04T13:08:00Z" +# exclude-newer = "2025-07-04T19:04:51Z" # /// # Guide to contributors: @@ -53,8 +54,12 @@ import datetime import json import logging import os +import pathlib +import re +import subprocess import sys -from typing import TYPE_CHECKING, Any, Literal +import tempfile +from typing import TYPE_CHECKING, Annotated, Any, Literal import aiohttp # type: ignore[import-not-found] import cyclopts # type: ignore[import-not-found] @@ -64,11 +69,11 @@ import platformdirs # type: ignore[import-not-found] import strictyaml # type: ignore[import-not-found] if TYPE_CHECKING: - import pathlib from collections.abc import Generator APP: cyclopts.App = cyclopts.App() CONFIG: cyclopts.App = cyclopts.App(name="config", help="Configuration operations.") +DEV: cyclopts.App = cyclopts.App(name="dev", help="Developer operations.") JWT: cyclopts.App = cyclopts.App(name="jwt", help="JWT operations.") LOGGER = logging.getLogger(__name__) RELEASE: cyclopts.App = cyclopts.App(name="release", help="Release operations.") @@ -87,6 +92,7 @@ YAML_SCHEMA: strictyaml.Map = strictyaml.Map( ) APP.command(CONFIG) +APP.command(DEV) APP.command(JWT) APP.command(RELEASE) @@ -108,6 +114,24 @@ def app_config_path() -> None: print(config_path()) +@DEV.command(name="lock", help="Regenerate uv lockfile.") +def app_dev_lock() -> None: + subprocess.check_call(["uv", "lock", "--script", str(pathlib.Path(__file__))]) + + +@DEV.command(name="stamp", help="Update date stamp in header.") +def app_dev_stamp() -> None: + path = pathlib.Path(__file__) + text = path.read_text() + ts = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + new_text = re.sub(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z", ts, text) + if text == new_text: + LOGGER.info("No stamp updated.") + return + path.write_text(new_text, "utf-8") + LOGGER.info(f"Stamp updated to {ts}.") + + @APP.command(name="drop", help="Remove a configuration key using dot notation.") def app_drop(path: str) -> None: parts = path.split(".") @@ -253,6 +277,28 @@ def app_show(path: str) -> None: print(value) +@APP.command(name="test", help="Run tests.") +def app_test(q: Annotated[bool, cyclopts.Parameter(alias="-q")] = False, *pytest_args: str) -> None: + import pytest + + cwd = os.getcwd() + with tempfile.TemporaryDirectory() as td: + p = pathlib.Path(td, "atr_api_client.py") + p.write_bytes(pathlib.Path(__file__).read_bytes()) + os.chdir(td) + prev = os.environ.get("ATR_CLIENT_CONFIG_PATH") + os.environ["ATR_CLIENT_CONFIG_PATH"] = str(pathlib.Path(td, "atr_test.yaml")) + try: + args = (["-q"] if q else []) + list(pytest_args) + [str(p)] + sys.exit(pytest.main(args)) + finally: + if prev is None: + os.environ.pop("ATR_CLIENT_CONFIG_PATH", None) + else: + os.environ["ATR_CLIENT_CONFIG_PATH"] = prev + os.chdir(cwd) + + def config_drop(cfg: dict[str, Any], parts: list[str]) -> None: config_walk(cfg, parts, "drop") @@ -272,6 +318,8 @@ def config_lock(write: bool = False) -> Generator[dict[str, Any]]: def config_path() -> pathlib.Path: + if env := os.getenv("ATR_CLIENT_CONFIG_PATH"): + return pathlib.Path(env).expanduser() return platformdirs.user_config_path("atr", appauthor="ASF") / "atr.yaml" @@ -337,6 +385,16 @@ def main() -> None: APP() +def test_config_set_get_roundtrip() -> None: + config: dict[str, object] = {} + config_set(config, ["abc", "pqr"], 123) + assert config_get(config, ["abc", "pqr"]) == 123 + + +def test_timestamp_format_epoch() -> None: + assert timestamp_format(0) == "01 Jan 1970 at 00:00:00 UTC" + + def timestamp_format(ts: int | str | None) -> str | None: if ts is None: return None diff --git a/client/atr.lock b/client/atr.lock index 239111f..143483e 100644 --- a/client/atr.lock +++ b/client/atr.lock @@ -2,7 +2,7 @@ version = 1 requires-python = ">=3.13" [options] -exclude-newer = "2025-07-04T13:08:00Z" +exclude-newer = "2025-07-04T19:04:51Z" [manifest] requirements = [ @@ -11,6 +11,7 @@ requirements = [ { name = "filelock" }, { name = "platformdirs" }, { name = "pyjwt" }, + { name = "pytest", specifier = ">=8.4.1" }, { name = "strictyaml" }, ] @@ -78,6 +79,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl", hash = "sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3", size = 63815 }, ] +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335 }, +] + [[package]] name = "cyclopts" version = "3.22.1" @@ -172,6 +182,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442 }, ] +[[package]] +name = "iniconfig" +version = "2.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f2/97/ebf4da567aa6827c909642694d71c9fcf53e5b504f2d96afea02718862f3/iniconfig-2.1.0.tar.gz", hash = "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7", size = 4793 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2c/e1/e6716421ea10d38022b952c159d5161ca1193197fb744506875fbb87ea7b/iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760", size = 6050 }, +] + [[package]] name = "markdown-it-py" version = "3.0.0" @@ -238,6 +257,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d8/30/9aec301e9772b098c1f5c0ca0279237c9766d94b97802e9888010c64b0ed/multidict-6.6.3-py3-none-any.whl", hash = "sha256:8db10f29c7541fc5da4defd8cd697e1ca429db743fa716325f236079b96f775a", size = 12313 }, ] +[[package]] +name = "packaging" +version = "25.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a1/d4/1fc4078c65507b51b96ca8f8c3ba19e6a61c8253c72794544580a7b6c24d/packaging-25.0.tar.gz", hash = "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f", size = 165727 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", size = 66469 }, +] + [[package]] name = "platformdirs" version = "4.3.8" @@ -247,6 +275,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/fe/39/979e8e21520d4e47a0bbe349e2713c0aac6f3d853d0e5b34d76206c439aa/platformdirs-4.3.8-py3-none-any.whl", hash = "sha256:ff7059bb7eb1179e2685604f4aaf157cfd9535242bd23742eadc3c13542139b4", size = 18567 }, ] +[[package]] +name = "pluggy" +version = "1.6.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538 }, +] + [[package]] name = "propcache" version = "0.3.2" @@ -306,6 +343,22 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/61/ad/689f02752eeec26aed679477e80e632ef1b682313be70793d798c1d5fc8f/PyJWT-2.10.1-py3-none-any.whl", hash = "sha256:dcdd193e30abefd5debf142f9adfcdd2b58004e644f25406ffaebd50bd98dacb", size = 22997 }, ] +[[package]] +name = "pytest" +version = "8.4.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/08/ba/45911d754e8eba3d5a841a5ce61a65a685ff1798421ac054f85aa8747dfb/pytest-8.4.1.tar.gz", hash = "sha256:7c67fd69174877359ed9371ec3af8a3d2b04741818c51e5e99cc1742251fa93c", size = 1517714 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/29/16/c8a903f4c4dffe7a12843191437d7cd8e32751d5de349d45d3fe69544e87/pytest-8.4.1-py3-none-any.whl", hash = "sha256:539c70ba6fcead8e78eebbf1115e8b589e7565830d7d006a8723f19ac8a0afb7", size = 365474 }, +] + [[package]] name = "python-dateutil" version = "2.9.0.post0" --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@tooling.apache.org For additional commands, e-mail: commits-h...@tooling.apache.org