Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a51e311

Browse filesBrowse files
hugovkCAM-Gerlach
andauthored
blurb: Add tests and run on CI (#520)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent c9c3e4a commit a51e311
Copy full SHA for a51e311

File tree

4 files changed

+167
-70
lines changed
Filter options

4 files changed

+167
-70
lines changed

‎.coveragerc

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# .coveragerc to control coverage.py
2+
3+
[report]
4+
# Regexes for lines to exclude from consideration
5+
exclude_also =
6+
# Don't complain if non-runnable code isn't run:
7+
if __name__ == .__main__.:
8+
def main
9+
10+
[run]
11+
omit =
12+
**/blurb/__main__.py

‎.github/workflows/tests.yml

Copy file name to clipboardExpand all lines: .github/workflows/tests.yml
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: Tests
22

33
on: [push, pull_request, workflow_dispatch]
44

5+
env:
6+
FORCE_COLOR: 1
7+
58
jobs:
69
build_ubuntu:
710
strategy:
11+
fail-fast: false
812
matrix:
913
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1014
name: ${{ matrix.python-version }}
@@ -14,17 +18,26 @@ jobs:
1418
- uses: actions/setup-python@v5
1519
with:
1620
python-version: ${{ matrix.python-version }}
21+
allow-prereleases: true
1722
cache: pip
1823
cache-dependency-path: ".github/workflows/tests.yml"
1924
- name: setup
2025
run: |
2126
python --version
2227
python -m pip install --upgrade pip
23-
python -m pip install --upgrade flit
28+
python -m pip install --upgrade pytest pytest-cov pyfakefs
2429
- name: install
2530
run: |
2631
cd blurb
27-
flit install
32+
python -m pip install -e .
2833
- name: test
2934
run: |
3035
blurb test
36+
- name: pytest
37+
run: |
38+
python -I -m pytest --cov blurb
39+
- name: Upload coverage
40+
uses: codecov/codecov-action@v3
41+
with:
42+
flags: ${{ matrix.python-version }}
43+
name: Python ${{ matrix.python-version }}

‎blurb/blurb.py

Copy file name to clipboardExpand all lines: blurb/blurb.py
-68Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import io
5252
import inspect
5353
import itertools
54-
import math
5554
import os
5655
from pathlib import Path
5756
import re
@@ -249,40 +248,6 @@ def safe_mkdir(path):
249248
os.makedirs(path)
250249

251250

252-
def which(cmd, path="PATH"):
253-
"""Find cmd on PATH."""
254-
if os.path.exists(cmd):
255-
return cmd
256-
if cmd[0] == '/':
257-
return None
258-
for segment in os.getenv(path).split(":"):
259-
program = os.path.normpath(os.path.join(segment, cmd))
260-
if os.path.exists(program):
261-
return program
262-
return None
263-
264-
265-
def strip_whitespace_lines(lines):
266-
# strip from head
267-
while lines:
268-
if lines[0]:
269-
break
270-
lines.pop(0)
271-
272-
# strip from tail
273-
while lines:
274-
if lines[-1]:
275-
return
276-
lines.pop()
277-
278-
279-
def longest_line(lines):
280-
longest = 0
281-
for line in lines:
282-
longest = max(longest, len(line))
283-
return longest
284-
285-
286251
def version_key(element):
287252
fields = list(element.split("."))
288253
if len(fields) == 1:
@@ -644,31 +609,6 @@ def save_next(self):
644609
blurb.save(filename)
645610
return filename
646611

647-
def save_split_next(self):
648-
"""
649-
Save out blurbs created from "blurb split".
650-
They don't have dates, so we have to get creative.
651-
"""
652-
filenames = []
653-
# the "date" MUST have a leading zero.
654-
# this ensures these files sort after all
655-
# newly created blurbs.
656-
width = int(math.ceil(math.log(len(self), 10))) + 1
657-
i = 1
658-
blurb = Blurbs()
659-
while self:
660-
metadata, body = self.pop()
661-
metadata['date'] = str(i).rjust(width, '0')
662-
if 'release date' in metadata:
663-
del metadata['release date']
664-
blurb.append((metadata, body))
665-
filename = blurb._extract_next_filename()
666-
blurb.save(filename)
667-
blurb.clear()
668-
filenames.append(filename)
669-
i += 1
670-
return filenames
671-
672612

673613
tests_run = 0
674614

@@ -706,13 +646,6 @@ def filename_test(self, filename):
706646
b.load(filename)
707647

708648

709-
710-
def run(s):
711-
process = subprocess.run(s.split(), capture_output=True)
712-
process.check_returncode()
713-
return process.stdout.decode('ascii')
714-
715-
716649
readme_re = re.compile(r"This is \w+ version \d+\.\d+").match
717650

718651
def chdir_to_repo_root():
@@ -1012,7 +945,6 @@ def release(version):
1012945
metadata = {"no changes": "True", "gh-issue": "0", "section": "Library", "date": date, "nonce": nonceify(body)}
1013946
blurbs.append((metadata, body))
1014947
else:
1015-
no_changes = None
1016948
count = len(filenames)
1017949
print(f'Merging {count} blurbs to "{output}".')
1018950

‎blurb/tests/test_blurb.py

Copy file name to clipboard
+140Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import pytest
2+
from pyfakefs.fake_filesystem import FakeFilesystem
3+
4+
import blurb
5+
6+
7+
UNCHANGED_SECTIONS = (
8+
"C API",
9+
"Core and Builtins",
10+
"Library",
11+
)
12+
13+
14+
@pytest.mark.parametrize("section", UNCHANGED_SECTIONS)
15+
def test_sanitize_section_no_change(section: str) -> None:
16+
sanitized = blurb.sanitize_section(section)
17+
assert sanitized == section
18+
19+
20+
@pytest.mark.parametrize(
21+
"section, expected",
22+
(
23+
("Tools/Demos", "Tools-Demos"),
24+
),
25+
)
26+
def test_sanitize_section_changed(section: str, expected: str) -> None:
27+
sanitized = blurb.sanitize_section(section)
28+
assert sanitized == expected
29+
30+
31+
@pytest.mark.parametrize("section", UNCHANGED_SECTIONS)
32+
def test_unsanitize_section_no_change(section: str) -> None:
33+
unsanitized = blurb.unsanitize_section(section)
34+
assert unsanitized == section
35+
36+
37+
@pytest.mark.parametrize(
38+
"section, expected",
39+
(
40+
("Tools-Demos", "Tools/Demos"),
41+
),
42+
)
43+
def test_unsanitize_section_changed(section: str, expected: str) -> None:
44+
unsanitized = blurb.unsanitize_section(section)
45+
assert unsanitized == expected
46+
47+
48+
def test_glob_blurbs_next(fs: FakeFilesystem) -> None:
49+
# Arrange
50+
fake_news_entries = (
51+
"Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst",
52+
"Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst",
53+
"Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst",
54+
"Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst",
55+
)
56+
fake_readmes = (
57+
"Misc/NEWS.d/next/Library/README.rst",
58+
"Misc/NEWS.d/next/Core and Builtins/README.rst",
59+
"Misc/NEWS.d/next/Tools-Demos/README.rst",
60+
"Misc/NEWS.d/next/C API/README.rst",
61+
)
62+
for fn in fake_news_entries + fake_readmes:
63+
fs.create_file(fn)
64+
65+
# Act
66+
filenames = blurb.glob_blurbs("next")
67+
68+
# Assert
69+
assert set(filenames) == set(fake_news_entries)
70+
71+
72+
@pytest.mark.parametrize(
73+
"news_entry, expected_section",
74+
(
75+
(
76+
"Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst",
77+
"Library",
78+
),
79+
(
80+
"Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst",
81+
"Core and Builtins",
82+
),
83+
(
84+
"Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst",
85+
"Tools/Demos",
86+
),
87+
(
88+
"Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst",
89+
"C API",
90+
),
91+
),
92+
)
93+
def test_load_next(news_entry: str, expected_section: str, fs: FakeFilesystem) -> None:
94+
# Arrange
95+
fs.create_file(news_entry, contents="testing")
96+
blurbs = blurb.Blurbs()
97+
98+
# Act
99+
blurbs.load_next(news_entry)
100+
101+
# Assert
102+
metadata = blurbs[0][0]
103+
assert metadata["section"] == expected_section
104+
105+
106+
@pytest.mark.parametrize(
107+
"news_entry, expected_path",
108+
(
109+
(
110+
"Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst",
111+
"root/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst",
112+
),
113+
(
114+
"Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst",
115+
"root/Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst",
116+
),
117+
(
118+
"Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst",
119+
"root/Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst",
120+
),
121+
(
122+
"Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst",
123+
"root/Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst",
124+
),
125+
),
126+
)
127+
def test_extract_next_filename(
128+
news_entry: str, expected_path: str, fs: FakeFilesystem
129+
) -> None:
130+
# Arrange
131+
fs.create_file(news_entry, contents="testing")
132+
blurb.root = "root"
133+
blurbs = blurb.Blurbs()
134+
blurbs.load_next(news_entry)
135+
136+
# Act
137+
path = blurbs._extract_next_filename()
138+
139+
# Assert
140+
assert path == expected_path

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.