Skip to content

Commit

Permalink
update url_is_reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
wenh06 committed May 9, 2024
1 parent 98665fa commit 93d732f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
du -sh ~/tmp/*
- name: Run test with pytest and collect coverage
run: |
pytest -v -s \
pytest -vv -s \
--cov=torch_ecg \
--ignore=test/test_pipelines \
test
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/test-databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ jobs:
du -sh ~/tmp/nsrr-data/*
- name: Run test SHHS with pytest
run: |
pytest -v -s test/test_databases/test_shhs.py
pytest -vv -s test/test_databases/test_shhs.py
- name: Run test other databases with pytest
run: |
pytest -v -s test/test_databases/test_cachet_cadb.py
pytest -v -s test/test_databases/test_sph.py
pytest -vv -s test/test_databases/test_cachet_cadb.py
pytest -vv -s test/test_databases/test_sph.py
- name: Run test normal physionet databases with pytest
run: |
pytest -v -s test/test_databases/test_base.py
pytest -v -s test/test_databases/test_afdb.py
pytest -v -s test/test_databases/test_apnea_ecg.py
pytest -v -s test/test_databases/test_cinc2017.py
pytest -v -s test/test_databases/test_cinc2018.py
pytest -v -s test/test_databases/test_ltafdb.py
pytest -v -s test/test_databases/test_ludb.py
pytest -v -s test/test_databases/test_mitdb.py
pytest -v -s test/test_databases/test_qtdb.py
pytest -vv -s test/test_databases/test_base.py
pytest -vv -s test/test_databases/test_afdb.py
pytest -vv -s test/test_databases/test_apnea_ecg.py
pytest -vv -s test/test_databases/test_cinc2017.py
pytest -vv -s test/test_databases/test_cinc2018.py
pytest -vv -s test/test_databases/test_ltafdb.py
pytest -vv -s test/test_databases/test_ludb.py
pytest -vv -s test/test_databases/test_mitdb.py
pytest -vv -s test/test_databases/test_qtdb.py
- name: Run test CPSC databases with pytest
run: |
pytest -v -s test/test_databases/test_cpsc2018.py
pytest -v -s test/test_databases/test_cpsc2019.py
pytest -v -s test/test_databases/test_cpsc2020.py
pytest -v -s test/test_databases/test_cpsc2021.py
pytest -vv -s test/test_databases/test_cpsc2018.py
pytest -vv -s test/test_databases/test_cpsc2019.py
pytest -vv -s test/test_databases/test_cpsc2020.py
pytest -vv -s test/test_databases/test_cpsc2021.py
- name: Run test CinC20/21 databases with pytest
run: |
pytest -v -s test/test_databases/test_cinc2020.py
pytest -v -s test/test_databases/test_cinc2021.py
pytest -vv -s test/test_databases/test_cinc2020.py
pytest -vv -s test/test_databases/test_cinc2021.py
2 changes: 1 addition & 1 deletion .github/workflows/test-models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
python -m pip list
- name: Run test with pytest
run: |
pytest -v -s test/test_models
pytest -vv -s test/test_models
2 changes: 1 addition & 1 deletion .github/workflows/test-ppl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
python -m pip list
- name: Run test with pytest
run: |
pytest -v -s test/test_pipelines
pytest -vv -s test/test_pipelines
9 changes: 9 additions & 0 deletions torch_ecg/databases/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@
class _DataBase(ReprMixin, ABC):
"""Universal abstract base class for all databases.
Abstract methods that should be implemented by the subclass:
- `_ls_rec`: Find all records in the database.
- `load_data`: Load data from a record.
- `load_ann`: Load annotations of a record.
Abstract properties that should be implemented by the subclass:
- `database_info`: The :class:`DataBaseInfo` object of the database.
- `url`: URL(s) for downloading the database.
Parameters
----------
db_dir : `path-like`, optional
Expand Down
1 change: 0 additions & 1 deletion torch_ecg/databases/nsrr_databases/shhs.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ class SHHS(NSRRDataBase, PSGDataBaseMixin):
----------
db_dir : `path-like`, optional
Storage path of the database.
If not specified, data will be fetched from Physionet.
working_dir : `path-like`, optional
Working directory, to store intermediate files and log files.
verbose : int, default 1
Expand Down
9 changes: 6 additions & 3 deletions torch_ecg/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import warnings
import zipfile
from pathlib import Path
from typing import Iterable, Optional, Union
from typing import Any, Iterable, Optional, Union

import requests
from tqdm.auto import tqdm
Expand Down Expand Up @@ -323,13 +323,15 @@ def _safe_tar_extract(
tar.extractall(dst_dir, members, numeric_owner=numeric_owner)


def url_is_reachable(url: str) -> bool:
def url_is_reachable(url: str, **kwargs: Any) -> bool:
"""Check if a URL is reachable.
Parameters
----------
url : str
The URL.
**kwargs : dict, optional
Additional keyword arguments to pass to :meth:`requests.head`.
Returns
-------
Expand All @@ -338,7 +340,8 @@ def url_is_reachable(url: str) -> bool:
"""
try:
r = requests.head(url, timeout=3)
timeout = kwargs.pop("timeout", 3)
r = requests.head(url, timeout=timeout, **kwargs)
# successful responses and redirection messages
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#information_responses
# Informational responses (100 – 199)
Expand Down

0 comments on commit 93d732f

Please sign in to comment.