Skip to content

implemented Sam's comments #1057

implemented Sam's comments

implemented Sam's comments #1057

GitHub Actions / Petals / Unit Test Results (3.9) failed Nov 6, 2024 in 0s

1 fail, 2 skipped, 200 pass in 4m 38s

203 tests   200 ✅  4m 38s ⏱️
  1 suites    2 💤
  1 files      1 ❌

Results for commit 4fe4c88.

Annotations

Check warning on line 0 in climada_petals.hazard.test.test_drought.TestReader

See this annotation in the file changed.

@github-actions github-actions / Petals / Unit Test Results (3.9)

test (climada_petals.hazard.test.test_drought.TestReader) failed

climada_petals/tests_xml/tests.xml [took 39s]
Raw output
requests.exceptions.ChunkedEncodingError: Importing the SPEI data file failed: ('Connection broken: IncompleteRead(220249666 bytes read, 139215463 more expected)', IncompleteRead(220249666 bytes read, 139215463 more expected))
self = <urllib3.response.HTTPResponse object at 0x7fa30d339d90>

    @contextmanager
    def _error_catcher(self) -> typing.Generator[None, None, None]:
        """
        Catch low-level python exceptions, instead re-raising urllib3
        variants, so that low-level exceptions are not leaked in the
        high-level api.
    
        On exit, release the connection back to the pool.
        """
        clean_exit = False
    
        try:
            try:
>               yield

../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/response.py:748: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <urllib3.response.HTTPResponse object at 0x7fa30d339d90>, amt = 1024

    def _raw_read(
        self,
        amt: int | None = None,
        *,
        read1: bool = False,
    ) -> bytes:
        """
        Reads `amt` of bytes from the socket.
        """
        if self._fp is None:
            return None  # type: ignore[return-value]
    
        fp_closed = getattr(self._fp, "closed", False)
    
        with self._error_catcher():
            data = self._fp_read(amt, read1=read1) if not fp_closed else b""
            if amt is not None and amt != 0 and not data:
                # Platform-specific: Buggy versions of Python.
                # Close the connection when no data is returned
                #
                # This is redundant to what httplib/http.client _should_
                # already do.  However, versions of python released before
                # December 15, 2012 (http://bugs.python.org/issue16298) do
                # not properly close the connection in all cases. There is
                # no harm in redundantly calling close.
                self._fp.close()
                if (
                    self.enforce_content_length
                    and self.length_remaining is not None
                    and self.length_remaining != 0
                ):
                    # This is an edge case that httplib failed to cover due
                    # to concerns of backward compatibility. We're
                    # addressing it here to make sure IncompleteRead is
                    # raised during streaming, so all calls with incorrect
                    # Content-Length are caught.
>                   raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
E                   urllib3.exceptions.IncompleteRead: IncompleteRead(220249666 bytes read, 139215463 more expected)

../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/response.py:894: IncompleteRead

The above exception was the direct cause of the following exception:

    def generate():
        # Special case for urllib3.
        if hasattr(self.raw, "stream"):
            try:
>               yield from self.raw.stream(chunk_size, decode_content=True)

../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/models.py:820: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/response.py:1060: in stream
    data = self.read(amt=amt, decode_content=decode_content)
../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/response.py:977: in read
    data = self._raw_read(amt)
../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/response.py:902: in _raw_read
    self._fp.close()
../../../../micromamba/envs/climada_env_3.9/lib/python3.9/contextlib.py:137: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <urllib3.response.HTTPResponse object at 0x7fa30d339d90>

    @contextmanager
    def _error_catcher(self) -> typing.Generator[None, None, None]:
        """
        Catch low-level python exceptions, instead re-raising urllib3
        variants, so that low-level exceptions are not leaked in the
        high-level api.
    
        On exit, release the connection back to the pool.
        """
        clean_exit = False
    
        try:
            try:
                yield
    
            except SocketTimeout as e:
                # FIXME: Ideally we'd like to include the url in the ReadTimeoutError but
                # there is yet no clean way to get at it from this context.
                raise ReadTimeoutError(self._pool, None, "Read timed out.") from e  # type: ignore[arg-type]
    
            except BaseSSLError as e:
                # FIXME: Is there a better way to differentiate between SSLErrors?
                if "read operation timed out" not in str(e):
                    # SSL errors related to framing/MAC get wrapped and reraised here
                    raise SSLError(e) from e
    
                raise ReadTimeoutError(self._pool, None, "Read timed out.") from e  # type: ignore[arg-type]
    
            except IncompleteRead as e:
                if (
                    e.expected is not None
                    and e.partial is not None
                    and e.expected == -e.partial
                ):
                    arg = "Response may not contain content."
                else:
                    arg = f"Connection broken: {e!r}"
>               raise ProtocolError(arg, e) from e
E               urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(220249666 bytes read, 139215463 more expected)', IncompleteRead(220249666 bytes read, 139215463 more expected))

../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/response.py:772: ProtocolError

During handling of the above exception, another exception occurred:

self = <climada_petals.hazard.drought.Drought object at 0x7fa310129670>

    def setup(self):
        """Set up the hazard drought"""
        try:
    
            if not self.file_path.is_file():
>               download_file(SPEI_FILE_URL, download_dir=SPEI_FILE_DIR)

climada_petals/hazard/drought.py:134: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/climada/util/files_handler.py:108: in download_file
    for data in tqdm(
../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/tqdm/std.py:1181: in __iter__
    for obj in iterable:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def generate():
        # Special case for urllib3.
        if hasattr(self.raw, "stream"):
            try:
                yield from self.raw.stream(chunk_size, decode_content=True)
            except ProtocolError as e:
>               raise ChunkedEncodingError(e)
E               requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(220249666 bytes read, 139215463 more expected)', IncompleteRead(220249666 bytes read, 139215463 more expected))

../../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/models.py:822: ChunkedEncodingError

The above exception was the direct cause of the following exception:

self = <climada_petals.hazard.test.test_drought.TestReader testMethod=test>

    def test(self):
    
        drought = Drought()
        drought.set_area(44.5, 5, 50, 12)
    
>       hazard_set = drought.setup()

climada_petals/hazard/test/test_drought.py:34: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <climada_petals.hazard.drought.Drought object at 0x7fa310129670>

    def setup(self):
        """Set up the hazard drought"""
        try:
    
            if not self.file_path.is_file():
                download_file(SPEI_FILE_URL, download_dir=SPEI_FILE_DIR)
    
            LOGGER.debug('Importing %s', str(SPEI_FILE_NAME))
            dataset = xr.open_dataset(self.file_path)
    
        except Exception as err:
>           raise type(err)('Importing the SPEI data file failed: ' + str(err)) from err
E           requests.exceptions.ChunkedEncodingError: Importing the SPEI data file failed: ('Connection broken: IncompleteRead(220249666 bytes read, 139215463 more expected)', IncompleteRead(220249666 bytes read, 139215463 more expected))

climada_petals/hazard/drought.py:140: ChunkedEncodingError