From 03872fe1d5fe2a48bbff393b0c63ce595a2a0bdf Mon Sep 17 00:00:00 2001 From: Stephane Restani Date: Tue, 28 Jul 2026 11:14:31 +0200 Subject: [PATCH 1/2] [cleanup] Remove useless tempfiles --- tests/test_tracer_client.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/test_tracer_client.py b/tests/test_tracer_client.py index 784a578..fc6d4fc 100644 --- a/tests/test_tracer_client.py +++ b/tests/test_tracer_client.py @@ -182,9 +182,6 @@ def test_analyse_plots(monkeypatch): {"status": "success", "results": {"analysis_id": "an-analysis-id"}}, ) client: TracerClient = _client(monkeypatch, platform="plots_analysis") - with tempfile.NamedTemporaryFile() as tmp: - with open(tmp.name, "w") as f: - json.dump({"type": "FeatureCollection", "features": []}, f) assert ( client.analyze_plots( "a-group-id", @@ -246,9 +243,6 @@ def test_analyse_precheck(monkeypatch): } responses.get("https://precheck_data_url.example.com/", json=precheck) client: TracerClient = _client(monkeypatch, platform="plots_analysis") - with tempfile.NamedTemporaryFile() as tmp: - with open(tmp.name, "w") as f: - json.dump({"type": "FeatureCollection", "features": []}, f) assert ( client.analyze_plots_precheck( "a-group-id", @@ -438,9 +432,6 @@ def test_create_plots_analysis_report_precheck(monkeypatch): }, ) client: TracerClient = _client(monkeypatch, platform="plots_analysis") - with tempfile.NamedTemporaryFile() as tmp: - with open(tmp.name, "w") as f: - json.dump({"type": "FeatureCollection", "features": []}, f) assert client.create_plots_analysis_report_precheck( "an-analysis-id", "foobar", @@ -489,9 +480,6 @@ def test_create_plots_analysis_report(monkeypatch): {"status": "success", "results": {"plots_analysis_report_id": "a-report-id"}}, ) client: TracerClient = _client(monkeypatch, platform="plots_analysis") - with tempfile.NamedTemporaryFile() as tmp: - with open(tmp.name, "w") as f: - json.dump({"type": "FeatureCollection", "features": []}, f) assert ( client.create_plots_analysis_report( "an-analysis-id", From 8bd6308bd3077a64d56a7e39d4620cd383ed1112 Mon Sep 17 00:00:00 2001 From: Stephane Restani Date: Tue, 28 Jul 2026 11:15:05 +0200 Subject: [PATCH 2/2] [tracer] Allow specifying a tag when running a methodology --- src/picterra/tracer_client.py | 4 ++++ tests/test_tracer_client.py | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/picterra/tracer_client.py b/src/picterra/tracer_client.py index 1788d21..52282d2 100644 --- a/src/picterra/tracer_client.py +++ b/src/picterra/tracer_client.py @@ -272,6 +272,7 @@ def analyze_plots( plot_ids: List[str], date_from: datetime.date, date_to: datetime.date, + tag_name: Optional[str] = None, ) -> str: """ Runs the analysis for a given date over the plot ids of the specified plot group, @@ -285,6 +286,7 @@ def analyze_plots( that **the date that make sense are methodology dependent**, so please check the methodology of the plots group beforehand date_to: end point in time at which the analysis should be evaluated. + tag_name: name of the methodology version to run Returns: str: the analysis id. @@ -296,6 +298,8 @@ def analyze_plots( "date_from": date_from.isoformat(), "date_to": date_to.isoformat(), } + if tag_name is not None: + data.update({"tag_name": tag_name}) resp = self.sess.post( self._full_url(f"plots_groups/{plots_group_id}/analysis/"), json=data ) diff --git a/tests/test_tracer_client.py b/tests/test_tracer_client.py index fc6d4fc..f4cdf40 100644 --- a/tests/test_tracer_client.py +++ b/tests/test_tracer_client.py @@ -3,6 +3,7 @@ import os import tempfile +import pytest import responses from picterra import TracerClient @@ -143,8 +144,9 @@ def test_update_plots_group_plots(monkeypatch): client.update_plots_group_plots("group-id", [tmp.name]) +@pytest.mark.parametrize("tag_name", [None, "v0"]) @responses.activate -def test_analyse_plots(monkeypatch): +def test_analyse_plots(monkeypatch, tag_name): _add_api_response( plots_analysis_api_url("upload/file/"), responses.POST, @@ -163,18 +165,19 @@ def test_analyse_plots(monkeypatch): ) ], ) + expected_params = { + "analysis_name": "foobar", + "upload_id": "an-upload-id", + "date_from": "2023-01-01", + "date_to": "2025-01-01", + } + if tag_name is not None: + expected_params.update({ "tag_name": tag_name }) _add_api_response( plots_analysis_api_url("plots_groups/a-group-id/analysis/"), responses.POST, OP_RESP, - match=responses.matchers.json_params_matcher( - { - "analysis_name": "foobar", - "upload_id": "an-upload-id", - "date_from": "2023-01-01", - "date_to": "2025-01-01", - } - ), + match=responses.matchers.json_params_matcher(expected_params), ) _add_api_response( plots_analysis_api_url(f"operations/{OPERATION_ID}/"), @@ -189,6 +192,7 @@ def test_analyse_plots(monkeypatch): ["uno", "dos"], datetime.date.fromisoformat("2023-01-01"), datetime.date.fromisoformat("2025-01-01"), + tag_name=tag_name, ) == "an-analysis-id" )