From 0e883ff1794eb0cd6629cf4a3e12cc3d4d44f04b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 19 May 2023 09:35:02 +0200 Subject: [PATCH 1/3] pre-commit autoupdate 2023_05_19 --- .pre-commit-config.yaml | 4 ++-- pyproject.toml | 6 +----- tests/conftest.py | 15 ++------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b1f255f4..cfe8f628 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.261 + rev: v0.0.269 hooks: - id: ruff @@ -42,7 +42,7 @@ repos: - id: codespell # See setup.cfg for args - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.1.1 + rev: v1.3.0 hooks: - id: mypy additional_dependencies: diff --git a/pyproject.toml b/pyproject.toml index ef31cd55..2ed3e1d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,11 +80,7 @@ max-statements = 124 [tool.ruff.per-file-ignores] "__init__.py" = ["E402"] -"tests/*" = [ - "PT017", - "S101", -] -"tests/conftest.py" = ["B018", "F811"] +"tests/*" = ["PT017", "S101"] "tests/cli/test_ia_list.py" = ["E741"] "tests/test_api.py" = ["E712"] "tests/test_config.py" = ["PT011"] diff --git a/tests/conftest.py b/tests/conftest.py index 0b1392a7..1f0ef92c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,17 +12,6 @@ from internetarchive.cli import ia from internetarchive.utils import json -try: - FileNotFoundError -except NameError: - FileNotFoundError = IOError - -try: - WindowsError # type: ignore[used-before-def] -except NameError: - class WindowsError(Exception): - pass - PROTOCOL = 'https:' BASE_URL = 'https://archive.org/' METADATA_URL = f'{BASE_URL}metadata/' @@ -74,7 +63,7 @@ def load_test_data_file(filename): def call_cmd(cmd, expected_exit_code=0): - proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) # noqa: S602 stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8').strip() stderr = stderr.decode('utf-8').strip() @@ -134,5 +123,5 @@ def nasa_metadata(): # TODO: Why is this function defined twice in this file? See issue #505 @pytest.fixture() # type: ignore -def nasa_item(nasa_mocker): +def nasa_item(nasa_mocker): # noqa: F811 return get_item('nasa') From 5f876f1b37e689be5422883c05ed2cf95a34eaed Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 19 May 2023 09:41:19 +0200 Subject: [PATCH 2/3] Upgrade ruff in tests/requirements.txt and setup.cfg --- setup.cfg | 2 +- tests/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 1b6af950..bec6295d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,7 +59,7 @@ docs = test = pytest==7.1.2 responses==0.20.0 - ruff==0.0.261 + ruff==0.0.269 types = tqdm-stubs>=0.2.0 types-colorama diff --git a/tests/requirements.txt b/tests/requirements.txt index 7b3df803..0cf7ee05 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,3 +1,3 @@ pytest==7.2.2 responses==0.23.1 -ruff==0.0.261 +ruff==0.0.269 From 7eee5a96b794562277ab9c1c2ce91e37469aed0b Mon Sep 17 00:00:00 2001 From: DuncanDHall Date: Wed, 23 Aug 2023 12:53:27 -0400 Subject: [PATCH 3/3] Patch search error Currently key error is thrown when elastic search returns no 'response' key in its json when we try to grab the num_found. --- internetarchive/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internetarchive/search.py b/internetarchive/search.py index 34791467..0205d691 100644 --- a/internetarchive/search.py +++ b/internetarchive/search.py @@ -130,7 +130,7 @@ def _advanced_search(self): auth=self.auth, **self.request_kwargs) j = r.json() - num_found = int(j['response']['numFound']) + num_found = int(j.get('response', {}).get('numFound', 0)) if not self._num_found: self._num_found = num_found if j.get('error'):