Skip to content

Commit

Permalink
Direct all print messages to stderr
Browse files Browse the repository at this point in the history
Stream all print messages to stderr so they can be controlled together.
  • Loading branch information
Dhwaniartefact committed Sep 13, 2024
1 parent 1348b1e commit 63bc51d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion fixity/fixity.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def scanall(
except Exception as e:
utils.pyprint(
f"Internal error encountered while scanning AIP {aip['uuid']} ({type(e).__name__})",
file=sys.stdout,
timestamps=timestamps,
)
if throttle_time:
Expand Down
2 changes: 1 addition & 1 deletion fixity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def format_timestamp(t):
def pyprint(message, **kwargs):
if kwargs.get("timestamps"):
message = f"[{format_timestamp(utcnow())}] {message}"
print(message, file=kwargs.get("file", sys.stderr))
print(message, file=sys.stderr)
13 changes: 5 additions & 8 deletions tests/test_fixity.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,10 @@ def test_scanall_handles_exceptions(_get, capsys):
assert response is False

captured = capsys.readouterr()
assert (
captured.out.strip()
== "Internal error encountered while scanning AIP 77adb748-8d9c-47ec-b593-53465749ce0e (StorageServiceError)"
)

assert captured.err.strip() == "\n".join(
[
"Internal error encountered while scanning AIP 77adb748-8d9c-47ec-b593-53465749ce0e (StorageServiceError)",
f'Storage service at "{STORAGE_SERVICE_URL}" failed authentication while scanning AIP 32f62f8b-ecfd-419e-a3e9-911ec23d0573',
"Successfully scanned 2 AIPs",
]
Expand Down Expand Up @@ -509,12 +506,12 @@ def test_main_handles_exceptions_if_scanall_fails(_get, monkeypatch, capsys):
assert result == 1

captured = capsys.readouterr()
assert (
captured.out.strip()
== f"Internal error encountered while scanning AIP {aip_id} (StorageServiceError)"
)

assert captured.out.strip() == ""

assert captured.err.strip() == "\n".join(
[
f"Internal error encountered while scanning AIP {aip_id} (StorageServiceError)",
f'Storage service at "{STORAGE_SERVICE_URL}" failed authentication while scanning AIP 32f62f8b-ecfd-419e-a3e9-911ec23d0573',
"Successfully scanned 2 AIPs",
]
Expand Down

0 comments on commit 63bc51d

Please sign in to comment.