Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: enable additional ruff rules #125

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/oaipmh_scythe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
18 changes: 9 additions & 9 deletions tests/integration/test_harvesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@


@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)
assert identify.repositoryName == "Zenodo"


@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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -55,22 +55,22 @@ 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)
assert record.metadata["title"][0] == "INFORMATION YOU KNOW AND DON'T KNOW ABOUT THE UNIVERSE"


@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)
Expand All @@ -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)
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) == "<OAIResponseIterator ListIdentifiers>"


@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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_resumption_token_repr() -> None:
assert repr(token) == "<ResumptionToken some-token>"


@pytest.fixture
@pytest.fixture()
def identify_response(mocker):
xml = """
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/">
Expand All @@ -32,7 +32,7 @@ def identify_response(mocker):
return mock_response


@pytest.fixture
@pytest.fixture()
def identify(identify_response) -> Identify:
return Identify(identify_response)

Expand Down Expand Up @@ -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)

Expand All @@ -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 = """
<record xmlns="http://www.openarchives.org/OAI/2.0/">
Expand All @@ -143,7 +143,7 @@ def record_element():
return etree.fromstring(xml.encode())


@pytest.fixture
@pytest.fixture()
def deleted_record_lement():
xml = """
<record xmlns="http://www.openarchives.org/OAI/2.0/">
Expand All @@ -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)

Expand Down Expand Up @@ -201,7 +201,7 @@ def test_deleted_record_no_metadata(deleted_record):
_ = record.metadata


@pytest.fixture
@pytest.fixture()
def set_element():
xml = """
<set>
Expand All @@ -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)

Expand All @@ -233,7 +233,7 @@ def test_set_iter(oai_set):
assert set_items["setSpec"] == ["user-emi"]


@pytest.fixture
@pytest.fixture()
def mdf_element():
xml = """
<metadataFormat>
Expand All @@ -245,7 +245,7 @@ def mdf_element():
return etree.fromstring(xml.encode())


@pytest.fixture
@pytest.fixture()
def mdf(mdf_element):
return MetadataFormat(mdf_element)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""


@pytest.fixture
@pytest.fixture()
def mock_response(mocker: MockerFixture):
response = mocker.Mock()
response.text = IDENTIFY_XML
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"><request verb="Identify">https://zenodo.org/oai2d</request></OAI-PMH>'
return etree.fromstring(xml)


@pytest.fixture
@pytest.fixture()
def xml_element_without_namespace() -> etree._Element:
xml = '<OAI-PMH><request verb="Identify">https://zenodo.org/oai2d</request></OAI-PMH>'
return etree.fromstring(xml)
Expand Down