Skip to content

Commit 438dfa2

Browse files
Add test validating markdown after all badge commands run in sequence
Creates a canonical expected_all_badges.md file that prek (markdownlint + prettier) validates, and a test that runs all 7 badge commands on a blank-slate project and compares the resulting README against this canonical file. Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/d900c1cf-759f-4cd3-85a2-4ccac33d5116 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent d1120c8 commit 438dfa2

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# my-project
2+
3+
[![PyPI Version](https://img.shields.io/pypi/v/my-project.svg)](https://pypi.python.org/pypi/my-project)
4+
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
5+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
6+
[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)
7+
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
8+
[![usethis](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/usethis-python/usethis-python/main/assets/badge/v1.json)](https://github.com/usethis-python/usethis-python)
9+
[![Socket Badge](https://badge.socket.dev/pypi/package/my-project)](https://socket.dev/pypi/package/my-project/overview)

tests/usethis/_core/test_core_badge.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
import pytest
44

5-
from usethis._core.badge import Badge, add_badge, is_badge, remove_badge
5+
from usethis._core.badge import (
6+
Badge,
7+
add_badge,
8+
get_pre_commit_badge,
9+
get_pypi_badge,
10+
get_ruff_badge,
11+
get_socket_badge,
12+
get_ty_badge,
13+
get_usethis_badge,
14+
get_uv_badge,
15+
is_badge,
16+
remove_badge,
17+
)
618
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
719
from usethis._test import change_cwd
820

@@ -734,3 +746,31 @@ def test_already_exists_no_newline_added(self, bare_dir: Path):
734746

735747
# Assert
736748
assert path.read_text() == content
749+
750+
751+
class TestAllBadgesMarkdownValid:
752+
"""Test that adding all badges in sequence produces valid markdown.
753+
754+
The expected output is stored as a canonical .md file and validated by prek
755+
(markdownlint + prettier), ensuring the generated markdown is always valid.
756+
"""
757+
758+
def test_all_badges(self, bare_dir: Path):
759+
# Arrange
760+
(bare_dir / "pyproject.toml").write_text('[project]\nname = "my-project"\n')
761+
762+
# Act
763+
with change_cwd(bare_dir), PyprojectTOMLManager():
764+
add_badge(get_pypi_badge())
765+
add_badge(get_uv_badge())
766+
add_badge(get_ruff_badge())
767+
add_badge(get_ty_badge())
768+
add_badge(get_pre_commit_badge())
769+
add_badge(get_usethis_badge())
770+
add_badge(get_socket_badge())
771+
772+
# Assert
773+
expected = (
774+
Path(__file__).parent / "assets" / "expected_all_badges.md"
775+
).read_text()
776+
assert (bare_dir / "README.md").read_text() == expected

0 commit comments

Comments
 (0)