From 4246be586a6e869a3f85a26b3a7ca16b033d0cf1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 28 Mar 2023 08:45:18 +0300 Subject: [PATCH 01/11] Remove unused code --- blurb/blurb.py | 68 -------------------------------------------------- 1 file changed, 68 deletions(-) diff --git a/blurb/blurb.py b/blurb/blurb.py index 7557c23..70a0bd5 100755 --- a/blurb/blurb.py +++ b/blurb/blurb.py @@ -51,7 +51,6 @@ import io import inspect import itertools -import math import os from pathlib import Path import re @@ -249,40 +248,6 @@ def safe_mkdir(path): os.makedirs(path) -def which(cmd, path="PATH"): - """Find cmd on PATH.""" - if os.path.exists(cmd): - return cmd - if cmd[0] == '/': - return None - for segment in os.getenv(path).split(":"): - program = os.path.normpath(os.path.join(segment, cmd)) - if os.path.exists(program): - return program - return None - - -def strip_whitespace_lines(lines): - # strip from head - while lines: - if lines[0]: - break - lines.pop(0) - - # strip from tail - while lines: - if lines[-1]: - return - lines.pop() - - -def longest_line(lines): - longest = 0 - for line in lines: - longest = max(longest, len(line)) - return longest - - def version_key(element): fields = list(element.split(".")) if len(fields) == 1: @@ -639,31 +604,6 @@ def save_next(self): blurb.save(filename) return filename - def save_split_next(self): - """ - Save out blurbs created from "blurb split". - They don't have dates, so we have to get creative. - """ - filenames = [] - # the "date" MUST have a leading zero. - # this ensures these files sort after all - # newly created blurbs. - width = int(math.ceil(math.log(len(self), 10))) + 1 - i = 1 - blurb = Blurbs() - while self: - metadata, body = self.pop() - metadata['date'] = str(i).rjust(width, '0') - if 'release date' in metadata: - del metadata['release date'] - blurb.append((metadata, body)) - filename = blurb._extract_next_filename() - blurb.save(filename) - blurb.clear() - filenames.append(filename) - i += 1 - return filenames - tests_run = 0 @@ -701,13 +641,6 @@ def filename_test(self, filename): b.load(filename) - -def run(s): - process = subprocess.run(s.split(), capture_output=True) - process.check_returncode() - return process.stdout.decode('ascii') - - readme_re = re.compile(r"This is \w+ version \d+\.\d+").match def chdir_to_repo_root(): @@ -1007,7 +940,6 @@ def release(version): metadata = {"no changes": "True", "gh-issue": "0", "section": "Library", "date": date, "nonce": nonceify(body)} blurbs.append((metadata, body)) else: - no_changes = None count = len(filenames) print(f'Merging {count} blurbs to "{output}".') From edc630c3abcf85773446abfcc2abd7823e2e797f Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 28 Mar 2023 08:49:04 +0300 Subject: [PATCH 02/11] Add tests --- .coveragerc | 12 ++++ .github/workflows/tests.yml | 18 ++++- blurb/tests/test_blurb.py | 127 ++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 .coveragerc create mode 100644 blurb/tests/test_blurb.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..dcd3739 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,12 @@ +# .coveragerc to control coverage.py + +[report] +# Regexes for lines to exclude from consideration +exclude_also = + # Don't complain if non-runnable code isn't run: + if __name__ == .__main__.: + def main + +[run] +omit = + **/blurb/__main__.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cbb8cd2..5a25a05 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,9 @@ name: Tests on: [push, pull_request, workflow_dispatch] +env: + FORCE_COLOR: 1 + jobs: build_ubuntu: strategy: @@ -21,10 +24,23 @@ jobs: python --version python -m pip install --upgrade pip python -m pip install --upgrade flit + python -m pip install --upgrade pytest pytest-cov pyfakefs - name: install run: | cd blurb - flit install + pip install -e . - name: test run: | blurb test + - name: pytest + # TODO Pending https://github.com/pytest-dev/pyfakefs/issues/770 + if: matrix.python-version != '3.12-dev' + run: | + pytest --cov blurb + - name: Upload coverage + # TODO Pending https://github.com/pytest-dev/pyfakefs/issues/770 + if: matrix.python-version != '3.12-dev' + uses: codecov/codecov-action@v3 + with: + flags: ${{ matrix.python-version }} + name: Python ${{ matrix.python-version }} diff --git a/blurb/tests/test_blurb.py b/blurb/tests/test_blurb.py new file mode 100644 index 0000000..b305cd8 --- /dev/null +++ b/blurb/tests/test_blurb.py @@ -0,0 +1,127 @@ +import pytest +from pyfakefs.fake_filesystem import FakeFilesystem + +import blurb + + +@pytest.mark.parametrize( + "section, expected", + ( + ("C API", "C API"), + ("Core and Builtins", "Core and Builtins"), + ("Library", "Library"), + ("Tools/Demos", "Tools-Demos"), + ), +) +def test_sanitize_section(section: str, expected: str) -> None: + sanitized = blurb.sanitize_section(section) + assert sanitized == expected + + +@pytest.mark.parametrize( + "section, expected", + ( + ("C API", "C API"), + ("Core and Builtins", "Core and Builtins"), + ("Library", "Library"), + ("Tools-Demos", "Tools/Demos"), + ), +) +def test_unsanitize_section(section: str, expected: str) -> None: + unsanitized = blurb.unsanitize_section(section) + assert unsanitized == expected + + +def test_glob_blurbs_next(fs: FakeFilesystem) -> None: + # Arrange + fake_news_entries = ( + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", + "Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", + "Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", + "Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", + ) + fake_readmes = ( + "Misc/NEWS.d/next/Library/README.rst", + "Misc/NEWS.d/next/Core and Builtins/README.rst", + "Misc/NEWS.d/next/Tools-Demos/README.rst", + "Misc/NEWS.d/next/C API/README.rst", + ) + for fn in fake_news_entries + fake_readmes: + fs.create_file(fn) + + # Act + filenames = blurb.glob_blurbs("next") + + # Assert + assert set(filenames) == set(fake_news_entries) + + +@pytest.mark.parametrize( + "news_entry, expected_section", + ( + ( + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", + "Library", + ), + ( + "Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", + "Core and Builtins", + ), + ( + "Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", + "Tools/Demos", + ), + ( + "Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", + "C API", + ), + ), +) +def test_load_next(news_entry: str, expected_section: str, fs: FakeFilesystem) -> None: + # Arrange + fs.create_file(news_entry, contents="testing") + blurbs = blurb.Blurbs() + + # Act + blurbs.load_next(news_entry) + + # Assert + metadata = blurbs[0][0] + assert metadata["section"] == expected_section + + +@pytest.mark.parametrize( + "news_entry, expected_path", + ( + ( + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", + "root/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", + ), + ( + "Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", + "root/Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", + ), + ( + "Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", + "root/Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", + ), + ( + "Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", + "root/Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", + ), + ), +) +def test_extract_next_filename( + news_entry: str, expected_path: str, fs: FakeFilesystem +) -> None: + # Arrange + fs.create_file(news_entry, contents="testing") + blurb.root = "root" + blurbs = blurb.Blurbs() + blurbs.load_next(news_entry) + + # Act + path = blurbs._extract_next_filename() + + # Assert + assert path == expected_path From 85956bb581ecda347ff645d114b3583d0edb0cdf Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 29 Mar 2023 22:38:30 +0300 Subject: [PATCH 03/11] Don't install flit Co-authored-by: C.A.M. Gerlach --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5a25a05..df087ff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,6 @@ jobs: run: | python --version python -m pip install --upgrade pip - python -m pip install --upgrade flit python -m pip install --upgrade pytest pytest-cov pyfakefs - name: install run: | From c5454fd9fcef999f0889bec5362e675c03f95bae Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 29 Mar 2023 22:47:43 +0300 Subject: [PATCH 04/11] Build and install package, then test installed package --- .github/workflows/tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index df087ff..81d17e5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,8 @@ jobs: - name: install run: | cd blurb - pip install -e . + python -m build + echo dist/*.whl | xargs -I % python -m pip install % - name: test run: | blurb test @@ -35,7 +36,7 @@ jobs: # TODO Pending https://github.com/pytest-dev/pyfakefs/issues/770 if: matrix.python-version != '3.12-dev' run: | - pytest --cov blurb + python -I -m pytest --cov blurb - name: Upload coverage # TODO Pending https://github.com/pytest-dev/pyfakefs/issues/770 if: matrix.python-version != '3.12-dev' From dc704da47af482d97f53917b602c46284124df3b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 29 Mar 2023 22:50:01 +0300 Subject: [PATCH 05/11] Install build --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 81d17e5..e856e3b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,6 +8,7 @@ env: jobs: build_ubuntu: strategy: + fail-fast: false matrix: python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"] name: ${{ matrix.python-version }} @@ -23,7 +24,7 @@ jobs: run: | python --version python -m pip install --upgrade pip - python -m pip install --upgrade pytest pytest-cov pyfakefs + python -m pip install --upgrade build pytest pytest-cov pyfakefs - name: install run: | cd blurb From 2d4ee185ce4c548c5a7bef641b960cf7dec2a0fb Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 30 Mar 2023 22:06:41 +0300 Subject: [PATCH 06/11] Install in place for easier test coverage --- .github/workflows/tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e856e3b..dcf5728 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,12 +24,11 @@ jobs: run: | python --version python -m pip install --upgrade pip - python -m pip install --upgrade build pytest pytest-cov pyfakefs + python -m pip install --upgrade pytest pytest-cov pyfakefs - name: install run: | cd blurb - python -m build - echo dist/*.whl | xargs -I % python -m pip install % + python -m pip install -e . - name: test run: | blurb test From 199c01fda9e487190a62b4e67e8253b7de4f42a2 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 23 Jul 2023 14:10:55 +0200 Subject: [PATCH 07/11] Test on Python 3.12 --- .github/workflows/tests.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dcf5728..88ff525 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] name: ${{ matrix.python-version }} runs-on: ubuntu-latest steps: @@ -18,6 +18,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + allow-prereleases: true cache: pip cache-dependency-path: ".github/workflows/tests.yml" - name: setup @@ -33,13 +34,9 @@ jobs: run: | blurb test - name: pytest - # TODO Pending https://github.com/pytest-dev/pyfakefs/issues/770 - if: matrix.python-version != '3.12-dev' run: | python -I -m pytest --cov blurb - name: Upload coverage - # TODO Pending https://github.com/pytest-dev/pyfakefs/issues/770 - if: matrix.python-version != '3.12-dev' uses: codecov/codecov-action@v3 with: flags: ${{ matrix.python-version }} From ef68ed086392eca44579f7b2eff519f4af723b8e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 18 Dec 2023 09:40:02 +0200 Subject: [PATCH 08/11] Bump GitHub Actions --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 88ff525..2105bec 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,8 +14,8 @@ jobs: name: ${{ matrix.python-version }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} allow-prereleases: true From a1bfb19877938e28d212c06baccda0df0b3065cc Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 24 Dec 2023 22:32:02 +0200 Subject: [PATCH 09/11] Split tests into cases that change and cases that don't --- blurb/tests/test_blurb.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/blurb/tests/test_blurb.py b/blurb/tests/test_blurb.py index b305cd8..d1d70d8 100644 --- a/blurb/tests/test_blurb.py +++ b/blurb/tests/test_blurb.py @@ -4,30 +4,50 @@ import blurb +@pytest.mark.parametrize( + "section", + ( + "C API", + "Core and Builtins", + "Library", + ), +) +def test_sanitize_section_no_change(section: str) -> None: + sanitized = blurb.sanitize_section(section) + assert sanitized == section + + @pytest.mark.parametrize( "section, expected", ( - ("C API", "C API"), - ("Core and Builtins", "Core and Builtins"), - ("Library", "Library"), ("Tools/Demos", "Tools-Demos"), ), ) -def test_sanitize_section(section: str, expected: str) -> None: +def test_sanitize_section_changed(section: str, expected: str) -> None: sanitized = blurb.sanitize_section(section) assert sanitized == expected +@pytest.mark.parametrize( + "section", + ( + "C API", + "Core and Builtins", + "Library", + ), +) +def test_unsanitize_section_no_change(section: str) -> None: + unsanitized = blurb.unsanitize_section(section) + assert unsanitized == section + + @pytest.mark.parametrize( "section, expected", ( - ("C API", "C API"), - ("Core and Builtins", "Core and Builtins"), - ("Library", "Library"), ("Tools-Demos", "Tools/Demos"), ), ) -def test_unsanitize_section(section: str, expected: str) -> None: +def test_unsanitize_section_changed(section: str, expected: str) -> None: unsanitized = blurb.unsanitize_section(section) assert unsanitized == expected From 70f600460e435f4c365d2b9d7a91cf527974f82b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 25 Dec 2023 00:35:24 +0200 Subject: [PATCH 10/11] Factor out unchanged sections --- blurb/tests/test_blurb.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/blurb/tests/test_blurb.py b/blurb/tests/test_blurb.py index d1d70d8..c5c34a1 100644 --- a/blurb/tests/test_blurb.py +++ b/blurb/tests/test_blurb.py @@ -4,14 +4,14 @@ import blurb -@pytest.mark.parametrize( - "section", - ( - "C API", - "Core and Builtins", - "Library", - ), +UNCHANGED_SECTIONS = ( + "C API", + "Core and Builtins", + "Library", ) + + +@pytest.mark.parametrize("section", UNCHANGED_SECTIONS) def test_sanitize_section_no_change(section: str) -> None: sanitized = blurb.sanitize_section(section) assert sanitized == section @@ -28,14 +28,7 @@ def test_sanitize_section_changed(section: str, expected: str) -> None: assert sanitized == expected -@pytest.mark.parametrize( - "section", - ( - "C API", - "Core and Builtins", - "Library", - ), -) +@pytest.mark.parametrize("section", UNCHANGED_SECTIONS) def test_unsanitize_section_no_change(section: str) -> None: unsanitized = blurb.unsanitize_section(section) assert unsanitized == section From fbc74f98a908294fa4533d6bca4d2d0e2327906c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 15 Jan 2024 22:55:08 +0200 Subject: [PATCH 11/11] Update arbitrary issue numbers to be valid --- blurb/tests/test_blurb.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blurb/tests/test_blurb.py b/blurb/tests/test_blurb.py index c5c34a1..b2d06b5 100644 --- a/blurb/tests/test_blurb.py +++ b/blurb/tests/test_blurb.py @@ -73,7 +73,7 @@ def test_glob_blurbs_next(fs: FakeFilesystem) -> None: "news_entry, expected_section", ( ( - "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst", "Library", ), ( @@ -107,8 +107,8 @@ def test_load_next(news_entry: str, expected_section: str, fs: FakeFilesystem) - "news_entry, expected_path", ( ( - "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", - "root/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst", + "root/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst", ), ( "Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst",