Skip to content

Commit 113e69a

Browse files
committed
update .gitignore with coverage
1 parent dc68fbd commit 113e69a

File tree

5 files changed

+44
-139
lines changed

5 files changed

+44
-139
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ vendor/
1818
test_images
1919
*-version
2020
.DS_Store
21+
.coverage

_conferences/__main__.py

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,39 @@
77
import gh_issues
88

99

10-
def get_conference_issues() -> Iterator[gh_issues.Issue]:
11-
query = "repo:blackpythondevs/blackpythondevs.github.io type:issue label:conference"
10+
QUERY = "repo:blackpythondevs/blackpythondevs.github.io type:issue label:conference"
11+
12+
13+
def get_conference_issues(
14+
query: str = QUERY,
15+
) -> Iterator[gh_issues.Issue]: # pragma no cover
1216
issues = gh_issues.issues_by_query(query)
1317
return issues
1418

1519

16-
def normalize_url(url_match: str = str):
17-
valid_url = None
18-
# Ensure the url field is not blank and the url matches the regex
19-
if url_match is not None and url_match.strip() != "":
20-
# Parse the url and see if a scheme (`https`) is included in it
21-
# If not, then prepend `https` to the url from the issue body
22-
# This guards against the website thinking the passed in url is another page on https://blackpythondevs.com/
20+
def normalize_url(url_match: str | None) -> str | None:
21+
"""
22+
Parse the url and see if a scheme (`https`) is included in it.
23+
If not, then prepend `https` to the url from the issue body
24+
25+
This guards against the website thinking the passed in url is another page on https://blackpythondevs.com/
26+
"""
27+
if url_match:
2328
parsed_url = urlparse(url_match)
2429

2530
if "http" not in parsed_url.scheme.casefold():
26-
valid_url = f"https://{url_match}"
31+
return f"https://{url_match}"
2732
else:
28-
valid_url = url_match
29-
30-
return valid_url
31-
32-
33-
def write_conferences_to_file(confs: list[dict]):
34-
# Write the conferences to the _data/conferences.yml file
35-
conferences_path.write_text(json.dumps(confs))
33+
return url_match
3634

3735

3836
def __to_conference_date(conference_date: str) -> datetime.date:
3937
return datetime.date.fromisoformat(conference_date)
4038

4139

42-
if __name__ == "__main__":
40+
def parse_conference(issue: gh_issues.Issue) -> dict[str, str | None]:
41+
"""convert an issue to a dictionary of parsed data"""
42+
4343
KEYS = [
4444
"conference_name",
4545
"url",
@@ -51,16 +51,31 @@ def __to_conference_date(conference_date: str) -> datetime.date:
5151
"speaking",
5252
]
5353

54-
conferences = []
55-
for _issue in get_conference_issues():
56-
if not hasattr(_issue, "conference_end_date"):
57-
continue
54+
_issue = {k: getattr(issue, k, None) for k in KEYS}
55+
_issue["url"] = normalize_url(_issue.get("url", None))
56+
return _issue
57+
58+
59+
def _validate_issue(issue: gh_issues.Issue, date_to_check: str):
60+
"""Validate an issue based on its `date_to_check`"""
61+
if not (valid_date := getattr(issue, date_to_check, False)):
62+
return False
63+
else:
64+
return __to_conference_date(valid_date) >= datetime.date.today()
65+
66+
67+
def build_conferences() -> list[dict[str, str | None]]: # pragma: no cover
68+
return [
69+
parse_conference(issue)
70+
for issue in get_conference_issues()
71+
if _validate_issue(issue, "conference_end_date")
72+
]
5873

59-
if __to_conference_date(_issue.conference_end_date) >= datetime.date.today():
60-
conferences.append({k: getattr(_issue, k, None) for k in KEYS})
6174

75+
if __name__ == "__main__": # pragma: no cover
6276
ROOT = pathlib.Path(__file__).parent.parent
6377
conferences_path = ROOT.joinpath("_data/conferences.json")
78+
conferences = build_conferences()
6479
conferences_path.write_text(
6580
json.dumps(
6681
list(

_data/conferences.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"conference_name": "PyconUg",
4-
"url": "ug.pycon.org",
4+
"url": "https://ug.pycon.org",
55
"conference_start_date": "2024-10-09",
66
"conference_end_date": "2024-10-13",
77
"conference_type": "in-person",
@@ -19,5 +19,4 @@
1919
"summary": "PyHo, champion the leverage of Python in education promote diversity and inclusion from underrepresented communities within\nthe/beyond our region. Provide the foundational platform for new and experienced speakers alike to share ideas and resources.",
2020
"speaking": null
2121
}
22-
]
23-
22+
]

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ black
22
ephemeral_port_reserve
33
gh-issues
44
pre-commit
5+
pytest-mock
56
pytest-pyodide
67
pytest-playwright
78
pytest-xprocess

tests/test.py

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import pytest
44
from xprocess import ProcessStarter
5-
from _conferences.__main__ import parse_conference_details
65
from playwright.sync_api import Page, expect, sync_playwright
76

87

@@ -100,113 +99,3 @@ def test_mailto_bpdevs(page_url: tuple[Page, str]) -> None:
10099
page.goto(live_server_url)
101100
mailto = page.get_by_role("link", name="email")
102101
expect(mailto).to_have_attribute("href", "mailto:[email protected]")
103-
104-
105-
def test_conference_parsing_valid_url():
106-
example_conf_issue = """### Conference Name
107-
108-
Test Conference Title
109-
110-
### URL
111-
112-
https://microsoft.com
113-
114-
### Conference Dates
115-
116-
10 - 15 Sep 2050
117-
118-
### Conference Type
119-
120-
both
121-
122-
### Conference Location
123-
124-
Redmond, WA, USA
125-
126-
### Summary
127-
128-
Test Conference Summary
129-
130-
### Speaking
131-
132-
* [Satya Nadella](https://www.linkedin.com/in/satyanadella/)
133-
"""
134-
expected_name = "Test Conference Title"
135-
expected_url = "https://microsoft.com"
136-
parsed_conf = parse_conference_details(issue_body=example_conf_issue)
137-
138-
assert parsed_conf["name"] == expected_name
139-
assert parsed_conf["url"] == expected_url
140-
141-
142-
def test_conference_parsing_logic_no_url_scheme():
143-
example_conf_issue = """### Conference Name
144-
145-
Test Conference Title
146-
147-
### URL
148-
149-
microsoft.com
150-
151-
### Conference Dates
152-
153-
10 - 15 Sep 2050
154-
155-
### Conference Type
156-
157-
both
158-
159-
### Conference Location
160-
161-
Redmond, WA, USA
162-
163-
### Summary
164-
165-
Test Conference Summary
166-
167-
### Speaking
168-
169-
* [Satya Nadella](https://www.linkedin.com/in/satyanadella/)
170-
"""
171-
expected_name = "Test Conference Title"
172-
expected_url = "https://microsoft.com"
173-
parsed_conf = parse_conference_details(issue_body=example_conf_issue)
174-
175-
assert parsed_conf["name"] == expected_name
176-
assert parsed_conf["url"] == expected_url
177-
178-
179-
def test_conference_parsing_logic_no_url():
180-
example_conf_issue = """### Conference Name
181-
182-
Test Conference Title
183-
184-
### URL
185-
186-
187-
### Conference Dates
188-
189-
10 - 15 Sep 2050
190-
191-
### Conference Type
192-
193-
both
194-
195-
### Conference Location
196-
197-
Redmond, WA, USA
198-
199-
### Summary
200-
201-
Test Conference Summary
202-
203-
### Speaking
204-
205-
* [Satya Nadella](https://www.linkedin.com/in/satyanadella/)
206-
"""
207-
expected_name = "Test Conference Title"
208-
expected_url = None
209-
parsed_conf = parse_conference_details(issue_body=example_conf_issue)
210-
211-
assert parsed_conf["name"] == expected_name
212-
assert parsed_conf["url"] == expected_url

0 commit comments

Comments
 (0)