Skip to content

implementing comments by Sarah Huelsen #915

implementing comments by Sarah Huelsen

implementing comments by Sarah Huelsen #915

GitHub Actions / Petals / Unit Test Results (3.11) failed Aug 22, 2024 in 0s

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

203 tests  +11   200 ✅ +10   11m 38s ⏱️ + 7m 8s
  1 suites ± 0     2 💤 ± 0 
  1 files   ± 0     1 ❌ + 1 

Results for commit 0274acd. ± Comparison against earlier commit 9939d63.

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.11)

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

climada_petals/tests_xml/tests.xml [took 7m 33s]
Raw output
ValueError: Importing the SPEI data file failed: Error loading page https://digital.csic.es/bitstream/10261/153475/8/spei06.nc
 Status: 502
 Content: b'<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor="white">\r\n<center><h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx/1.14.1</center>\r\n</body>\r\n</html>\r\n'
self = <climada_petals.hazard.drought.Drought object at 0x7fc70da071d0>

    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: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

url = 'https://digital.csic.es/bitstream/10261/153475/8/spei06.nc'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True

    def download_file(url, download_dir=None, overwrite=True):
        """Download file from url to given target folder and provide full path of the downloaded file.
    
        Parameters
        ----------
        url : str
            url containing data to download
        download_dir : Path or str, optional
            the parent directory of the eventually downloaded file
            default: local_data.save_dir as defined in climada.conf
        overwrite : bool, optional
            whether or not an already existing file at the target location should be overwritten,
            by default True
    
        Returns
        -------
        str
            the full path to the eventually downloaded file
        """
        file_name = url.split('/')[-1]
        if file_name.strip() == '':
            raise ValueError(f"cannot download {url} as a file")
        download_path = CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
        file_path = download_path.absolute().joinpath(file_name)
        if file_path.exists():
            if not file_path.is_file() or not overwrite:
                raise FileExistsError(f"cannot download to {file_path}")
    
        try:
            req_file = requests.get(url, stream=True)
        except IOError as ioe:
            raise type(ioe)('Check URL and internet connection: ' + str(ioe)) from ioe
        if req_file.status_code < 200 or req_file.status_code > 299:
>           raise ValueError(f'Error loading page {url}\n'
                             f' Status: {req_file.status_code}\n'
                             f' Content: {req_file.content}')
E           ValueError: Error loading page https://digital.csic.es/bitstream/10261/153475/8/spei06.nc
E            Status: 502
E            Content: b'<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor="white">\r\n<center><h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx/1.14.1</center>\r\n</body>\r\n</html>\r\n'

../../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/climada/util/files_handler.py:94: ValueError

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 0x7fc70da071d0>

    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           ValueError: Importing the SPEI data file failed: Error loading page https://digital.csic.es/bitstream/10261/153475/8/spei06.nc
E            Status: 502
E            Content: b'<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor="white">\r\n<center><h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx/1.14.1</center>\r\n</body>\r\n</html>\r\n'

climada_petals/hazard/drought.py:140: ValueError