Skip to content

Commit bc3d395

Browse files
committed
Fix: add tests for categories
1 parent e341f40 commit bc3d395

File tree

6 files changed

+82
-8
lines changed

6 files changed

+82
-8
lines changed

src/pyosmeta/parse_issues.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,14 @@ def get_categories(
725725
The first comment from the issue split into lines and then the
726726
lines split as by self.parse_comment()
727727
728-
fmt : bool
729-
Applies some formatting changes to the categories to match what is
730-
required for the website.
728+
section_str : str
729+
The section string to find where the categories live in the review
730+
metadata. Example ## Scope contains the package categories such as
731+
data viz, etc
732+
733+
num_vals : int
734+
Number of categories expected in the list. for instance
735+
3 partner options.
731736
"""
732737
# Find the starting index of the category section
733738
# This will be more robust if we use starts_with rather than in i think
@@ -737,8 +742,9 @@ def get_categories(
737742
for i, sublist in enumerate(issue_list)
738743
if section_str in sublist
739744
)
740-
# Iterate from scope index to first line starting with " - ["
741-
# To find list of category check boxes
745+
# Iterate starting at the specified section location index
746+
# find the first line starting with " - ["
747+
# This represents the first category in a list of categories
742748
for i in range(index + 1, len(issue_list)):
743749
if issue_list[i] and issue_list[i][0].startswith("- ["):
744750
cat_index = i
@@ -748,10 +754,14 @@ def get_categories(
748754
return None
749755

750756
# Get checked categories for package
757+
# TODO: it would be nice to figure out where the end of the list is
758+
# rather than hard coding it
751759
cat_list = issue_list[cat_index : cat_index + num_vals]
752760
selected = [
753761
item[0] for item in cat_list if re.search(r"- \[[xX]\] ", item[0])
754762
]
763+
# Above returns a list of list elements that are checked
764+
# Now, clean the extra markdown and only return the category text
755765
cleaned = [re.sub(r"- \[[xX]\] ", "", item) for item in selected]
756766
categories = [
757767
re.sub(r"(\w+) (\w+)", r"\1-\2", item) for item in cleaned

src/tests/__init__.py

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

tests/__init__.py

Whitespace-only changes.

tests/unit/__init__.py

Whitespace-only changes.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import pytest
2+
3+
from pyosmeta.parse_issues import ProcessIssues
4+
5+
checked = [
6+
["Submitting Author", "Nabil Freij (@nabobalis)"],
7+
["- sunpy is a community-developed, free and open-source."],
8+
["## Scope"],
9+
["- Please indicate which category or categories."],
10+
["- [X] Data retrieval"],
11+
["- [ ] Data extraction"],
12+
["- [x] Data Viz"],
13+
["## Domain Specific"],
14+
["something else"],
15+
]
16+
17+
not_checked = [
18+
["Submitting Author", "Nabil Freij (@nabobalis)"],
19+
["- sunpy is a community-developed, free and open-source."],
20+
["## Scope"],
21+
["- Please indicate which category or categories."],
22+
["- [ ] Data retrieval"],
23+
["- [ ] Data extraction"],
24+
["- [ ] Data Viz"],
25+
["## Domain Specific"],
26+
["something else"],
27+
]
28+
29+
no_categories = [
30+
["Submitting Author", "Nabil Freij (@nabobalis)"],
31+
["- sunpy is a community-developed, free and open-source."],
32+
["something else"],
33+
]
34+
35+
36+
@pytest.mark.parametrize(
37+
"issue_list, expected_categories",
38+
[
39+
(
40+
checked,
41+
["data-retrieval", "data-viz"],
42+
),
43+
(
44+
not_checked,
45+
[],
46+
),
47+
(
48+
no_categories,
49+
None,
50+
),
51+
],
52+
)
53+
def test_get_categories(
54+
issue_list: list[list[str]], expected_categories: list[str | None]
55+
):
56+
# Initialize your class or use an existing instance
57+
issues = ProcessIssues(
58+
org="pyopensci",
59+
repo_name="software-submission",
60+
label_name="presubmission",
61+
)
62+
63+
# Call the get_categories method
64+
categories = issues.get_categories(issue_list, "## Scope", 3)
65+
66+
# Assert the result matches the expected categories
67+
assert categories == expected_categories

0 commit comments

Comments
 (0)