diff --git a/pyproject.toml b/pyproject.toml index 483574b..82d2f16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -132,8 +132,12 @@ select = [ "E", # pycodestyle "F", # pyflakes "I", # isort + "PERF", # #perflint-perf "PGH", # pygrep-hooks + "PT", # flake8-pytest-style-pt "RUF", # ruff + "TCH", # flake8-type-checking-tch + "T20", # flake8-print-t20 "UP", # pyupgrade "W", # pycodestyle "YTT", # flake8-2020 diff --git a/src/oaipmh_scythe/models.py b/src/oaipmh_scythe/models.py index a102199..2f37071 100644 --- a/src/oaipmh_scythe/models.py +++ b/src/oaipmh_scythe/models.py @@ -26,12 +26,13 @@ from lxml import etree -from oaipmh_scythe.response import OAIResponse from oaipmh_scythe.utils import get_namespace, xml_to_dict if TYPE_CHECKING: from collections.abc import Iterator + from oaipmh_scythe.response import OAIResponse + @dataclass class ResumptionToken: diff --git a/tests/conftest.py b/tests/conftest.py index c365a19..30c7b16 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,6 @@ def vcr_config() -> dict[str, str]: return {"cassette_library_dir": "tests/cassettes"} -@pytest.fixture +@pytest.fixture() def scythe() -> Scythe: return Scythe("https://zenodo.org/oai2d") diff --git a/tests/integration/test_harvesting.py b/tests/integration/test_harvesting.py index b636ba1..d915947 100644 --- a/tests/integration/test_harvesting.py +++ b/tests/integration/test_harvesting.py @@ -17,7 +17,7 @@ @pytest.mark.default_cassette("identify.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_identify(scythe: Scythe) -> None: identify = scythe.identify() assert isinstance(identify, Identify) @@ -25,7 +25,7 @@ def test_identify(scythe: Scythe) -> None: @pytest.mark.default_cassette("list_identifiers.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_list_identifiers(scythe: Scythe) -> None: identifiers = scythe.list_identifiers(metadataPrefix="oai_dc") assert isinstance(identifiers, Iterator) @@ -35,7 +35,7 @@ def test_list_identifiers(scythe: Scythe) -> None: @pytest.mark.default_cassette("list_identifiers.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_list_identifiers_ignore_deleted(scythe: Scythe) -> None: identifiers = scythe.list_identifiers(metadataPrefix="oai_dc", ignore_deleted=True) identifiers = list(identifiers) @@ -45,7 +45,7 @@ def test_list_identifiers_ignore_deleted(scythe: Scythe) -> None: @pytest.mark.default_cassette("list_records.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_list_records(scythe: Scythe) -> None: records = scythe.list_records(metadataPrefix="oai_dc") assert isinstance(records, Iterator) @@ -55,7 +55,7 @@ def test_list_records(scythe: Scythe) -> None: @pytest.mark.default_cassette("get_record.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_get_record(scythe: Scythe) -> None: record = scythe.get_record(identifier="oai:zenodo.org:6538892", metadataPrefix="oai_dc") assert isinstance(record, Record) @@ -63,14 +63,14 @@ def test_get_record(scythe: Scythe) -> None: @pytest.mark.default_cassette("id_does_not_exist.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_get_record_invalid_id(scythe: Scythe) -> None: with pytest.raises(HTTPStatusError): scythe.get_record(identifier="oai:zenodo.org:XXX", metadataPrefix="oai_dc") @pytest.mark.default_cassette("list_sets.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_list_sets(scythe: Scythe) -> None: sets = scythe.list_sets() assert isinstance(sets, Iterator) @@ -80,7 +80,7 @@ def test_list_sets(scythe: Scythe) -> None: @pytest.mark.default_cassette("list_metadata_formats.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_list_metadata_formats(scythe: Scythe) -> None: metadata_formats = scythe.list_metadata_formats() assert isinstance(metadata_formats, Iterator) @@ -90,7 +90,7 @@ def test_list_metadata_formats(scythe: Scythe) -> None: @pytest.mark.default_cassette("list_identifiers.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_list_identifiers_oai_response(scythe: Scythe) -> None: scythe.iterator = OAIResponseIterator responses = scythe.list_identifiers(metadataPrefix="oai_dc") diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 431e59d..aef4289 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -21,12 +21,12 @@ def test_invalid_http_method() -> None: - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Invalid HTTP method"): Scythe("https://localhost", http_method="DELETE") def test_wrong_protocol_version() -> None: - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Invalid protocol version"): Scythe("https://localhost", protocol_version="3.0") diff --git a/tests/unit/test_iterator.py b/tests/unit/test_iterator.py index bfa109a..c9e4bfd 100644 --- a/tests/unit/test_iterator.py +++ b/tests/unit/test_iterator.py @@ -14,14 +14,14 @@ @pytest.mark.default_cassette("list_identifiers.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_iterator_str(scythe: Scythe) -> None: iterator = OAIResponseIterator(scythe, params) assert str(iterator) == "" @pytest.mark.default_cassette("list_identifiers.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_oai_response_iterator(scythe: Scythe) -> None: iterator = OAIResponseIterator(scythe, params) responses = list(iterator) @@ -31,7 +31,7 @@ def test_oai_response_iterator(scythe: Scythe) -> None: @pytest.mark.default_cassette("list_identifiers.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_oai_item_iterator(scythe: Scythe) -> None: iterator = OAIItemIterator(scythe, params) identifiers = list(iterator) @@ -41,7 +41,7 @@ def test_oai_item_iterator(scythe: Scythe) -> None: @pytest.mark.default_cassette("list_identifiers.yaml") -@pytest.mark.vcr +@pytest.mark.vcr() def test_oai_item_iterator_ignore_deleted(scythe: Scythe) -> None: iterator = OAIItemIterator(scythe, params, ignore_deleted=True) identifiers = list(iterator) diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index b780fbb..2006ba6 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -14,7 +14,7 @@ def test_resumption_token_repr() -> None: assert repr(token) == "" -@pytest.fixture +@pytest.fixture() def identify_response(mocker): xml = """ @@ -32,7 +32,7 @@ def identify_response(mocker): return mock_response -@pytest.fixture +@pytest.fixture() def identify(identify_response) -> Identify: return Identify(identify_response) @@ -91,12 +91,12 @@ def deleted_header_element(): return etree.fromstring(xml.encode()) -@pytest.fixture +@pytest.fixture() def header(header_element): return Header(header_element) -@pytest.fixture +@pytest.fixture() def deleted_header(deleted_header_element): return Header(deleted_header_element) @@ -123,7 +123,7 @@ def test_header_iter(header): assert items == {"identifier": "oai:zenodo.org:6538892", "datestamp": "2022-05-11T13:49:36Z", "setSpecs": []} -@pytest.fixture +@pytest.fixture() def record_element(): xml = """ @@ -143,7 +143,7 @@ def record_element(): return etree.fromstring(xml.encode()) -@pytest.fixture +@pytest.fixture() def deleted_record_lement(): xml = """ @@ -163,12 +163,12 @@ def deleted_record_lement(): return etree.fromstring(xml.encode()) -@pytest.fixture +@pytest.fixture() def record(record_element): return Record(record_element) -@pytest.fixture +@pytest.fixture() def deleted_record(deleted_record_lement): return Record(deleted_record_lement) @@ -201,7 +201,7 @@ def test_deleted_record_no_metadata(deleted_record): _ = record.metadata -@pytest.fixture +@pytest.fixture() def set_element(): xml = """ @@ -213,7 +213,7 @@ def set_element(): return etree.fromstring(xml.encode()) -@pytest.fixture +@pytest.fixture() def oai_set(set_element): return Set(set_element) @@ -233,7 +233,7 @@ def test_set_iter(oai_set): assert set_items["setSpec"] == ["user-emi"] -@pytest.fixture +@pytest.fixture() def mdf_element(): xml = """ @@ -245,7 +245,7 @@ def mdf_element(): return etree.fromstring(xml.encode()) -@pytest.fixture +@pytest.fixture() def mdf(mdf_element): return MetadataFormat(mdf_element) diff --git a/tests/unit/test_response.py b/tests/unit/test_response.py index a1b807e..c6745c1 100644 --- a/tests/unit/test_response.py +++ b/tests/unit/test_response.py @@ -29,7 +29,7 @@ """ -@pytest.fixture +@pytest.fixture() def mock_response(mocker: MockerFixture): response = mocker.Mock() response.text = IDENTIFY_XML diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 791ca47..65f82c6 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -9,13 +9,13 @@ from oaipmh_scythe.utils import get_namespace, xml_to_dict -@pytest.fixture +@pytest.fixture() def xml_element_with_namespace() -> etree._Element: xml = 'https://zenodo.org/oai2d' return etree.fromstring(xml) -@pytest.fixture +@pytest.fixture() def xml_element_without_namespace() -> etree._Element: xml = 'https://zenodo.org/oai2d' return etree.fromstring(xml)