Skip to content

Commit

Permalink
tests: introduce ETagNotInResponseHeaderWarning to reduce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 8, 2024
1 parent 4051358 commit 04dc7bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dclab/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
)


class ETagNotInResponseHeaderWarning(UserWarning):
"""Used for cases where the requests.Response does not contain an ETag"""


class HTTPFile(io.IOBase):
def __init__(self, url, chunk_size=2**18, keep_chunks=200):
"""Chunk-cached access to a URL supporting range requests
Expand Down Expand Up @@ -78,7 +82,8 @@ def _parse_header(self):
etag = resp.headers.get("etag", "").strip("'").strip('"')
if len(etag) < 5:
etag = None
warnings.warn(f"Got empty ETag header for {self.url}")
warnings.warn(f"Got empty ETag header for {self.url}",
ETagNotInResponseHeaderWarning)
self._etag = etag

@property
Expand Down
5 changes: 5 additions & 0 deletions tests/test_rtdc_fmt_http_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

import dclab
from dclab.http_utils import ETagNotInResponseHeaderWarning
from dclab import new_dataset, RTDCWriter
from dclab.rtdc_dataset.fmt_http import HTTPBasin, RTDC_HTTP
from dclab.rtdc_dataset.feat_basin import BasinNotAvailableError
Expand Down Expand Up @@ -271,8 +272,12 @@ def test_trace_availability_invalid(tmp_path):
# because `__contains__` returns True for "trace", but the trace data
# are nowhere to find.
with (pytest.warns(UserWarning, match="but I cannot get its data"),
pytest.warns(ETagNotInResponseHeaderWarning,
match="Got empty ETag header"),
pytest.raises(KeyError, match="trace")):
_ = ds["trace"]
with (pytest.warns(UserWarning, match="but I cannot get its data"),
pytest.warns(ETagNotInResponseHeaderWarning,
match="Got empty ETag header"),
pytest.raises(KeyError, match="trace")):
dclab.new_dataset(ds)

0 comments on commit 04dc7bf

Please sign in to comment.