Skip to content

Commit bc2d02c

Browse files
authored
tests: Add data with multiple dois for tests and update pyproject.toml (#16)
1 parent 192dff0 commit bc2d02c

19 files changed

+2026
-1572
lines changed

.github/workflows/main.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
tests:
3030
needs: check-branch
3131
strategy:
32+
fail-fast: false
3233
matrix:
3334
python_version:
34-
- "3.8.1"
3535
- "3.9"
3636
- "3.10"
3737
- "3.11"
@@ -63,6 +63,7 @@ jobs:
6363
activate-environment: pymedx
6464
auto-update-conda: true
6565
conda-solver: libmamba
66+
python-version: "${{ matrix.python_version }}"
6667

6768
- name: Install dependencies
6869
run: |
@@ -97,6 +98,7 @@ jobs:
9798
activate-environment: pymedx
9899
auto-update-conda: true
99100
conda-solver: libmamba
101+
python-version: "3.12"
100102

101103
- name: Install dependencies
102104
run: |

.github/workflows/release.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
activate-environment: pymedx
3434
auto-update-conda: true
3535
conda-solver: libmamba
36+
python-version: "3.12"
3637

3738
- name: Install deps
3839
run: poetry install

conda/dev.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ channels:
33
- nodefaults
44
- conda-forge
55
dependencies:
6-
- python >=3.8.1,<4
6+
- compilers
7+
- python
78
- pip
8-
- poetry
9+
- poetry >=2
910
- nodejs # used by semantic-release
1011
- shellcheck
1112
- pip:
1213
- paginate
14+
- levenshtein==0.25.1 # pep517

poetry.lock

+1,951-1,537
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
1-
[tool.poetry]
1+
[project]
22
name = "pymedx"
33
version = "0.5.0" # semantic-release
44
description = "PyMedX is a tool set for handling multimedia files."
55
readme = "docs/index.md"
6-
authors = ["Gijs Wobben <[email protected]>", "Ivan Ogasawara <[email protected]>"]
6+
authors = [
7+
{ name = "Gijs Wobben", email = "[email protected]" },
8+
{ name = "Ivan Ogasawara", email = "[email protected]" },
9+
{ name = "Ever Vino", email = "[email protected]" },
10+
]
711
packages = [
8-
{include = "pymedx", from="src"},
12+
{include = "pymedx", from = "src"},
913
]
1014
license = "MIT"
1115
exclude = [
1216
".git/*",
1317
".env*",
1418
]
19+
requires-python = ">3.9,<4"
20+
dependencies = [
21+
"requests (>=2.20.0)",
22+
"lxml (>=5.1.0)",
23+
]
1524

16-
17-
[tool.poetry.dependencies]
18-
python = ">3.8.1,<4"
19-
requests = ">=2.20.0"
20-
lxml = "^5.1.0"
25+
[build-system]
26+
requires = ["poetry-core>=2", "poetry>=2"]
27+
build-backend = "poetry.core.masonry.api"
2128

2229
[tool.poetry.group.dev.dependencies]
30+
python = ">3.9,<4"
31+
python-dotenv = ">=1.0"
2332
pytest = ">=7.3.2"
2433
pytest-cov = ">=4.1.0"
2534
coverage = ">=7.2.7"
2635
pre-commit = ">=3.3.2"
27-
ruff = ">=0.1.5"
36+
ruff = ">=0.9.5"
2837
mypy = ">=1.6.0"
2938
bandit = ">=1.7.5"
3039
vulture = ">=2.9.1"

src/pymedx/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mypy: disable-error-code="attr-defined"
22
"""PyMedX package."""
3+
34
from importlib import metadata as importlib_metadata
45

56
from .api import PubMed, PubMedCentral

src/pymedx/api.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""API module for PubMed."""
2+
23
from __future__ import annotations
34

45
import datetime

src/pymedx/article.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Module for handling articles."""
2+
23
import datetime
34
import json
45

@@ -13,18 +14,18 @@ class PubMedArticle:
1314
"""Data class that contains a PubMed article."""
1415

1516
__slots__ = (
16-
"pubmed_id",
17-
"title",
1817
"abstract",
19-
"keywords",
20-
"journal",
21-
"publication_date",
2218
"authors",
23-
"methods",
2419
"conclusions",
25-
"results",
2620
"copyrights",
2721
"doi",
22+
"journal",
23+
"keywords",
24+
"methods",
25+
"publication_date",
26+
"pubmed_id",
27+
"results",
28+
"title",
2829
"xml",
2930
)
3031

@@ -197,12 +198,12 @@ class PubMedCentralArticle:
197198

198199
# slots which have been implemented
199200
__slots__ = (
200-
"pmc_id",
201-
"title",
202201
"abstract",
203-
"publication_date",
204202
"authors",
205203
"doi",
204+
"pmc_id",
205+
"publication_date",
206+
"title",
206207
)
207208

208209
def __init__(

src/pymedx/book.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Module for functions about book article."""
2+
23
import datetime
34
import json
45

@@ -13,19 +14,19 @@ class PubMedBookArticle:
1314
"""Data class that contains a PubMed article."""
1415

1516
__slots__ = (
16-
"pubmed_id",
17-
"title",
1817
"abstract",
19-
"publication_date",
2018
"authors",
2119
"copyrights",
2220
"doi",
2321
"isbn",
2422
"language",
23+
"publication_date",
2524
"publication_type",
26-
"sections",
2725
"publisher",
2826
"publisher_location",
27+
"pubmed_id",
28+
"sections",
29+
"title",
2930
)
3031

3132
def __init__(

src/pymedx/helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Module for helper functions."""
2+
23
from __future__ import annotations
34

45
import datetime
@@ -127,8 +128,7 @@ def get_range_months(
127128
current_end_date = next_month - datetime.timedelta(days=next_month.day)
128129

129130
# Adjust the end date if it goes beyond the specified end_date
130-
if current_end_date > end_date:
131-
current_end_date = end_date
131+
current_end_date = min(current_end_date, end_date)
132132

133133
date_ranges.append((current_start_date, current_end_date))
134134

tests/.env.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NCBI_API_KEY=${NCBI_API_KEY}
2+
SERVICE_EMAIL=${SERVICE_EMAIL}

tests/conftest.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
"""Configuration for the tests."""
2+
23
import os
34

5+
from pathlib import Path
6+
from typing import Dict, cast
7+
48
import pytest
59
import requests_cache
610

11+
from dotenv import dotenv_values, load_dotenv
712
from pymedx.api import PubMed, PubMedCentral
813

914

@@ -28,8 +33,18 @@ def setup_request_cache():
2833
# requests_cache doesn't require special teardown
2934

3035

36+
@pytest.fixture(scope="session")
37+
def env() -> dict[str, str]:
38+
"""Return a fixture for the environment variables from .env."""
39+
dotenv_file = Path(__file__).parent / ".env"
40+
if dotenv_file.exists():
41+
load_dotenv(dotenv_file)
42+
return cast(Dict[str, str], dotenv_values(dotenv_file) or {})
43+
return {}
44+
45+
3146
@pytest.fixture(scope="session", autouse=True)
32-
def pubmed() -> PubMed:
47+
def pubmed(env) -> PubMed:
3348
"""Fixture to create a PubMed instance."""
3449
params = dict(tool="TestTool", email="[email protected]")
3550

@@ -41,7 +56,7 @@ def pubmed() -> PubMed:
4156

4257

4358
@pytest.fixture(scope="session", autouse=True)
44-
def pmc() -> PubMedCentral:
59+
def pmc(env) -> PubMedCentral:
4560
"""Fixture to create a PubMed instance."""
4661
params = dict(tool="TestTool", email="[email protected]")
4762

tests/data/pmid_ 31815395.xml

+4
Large diffs are not rendered by default.

tests/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for the api module."""
22

3-
43
from pymedx.api import (
54
PubMed,
65
)

tests/test_article.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test for the article module."""
2+
23
import datetime
34

45
import pytest

tests/test_book.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for the book module."""
2+
23
import datetime
34

45
import pytest

tests/test_helpers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def test_batches(self):
2525
generated_batches = list(batches(input_list, batch_size))
2626

2727
# Verify
28-
assert (
29-
generated_batches == expected_batches
30-
), "Batches not generated as expected."
28+
assert generated_batches == expected_batches, (
29+
"Batches not generated as expected."
30+
)
3131

3232
def test_get_content(self):
3333
"""Test the getContent function."""

tests/test_pmc_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for the api module."""
22

3-
43
from pymedx.api import PubMedCentral
54

65

tests/test_pmc_article.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test for the article module."""
2+
23
import datetime
34

45
import pytest

0 commit comments

Comments
 (0)