From f42a61f44e55b670344600866b4176c17b02e8f4 Mon Sep 17 00:00:00 2001 From: charan Date: Sat, 5 Dec 2026 00:39:09 +0530 Subject: [PATCH 1/2] fix: record failed and not-attempted files in download manifest (#131) --- databusclient/api/download.py | 201 ++++++++++++++++++------------ databusclient/manifest/context.py | 20 ++- databusclient/manifest/summary.py | 6 +- databusclient/manifest/writer.py | 2 + databusclient/workflow/engine.py | 14 ++- tests/test_manifest.py | 92 +++++++++++++- tests/test_manifest_failures.py | 117 +++++++++++++++++ 7 files changed, 360 insertions(+), 92 deletions(-) create mode 100644 tests/test_manifest_failures.py diff --git a/databusclient/api/download.py b/databusclient/api/download.py index f2aead78..2b834817 100644 --- a/databusclient/api/download.py +++ b/databusclient/api/download.py @@ -912,27 +912,34 @@ def _download_files( the versioned databus-python-client default. checksums: Dictionary mapping URLs to their expected checksums. """ - for url in urls: + for idx, url in enumerate(urls): expected = None if checksums and isinstance(checksums, dict): expected = checksums.get(url) - _download_file( - url=url, - localDir=localDir, - vault_token_file=vault_token_file, - databus_key=databus_key, - auth_url=auth_url, - client_id=client_id, - compression=compression, - convert_format=convert_format, - graph_name=graph_name, - base_uri=base_uri, - graph_mode=graph_mode, - validate_checksum=validate_checksum, - expected_checksum=expected, - manifest_context=manifest_context, - user_agent=user_agent, - ) + try: + _download_file( + url=url, + localDir=localDir, + vault_token_file=vault_token_file, + databus_key=databus_key, + auth_url=auth_url, + client_id=client_id, + compression=compression, + convert_format=convert_format, + graph_name=graph_name, + base_uri=base_uri, + graph_mode=graph_mode, + validate_checksum=validate_checksum, + expected_checksum=expected, + manifest_context=manifest_context, + user_agent=user_agent, + ) + except Exception as e: + if manifest_context is not None: + manifest_context.record_file_error(url, e) + for remaining_url in urls[idx + 1:]: + manifest_context.record_file_not_attempted(remaining_url) + raise def _get_sparql_query_of_collection(uri: str, databus_key: str | None = None) -> str: @@ -1195,6 +1202,31 @@ def _download_version( ) +def _collect_artifact_files( + uri: str, + all_versions: bool = False, + databus_key: str = None, +) -> tuple[List[str], dict]: + """Collect all file download URLs and checksums for an artifact.""" + json_str = fetch_databus_jsonld(uri, databus_key=databus_key) + versions = _get_databus_versions_of_artifact(json_str, all_versions=all_versions) + if isinstance(versions, str): + versions = [versions] + + all_urls: List[str] = [] + all_checksums: dict = {} + for version_uri in versions: + print(f"Downloading version: {version_uri}") + version_json = fetch_databus_jsonld(version_uri, databus_key=databus_key) + all_urls.extend(_get_file_download_urls_from_artifact_jsonld(version_json)) + try: + all_checksums.update(_extract_checksums_from_jsonld(version_json)) + except Exception: + pass + + return all_urls, all_checksums + + def _download_artifact( uri: str, localDir: str, @@ -1231,38 +1263,26 @@ def _download_artifact( user_agent: HTTP User-Agent for file HEAD and GET requests. None uses the versioned databus-python-client default. """ - json_str = fetch_databus_jsonld(uri, databus_key=databus_key) - versions = _get_databus_versions_of_artifact(json_str, all_versions=all_versions) - if isinstance(versions, str): - versions = [versions] - for version_uri in versions: - print(f"Downloading version: {version_uri}") - json_str = fetch_databus_jsonld(version_uri, databus_key=databus_key) - file_urls = _get_file_download_urls_from_artifact_jsonld(json_str) - # extract checksums for this version - checksums: dict = {} - try: - checksums = _extract_checksums_from_jsonld(json_str) - except Exception: - checksums = {} - - _download_files( - file_urls, - localDir, - vault_token_file=vault_token_file, - databus_key=databus_key, - auth_url=auth_url, - client_id=client_id, - compression=compression, - convert_format=convert_format, - graph_name=graph_name, - base_uri=base_uri, - graph_mode=graph_mode, - manifest_context=manifest_context, - validate_checksum=validate_checksum, - checksums=checksums, - user_agent=user_agent, - ) + file_urls, checksums = _collect_artifact_files( + uri, all_versions=all_versions, databus_key=databus_key + ) + _download_files( + file_urls, + localDir, + vault_token_file=vault_token_file, + databus_key=databus_key, + auth_url=auth_url, + client_id=client_id, + compression=compression, + convert_format=convert_format, + graph_name=graph_name, + base_uri=base_uri, + graph_mode=graph_mode, + manifest_context=manifest_context, + validate_checksum=validate_checksum, + checksums=checksums, + user_agent=user_agent, + ) def _get_databus_versions_of_artifact( @@ -1364,25 +1384,34 @@ def _download_group( """ json_str = fetch_databus_jsonld(uri, databus_key=databus_key) artifacts = _get_databus_artifacts_of_group(json_str) + + all_urls: List[str] = [] + all_checksums: dict = {} for artifact_uri in artifacts: print(f"Download artifact: {artifact_uri}") - _download_artifact( - artifact_uri, - localDir, - all_versions=all_versions, - vault_token_file=vault_token_file, - databus_key=databus_key, - auth_url=auth_url, - client_id=client_id, - compression=compression, - convert_format=convert_format, - graph_name=graph_name, - base_uri=base_uri, - graph_mode=graph_mode, - manifest_context=manifest_context, - validate_checksum=validate_checksum, - user_agent=user_agent, + urls, checksums = _collect_artifact_files( + artifact_uri, all_versions=all_versions, databus_key=databus_key ) + all_urls.extend(urls) + all_checksums.update(checksums) + + _download_files( + all_urls, + localDir, + vault_token_file=vault_token_file, + databus_key=databus_key, + auth_url=auth_url, + client_id=client_id, + compression=compression, + convert_format=convert_format, + graph_name=graph_name, + base_uri=base_uri, + graph_mode=graph_mode, + manifest_context=manifest_context, + validate_checksum=validate_checksum, + checksums=all_checksums, + user_agent=user_agent, + ) def _get_databus_artifacts_of_group(json_str: str) -> List[str]: @@ -1502,23 +1531,29 @@ def download( ) # Call the worker to download the single file (passes expected checksum) - _download_file( - databusURI, - localDir, - vault_token_file=token, - databus_key=databus_key, - auth_url=auth_url, - client_id=client_id, - compression=compression, - convert_format=convert_format, - graph_name=graph_name, - base_uri=base_uri, - graph_mode=graph_mode, - manifest_context=manifest_context, - validate_checksum=validate_checksum, - expected_checksum=expected, - user_agent=user_agent, - ) + try: + _download_file( + databusURI, + localDir, + vault_token_file=token, + databus_key=databus_key, + auth_url=auth_url, + client_id=client_id, + compression=compression, + convert_format=convert_format, + graph_name=graph_name, + base_uri=base_uri, + graph_mode=graph_mode, + validate_checksum=validate_checksum, + expected_checksum=expected, + manifest_context=manifest_context, + user_agent=user_agent, + ) + except Exception as e: + if manifest_context is not None: + manifest_context.record_file_error(databusURI, e) + raise + elif version is not None: print(f"Downloading version: {databusURI}") _download_version( diff --git a/databusclient/manifest/context.py b/databusclient/manifest/context.py index 2e6cf324..6382c207 100644 --- a/databusclient/manifest/context.py +++ b/databusclient/manifest/context.py @@ -77,7 +77,7 @@ def record_file( Args: url: The file URL or Databus URI that was processed. - status: 'success' or 'failed'. + status: 'success', 'failed' or 'not_attempted'. sha256: SHA-256 checksum of the file (if available). size_bytes: File size in bytes (if available). compression: Compression format of the file (if applicable). @@ -123,6 +123,10 @@ def record_file_error(self, url: str, exc: Exception) -> None: error_traceback=tb.format_exc(), ) + def record_file_not_attempted(self, url: str) -> None: + """Record a requested file that was not attempted because an earlier error aborted the operation.""" + self.record_file(url=url, status="not_attempted") + def record_operation_error(self, exc: Exception) -> None: """Record a top-level operation failure. @@ -144,18 +148,30 @@ def summary(self) -> dict: """Return execution summary counts. Returns: - Dict with total, succeeded, failed counts and total_bytes. + Dict with total, succeeded, failed, not_attempted counts, + total_bytes, and overall status. """ succeeded = sum(1 for f in self.files if f["status"] == "success") failed = sum(1 for f in self.files if f["status"] == "failed") + not_attempted = sum(1 for f in self.files if f["status"] == "not_attempted") total_bytes = sum( f.get("size_bytes", 0) for f in self.files if f["status"] == "success" ) + + if succeeded > 0 and (failed > 0 or not_attempted > 0 or self.operation_error is not None): + status = "partial" + elif failed > 0 or not_attempted > 0 or self.operation_error is not None: + status = "failed" + else: + status = "completed" + return { "total": len(self.files), "succeeded": succeeded, "failed": failed, + "not_attempted": not_attempted, "total_bytes": total_bytes, + "status": status, } def merge_from(self, other: "ManifestContext", step_name: Optional[str] = None) -> None: diff --git a/databusclient/manifest/summary.py b/databusclient/manifest/summary.py index a8bd6e0d..60f48fa4 100644 --- a/databusclient/manifest/summary.py +++ b/databusclient/manifest/summary.py @@ -64,7 +64,11 @@ def format_summary(manifest: Dict[str, Any]) -> str: result = manifest.get("dbus:executionResult", {}) succeeded = result.get("dbus:succeeded", 0) failed = result.get("dbus:failed", 0) - lines.append(f"Files : {succeeded} succeeded \u00b7 {failed} failed") + not_attempted = result.get("dbus:notAttempted", 0) + files_line = f"Files : {succeeded} succeeded \u00b7 {failed} failed" + if not_attempted: + files_line += f" \u00b7 {not_attempted} not attempted" + lines.append(files_line) total_bytes = result.get("dbus:totalBytes", 0) if command == "download" and total_bytes: diff --git a/databusclient/manifest/writer.py b/databusclient/manifest/writer.py index 7e88e67f..6273bffc 100644 --- a/databusclient/manifest/writer.py +++ b/databusclient/manifest/writer.py @@ -95,7 +95,9 @@ def build_manifest_dict(context: ManifestContext) -> dict: "dbus:totalFiles": summary["total"], "dbus:succeeded": summary["succeeded"], "dbus:failed": summary["failed"], + "dbus:notAttempted": summary["not_attempted"], "dbus:totalBytes": summary["total_bytes"], + "dbus:status": summary["status"], } if context.operation_error: diff --git a/databusclient/workflow/engine.py b/databusclient/workflow/engine.py index 8a15e9ea..f984c6c0 100644 --- a/databusclient/workflow/engine.py +++ b/databusclient/workflow/engine.py @@ -144,12 +144,16 @@ def _finish_step_manifest( return self.manifest_context.merge_from(step_manifest_ctx, step_name=step_name) if error is not None: - self.manifest_context.record_file( - url="(no file-level detail -- step failed before producing one)", - status="failed", - error_message=str(error), + has_failed = any( + f.get("status") == "failed" for f in step_manifest_ctx.files ) - self.manifest_context.files[-1]["step"] = step_name + if not has_failed: + self.manifest_context.record_file( + url="(no file-level detail — step failed before producing one)", + status="failed", + error_message=str(error), + ) + self.manifest_context.files[-1]["step"] = step_name def _run_with_retry(self, name: str, step: Any, step_config: Dict[str, Any]) -> StepResult: retry_config = step_config["retry"] diff --git a/tests/test_manifest.py b/tests/test_manifest.py index 573978c8..91b1cc75 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -316,4 +316,94 @@ def test_writer_no_operation_error_field_when_success(): assert "dbus:operationError" not in manifest finally: if os.path.exists(actual_path): - os.remove(actual_path) \ No newline at end of file + os.remove(actual_path) +def test_download_files_records_failure_and_not_attempted_on_timeout(monkeypatch): + """Regression test for #131: timeout mid-download must record failed + not_attempted.""" + import requests + from databusclient.api.download import _download_files + from databusclient.manifest.context import ManifestContext + from databusclient.manifest.writer import ManifestWriter + + urls = [ + "https://example.org/file1.nt.gz", + "https://example.org/file2.nt.gz", + "https://example.org/file3.nt.gz", + "https://example.org/file4.nt.gz", + ] + + def fake_download_file(url, manifest_context=None, **kwargs): + if url == urls[0]: + manifest_context.record_file(url=url, status="success", size_bytes=100) + elif url == urls[1]: + raise requests.exceptions.Timeout("Connection timed out") + + monkeypatch.setattr("databusclient.api.download._download_file", fake_download_file) + + ctx = ManifestContext(command="download") + with pytest.raises(requests.exceptions.Timeout): + _download_files(urls=urls, localDir="/tmp", manifest_context=ctx) + + manifest = ManifestWriter.build_manifest_dict(ctx) + result = manifest["dbus:executionResult"] + + assert result["dbus:totalFiles"] == 4 + assert result["dbus:succeeded"] == 1 + assert result["dbus:failed"] == 1 + assert result["dbus:notAttempted"] == 2 + assert result["dbus:status"] == "partial" + + statuses = {f["dcat:downloadURL"]: f["dbus:status"] for f in manifest["dataid:distribution"]["dataid:file"]} + assert statuses == { + urls[0]: "success", + urls[1]: "failed", + urls[2]: "not_attempted", + urls[3]: "not_attempted", + } + +def test_download_group_records_not_attempted_across_artifacts(monkeypatch): + """Multi-artifact group failure must count unattempted files from later artifacts.""" + import requests + from databusclient.api.download import _download_group + from databusclient.manifest.context import ManifestContext + from databusclient.manifest.writer import ManifestWriter + + monkeypatch.setattr( + "databusclient.api.download.fetch_databus_jsonld", + lambda uri, databus_key=None: uri, + ) + monkeypatch.setattr( + "databusclient.api.download._get_databus_artifacts_of_group", + lambda _: ["https://example.org/group/art1", "https://example.org/group/art2"], + ) + monkeypatch.setattr( + "databusclient.api.download._collect_artifact_files", + lambda uri, all_versions=False, databus_key=None: ( + [f"{uri}/file1.nt.gz", f"{uri}/file2.nt.gz"], + {}, + ), + ) + + def fake_download_file(url, manifest_context=None, **kwargs): + if url == "https://example.org/group/art1/file1.nt.gz": + manifest_context.record_file(url=url, status="success", size_bytes=50) + elif url == "https://example.org/group/art1/file2.nt.gz": + raise requests.exceptions.Timeout("Connection timed out") + + monkeypatch.setattr("databusclient.api.download._download_file", fake_download_file) + + ctx = ManifestContext(command="download") + with pytest.raises(requests.exceptions.Timeout): + _download_group( + uri="https://example.org/group", + localDir="/tmp", + manifest_context=ctx, + ) + + manifest = ManifestWriter.build_manifest_dict(ctx) + result = manifest["dbus:executionResult"] + + assert result["dbus:totalFiles"] == 4 + assert result["dbus:succeeded"] == 1 + assert result["dbus:failed"] == 1 + assert result["dbus:notAttempted"] == 2 + assert result["dbus:status"] == "partial" \ No newline at end of file diff --git a/tests/test_manifest_failures.py b/tests/test_manifest_failures.py new file mode 100644 index 00000000..004bcdda --- /dev/null +++ b/tests/test_manifest_failures.py @@ -0,0 +1,117 @@ +"""Regression tests for #131: manifest must reflect failed / not-attempted files.""" +import inspect + +import requests + +from databusclient.api.download import _download_files +from databusclient.manifest.context import ManifestContext +from databusclient.manifest.summary import format_summary +from databusclient.manifest.writer import ManifestWriter + +URLS = [f"https://example.org/file{i}.nt.gz" for i in range(1, 4)] + + +def _run(monkeypatch, behaviour): + def fake_download_file(url, manifest_context=None, **kwargs): + outcome = behaviour.get(url, "ok") + if outcome == "ok": + manifest_context.record_file(url=url, status="success", size_bytes=10) + elif outcome == "404": + manifest_context.record_file( + url=url, status="failed", error_message="404 Not Found" + ) + elif outcome == "timeout": + raise requests.exceptions.Timeout("timed out") + + monkeypatch.setattr("databusclient.api.download._download_file", fake_download_file) + ctx = ManifestContext(command="download") + try: + _download_files(urls=URLS, localDir="/tmp", manifest_context=ctx) + except requests.exceptions.Timeout: + pass + return ManifestWriter.build_manifest_dict(ctx)["dbus:executionResult"] + + +def test_all_success_is_completed(monkeypatch): + r = _run(monkeypatch, {}) + assert (r["dbus:totalFiles"], r["dbus:succeeded"]) == (3, 3) + assert r["dbus:failed"] == 0 and r["dbus:notAttempted"] == 0 + assert r["dbus:status"] == "completed" + + +def test_first_file_timeout_is_failed(monkeypatch): + r = _run(monkeypatch, {URLS[0]: "timeout"}) + assert r["dbus:totalFiles"] == 3 + assert r["dbus:succeeded"] == 0 + assert r["dbus:failed"] == 1 + assert r["dbus:notAttempted"] == 2 + assert r["dbus:status"] == "failed" + + +def test_last_file_timeout_is_partial(monkeypatch): + r = _run(monkeypatch, {URLS[2]: "timeout"}) + assert r["dbus:totalFiles"] == 3 + assert r["dbus:succeeded"] == 2 + assert r["dbus:failed"] == 1 + assert r["dbus:notAttempted"] == 0 + assert r["dbus:status"] == "partial" + + +def test_404_mid_run_continues_and_is_partial(monkeypatch): + r = _run(monkeypatch, {URLS[1]: "404"}) + assert r["dbus:totalFiles"] == 3 + assert r["dbus:succeeded"] == 2 + assert r["dbus:failed"] == 1 + assert r["dbus:notAttempted"] == 0 + assert r["dbus:status"] == "partial" + + +def test_format_summary_shows_not_attempted(): + manifest = { + "dbus:executionResult": { + "dbus:succeeded": 1, + "dbus:failed": 1, + "dbus:notAttempted": 2, + } + } + assert "2 not attempted" in format_summary(manifest) + + +def _engine_with_master(): + from databusclient.workflow import engine as eng + + cls = next( + c + for _, c in inspect.getmembers(eng, inspect.isclass) + if hasattr(c, "_finish_step_manifest") + ) + inst = object.__new__(cls) + inst.manifest_context = ManifestContext(command="workflow") + return inst + + +def test_engine_does_not_double_count_failed_step(): + engine = _engine_with_master() + step_ctx = ManifestContext(command="download") + step_ctx.record_file(url="u1", status="success", size_bytes=1) + step_ctx.record_file(url="u2", status="failed", error_message="timeout") + step_ctx.record_file_not_attempted("u3") + step_ctx.record_file_not_attempted("u4") + + engine._finish_step_manifest(step_ctx, "dl", error=Exception("timeout")) + + r = ManifestWriter.build_manifest_dict(engine.manifest_context)["dbus:executionResult"] + assert r["dbus:totalFiles"] == 4 + assert r["dbus:failed"] == 1 + assert r["dbus:notAttempted"] == 2 + + +def test_engine_adds_synthetic_entry_when_step_recorded_nothing(): + engine = _engine_with_master() + step_ctx = ManifestContext(command="download") + + engine._finish_step_manifest(step_ctx, "dl", error=Exception("auth failed")) + + r = ManifestWriter.build_manifest_dict(engine.manifest_context)["dbus:executionResult"] + assert r["dbus:totalFiles"] == 1 + assert r["dbus:failed"] == 1 From 9cc5ac3e0f4410c2e0f52617e5112967475fdbf4 Mon Sep 17 00:00:00 2001 From: charan Date: Sat, 5 Dec 2026 01:22:37 +0530 Subject: [PATCH 2/2] fix: address review feedback on summary status, metadata errors, and top-level URIs --- databusclient/api/download.py | 25 +++++++--- databusclient/manifest/summary.py | 9 +++- tests/test_manifest_failures.py | 82 +++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 9 deletions(-) diff --git a/databusclient/api/download.py b/databusclient/api/download.py index 2b834817..9e156909 100644 --- a/databusclient/api/download.py +++ b/databusclient/api/download.py @@ -1387,13 +1387,19 @@ def _download_group( all_urls: List[str] = [] all_checksums: dict = {} - for artifact_uri in artifacts: - print(f"Download artifact: {artifact_uri}") - urls, checksums = _collect_artifact_files( - artifact_uri, all_versions=all_versions, databus_key=databus_key - ) - all_urls.extend(urls) - all_checksums.update(checksums) + try: + for artifact_uri in artifacts: + print(f"Download artifact: {artifact_uri}") + urls, checksums = _collect_artifact_files( + artifact_uri, all_versions=all_versions, databus_key=databus_key + ) + all_urls.extend(urls) + all_checksums.update(checksums) + except Exception: + if manifest_context is not None: + for url in all_urls: + manifest_context.record_file_not_attempted(url) + raise _download_files( all_urls, @@ -1489,7 +1495,8 @@ def download( the versioned databus-python-client default. """ _validate_graph_mode(graph_mode) - for databusURI in databusURIs: + databusURIs = list(databusURIs) + for idx, databusURI in enumerate(databusURIs): host, account, group, artifact, version, file = get_databus_id_parts_from_file_url(databusURI) # Determine endpoint per-URI if not explicitly provided @@ -1552,6 +1559,8 @@ def download( except Exception as e: if manifest_context is not None: manifest_context.record_file_error(databusURI, e) + for remaining_uri in databusURIs[idx + 1:]: + manifest_context.record_file_not_attempted(remaining_uri) raise elif version is not None: diff --git a/databusclient/manifest/summary.py b/databusclient/manifest/summary.py index 60f48fa4..68197456 100644 --- a/databusclient/manifest/summary.py +++ b/databusclient/manifest/summary.py @@ -24,10 +24,17 @@ def _derive_status(manifest: Dict[str, Any]) -> str: operation itself did not raise. - "completed" otherwise. """ + result = manifest.get("dbus:executionResult", {}) + explicit_status = result.get("dbus:status") + if explicit_status in ("partial", "failed"): + return explicit_status + if manifest.get("dbus:operationError"): return "failed" - result = manifest.get("dbus:executionResult", {}) + if explicit_status: + return explicit_status + if result.get("dbus:failed", 0) > 0: return "completed with errors" diff --git a/tests/test_manifest_failures.py b/tests/test_manifest_failures.py index 004bcdda..2222413c 100644 --- a/tests/test_manifest_failures.py +++ b/tests/test_manifest_failures.py @@ -115,3 +115,85 @@ def test_engine_adds_synthetic_entry_when_step_recorded_nothing(): r = ManifestWriter.build_manifest_dict(engine.manifest_context)["dbus:executionResult"] assert r["dbus:totalFiles"] == 1 assert r["dbus:failed"] == 1 + + +def test_format_summary_uses_explicit_status(): + partial_manifest = { + "dbus:operationError": {"dbus:errorType": "Timeout", "dbus:errorMessage": "Read timed out"}, + "dbus:executionResult": { + "dbus:succeeded": 2, + "dbus:failed": 1, + "dbus:notAttempted": 1, + "dbus:status": "partial", + }, + } + assert "Status : partial" in format_summary(partial_manifest) + + failed_manifest = { + "dbus:executionResult": { + "dbus:succeeded": 0, + "dbus:failed": 1, + "dbus:notAttempted": 2, + "dbus:status": "failed", + }, + } + assert "Status : failed" in format_summary(failed_manifest) + + +def test_download_group_retains_collected_urls_on_metadata_error(monkeypatch): + from databusclient.api.download import _download_group + + monkeypatch.setattr( + "databusclient.api.download.fetch_databus_jsonld", + lambda uri, **kw: "{}", + ) + monkeypatch.setattr( + "databusclient.api.download._get_databus_artifacts_of_group", + lambda json_str: ["https://example.org/g/a1", "https://example.org/g/a2"], + ) + + def fake_collect(artifact_uri, **kw): + if artifact_uri.endswith("/a1"): + return (["https://example.org/f1.ttl", "https://example.org/f2.ttl"], {}) + raise requests.exceptions.Timeout("metadata timeout") + + monkeypatch.setattr("databusclient.api.download._collect_artifact_files", fake_collect) + + ctx = ManifestContext(command="download") + try: + _download_group("https://example.org/g", "/tmp", manifest_context=ctx) + except requests.exceptions.Timeout: + pass + + r = ManifestWriter.build_manifest_dict(ctx)["dbus:executionResult"] + assert r["dbus:totalFiles"] == 2 + assert r["dbus:notAttempted"] == 2 + + +def test_top_level_download_records_remaining_file_uris(monkeypatch): + from databusclient.api.download import download + + def fake_download_file(*args, **kw): + raise requests.exceptions.Timeout("timed out") + + monkeypatch.setattr("databusclient.api.download._download_file", fake_download_file) + + ctx = ManifestContext(command="download") + try: + download( + localDir="/tmp", + endpoint="https://example.org", + databusURIs=[ + "https://example.org/u/g/a/v/file1.ttl", + "https://example.org/u/g/a/v/file2.ttl", + "https://example.org/u/g/a/v/file3.ttl", + ], + manifest_context=ctx, + ) + except requests.exceptions.Timeout: + pass + + r = ManifestWriter.build_manifest_dict(ctx)["dbus:executionResult"] + assert r["dbus:totalFiles"] == 3 + assert r["dbus:failed"] == 1 + assert r["dbus:notAttempted"] == 2