Skip to content

Commit

Permalink
Fix: more test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lwasser committed Mar 7, 2024
1 parent 02a1432 commit a2f4f64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/pyosmeta/parse_issues.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import warnings
from datetime import datetime

import requests
Expand Down Expand Up @@ -665,7 +666,13 @@ def comment_to_list(self, issue: dict[str, str]) -> tuple[str, list[str]]:
None,
)

pkg_name = body_data[name_index][1] if name_index else None
if name_index is None:
warnings.warn(
"Package Name not found in the issue comment.", UserWarning
)
pkg_name = "missing_name"
else:
pkg_name = body_data[name_index][1]

return clean_markdown(pkg_name), body_data

Expand Down
29 changes: 17 additions & 12 deletions tests/unit/test_get_contrib_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyosmeta.parse_issues import ProcessIssues
import pytest

sample_response = {
"url": "https://api.github.com/repos/pyOpenSci/software-submission/issues/147",
Expand Down Expand Up @@ -26,28 +26,33 @@
"timeline_url": "https://api.github.com/repos/pyOpenSci/software-submission/issues/147/timeline",
}

# Create a generic object to use in all tests
p_issues = ProcessIssues(
repo_name="pyostest", org="pyopensci", label_name="test"
)


def test_comment_to_list_returns_list():
def test_comment_to_list_returns_list(process_issues):
"""Test that comment_to_list returns a list"""

name, body = p_issues.comment_to_list(sample_response)
name, body = process_issues.comment_to_list(sample_response)

assert isinstance(body, list)


def test_comment_no_name():
def test_comment_no_name(process_issues):
"""Test what happens if the package name key is missing in the review
this means that a user has likely modified the template.
In that case we just insert a placeholder name and keep processing issues.
This is a template issue not a code issue.
"""

name, body = p_issues.comment_to_list(sample_response_no_name)
with pytest.warns(
UserWarning, match="Package Name not found in the issue comment."
):
name, body = process_issues.comment_to_list(sample_response_no_name)
assert name == "missing_name"


def test_comment_to_list_package_name():
def test_comment_to_list_package_name(process_issues):
"""Test that comment_to_list returns a proper package name"""

name, body = p_issues.comment_to_list(sample_response)
name, body = process_issues.comment_to_list(sample_response)

assert name == "sunpy"
12 changes: 6 additions & 6 deletions tests/unit/test_parse_issue_header_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def test_comment_to_list(process_issues, issue_list):
("`Code`", "Code"),
("**Bold**", "Bold"),
("***Strong***", "Strong"),
("`*Code*`", "*Code*"),
("`**Code**`", "**Code**"),
("`***Code***`", "***Code***"),
("`Code***`", "Code***"),
("***Code`", "***Code"),
("***Code*`", "***Code*"),
("`*Code*`", "Code"),
("`**Code**`", "Code"),
("`***Code***`", "Code"),
("`Code***`", "Code"),
("***Code`", "Code"),
("***Code*`", "Code"),
],
)
def test_clean_markdown(input_string, expected_output):
Expand Down

0 comments on commit a2f4f64

Please sign in to comment.