Skip to content

Commit 9740ee4

Browse files
authored
Merge branch 'main' into add-coverage
2 parents 8245277 + fe96d53 commit 9740ee4

File tree

5 files changed

+96
-20
lines changed

5 files changed

+96
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fix: migrate to pytest for tests and setup hatch scripts (#89, @lwasser)
99
- Add: Partner support to package (#92, @lwasser)
1010
- Add: Code coverage setup (#97, @lwasser)
11+
- Fix: Add validation step to categories attr in pydantic model (#105, @lwasser)
1112

1213
## [v0.15](https://github.com/pyOpenSci/pyosMeta/releases/tag/v0.15)
1314

pyproject.toml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ authors = [{ name = "Leah Wasser", email = "[email protected]" }]
1010
maintainers = [
1111
{ name = "pyOpenSci", email = "[email protected]" }, # Optional
1212
]
13-
1413
classifiers = [
1514
"Development Status :: 4 - Beta",
1615
"Intended Audience :: Developers",
@@ -24,33 +23,31 @@ classifiers = [
2423
"Programming Language :: Python :: 3.10",
2524
"Programming Language :: Python :: 3.11",
2625
]
27-
28-
2926
dependencies = [
30-
"ruamel-yaml>=0.17.21",
31-
"requests",
32-
"python-dotenv",
33-
"pydantic>=2.0",
34-
"requests",
35-
"python-dotenv",
27+
"pydantic>=2.0",
28+
"python-dotenv",
29+
"requests",
30+
"ruamel-yaml>=0.17.21",
3631
]
37-
38-
39-
# This is the metadata that pip reads to understand what versions your package supports
32+
# This is metadata that pip reads to understand what Python versions your package supports
4033
requires-python = ">=3.10"
4134
readme = "README.md"
4235
license = { text = "MIT" }
4336

44-
4537
[project.optional-dependencies]
46-
dev = ["pre-commit"]
38+
dev = [
39+
"black",
40+
"flake8",
41+
"pre-commit",
42+
"pytest",
43+
"pytest-cov"
44+
]
4745

4846
[project.urls]
4947
"Homepage" = "https://github.com/pyopensci/pyosmeta/"
5048
"Bug Reports" = "https://github.com/pyopensci/pyosmeta/issues"
5149
"Source" = "https://github.com/pyopensci/pyosmeta/issues"
5250

53-
5451
# These are entry points that allow you to surface specific functionality
5552
# for a user to run directly from the package.
5653
[project.scripts]
@@ -79,6 +76,9 @@ run-coverage = "pytest --cov-config=pyproject.toml --cov=pyosmeta --cov=tests/*"
7976
run-no-cov = "run-coverage --no-cov"
8077
run-report = "run-coverage --cov-report=xml:coverage.xml"
8178

79+
80+
### Tool configuration ###
81+
8282
[tool.black]
8383
line-length = 79
8484
target-version = ['py310']

src/pyosmeta/__about__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/pyosmeta/parse_issues.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,51 @@ def clean_gh_url(cls, user: dict[str, str]) -> dict[str, str]:
265265

266266
return user
267267

268+
@field_validator(
269+
"categories",
270+
mode="before",
271+
)
272+
@classmethod
273+
def clean_categories(cls, categories: list[str]) -> list[str]:
274+
"""Make sure each category in the list is a valid value.
275+
276+
Valid pyos software categories are:
277+
citation-management-bibliometrics, data-deposition,
278+
data-extraction, data-processing-munging, data-retrieval,
279+
data-validation-testing, data-visualization-analysis,
280+
database-interoperability, education,
281+
geospatial, scientific-software-wrappers,
282+
workflow-automation-versioning
283+
284+
285+
Parameters
286+
----------
287+
categories : list[str]
288+
List of categories to clean.
289+
290+
Returns
291+
-------
292+
list[str]
293+
List of cleaned categories.
294+
"""
295+
296+
valid_categories = {
297+
"data-processing": "data-processing-munging",
298+
"data-validation": "data-validation-testing",
299+
"scientific-software": "scientific-software-wrapper",
300+
}
301+
302+
cleaned_cats = []
303+
for category in categories:
304+
for valid_prefix, valid_cat in valid_categories.items():
305+
if category.startswith(valid_prefix):
306+
cleaned_cats.append(valid_cat)
307+
break
308+
else:
309+
# No match found, keep the original category
310+
cleaned_cats.append(category)
311+
return cleaned_cats
312+
268313

269314
@dataclass
270315
class ProcessIssues:

tests/unit/test_parse_categories.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from pyosmeta.parse_issues import ProcessIssues
3+
from pyosmeta.parse_issues import ProcessIssues, ReviewModel
44

55
checked = [
66
["Submitting Author", "Nabil Freij (@nabobalis)"],
@@ -65,3 +65,37 @@ def test_get_categories(
6565

6666
# Assert the result matches the expected categories
6767
assert categories == expected_categories
68+
69+
70+
@pytest.mark.parametrize(
71+
"input_categories,expected_return",
72+
[
73+
(
74+
["data-processing"],
75+
["data-processing-munging"],
76+
),
77+
(
78+
["data-processing/munging"],
79+
["data-processing-munging"],
80+
),
81+
(
82+
["scientific-software and friends"],
83+
["scientific-software-wrapper"],
84+
),
85+
(
86+
["data-validation and things -testing"],
87+
["data-validation-testing"],
88+
),
89+
(
90+
["data-processing", "data-extraction"],
91+
["data-processing-munging", "data-extraction"],
92+
),
93+
],
94+
)
95+
def test_clean_categories(
96+
input_categories: list[str], expected_return: list[str]
97+
):
98+
"""Test that ensures our pydantic model cleans categories as expected"""
99+
100+
review = ReviewModel(categories=input_categories)
101+
assert review.categories == expected_return

0 commit comments

Comments
 (0)