Remove useless Hypothesis tests that fuzz trivial operations

Removed tests that were running 100 random inputs through string
operations that can never fail regardless of input:
- process_highlights: fuzzing "- " + string prepend
- process_authors: fuzzing ", ".join()
- PublicationEntry DOI URL: fuzzing f"https://doi.org/{doi}"

These tests add execution time without any chance of finding bugs.
This commit is contained in:
Sina Atalay
2026-03-25 04:05:28 +03:00
parent 1704a4be57
commit 005d1d835f
2 changed files with 28 additions and 102 deletions

View File

@@ -33,102 +33,36 @@ from rendercv.schema.models.locale.english_locale import EnglishLocale
from rendercv.schema.models.locale.locale import locale_adapter
class TestProcessHighlights:
@pytest.mark.parametrize(
("highlights", "expected"),
[
(
["First line", "Second line - Nested"],
"- First line\n- Second line\n - Nested",
),
(["Single item"], "- Single item"),
(["Item 1", "Item 2", "Item 3"], "- Item 1\n- Item 2\n- Item 3"),
(
["Parent - Child 1", "Item 2 - Nested item"],
"- Parent\n - Child 1\n- Item 2\n - Nested item",
),
],
)
def test_returns_expected_output(self, highlights, expected):
result = process_highlights(highlights)
assert result == expected
@settings(deadline=None)
@given(
highlights=st.lists(
st.text(
alphabet=st.characters(categories=("L", "N", "Zs")),
min_size=1,
max_size=30,
),
min_size=1,
max_size=10,
)
)
def test_every_item_starts_with_bullet(self, highlights: list[str]) -> None:
result = process_highlights(highlights)
assert result.startswith("- ")
@settings(deadline=None)
@given(
highlights=st.lists(
st.text(
alphabet=st.characters(categories=("L", "N", "Zs")),
min_size=1,
max_size=30,
),
min_size=1,
max_size=10,
)
)
def test_top_level_bullet_count_matches_input_length(
self, highlights: list[str]
) -> None:
result = process_highlights(highlights)
top_level_bullets = [
line for line in result.split("\n") if line.startswith("- ")
]
assert len(top_level_bullets) == len(highlights)
@pytest.mark.parametrize(
("highlights", "expected"),
[
(
["First line", "Second line - Nested"],
"- First line\n- Second line\n - Nested",
),
(["Single item"], "- Single item"),
(["Item 1", "Item 2", "Item 3"], "- Item 1\n- Item 2\n- Item 3"),
(
["Parent - Child 1", "Item 2 - Nested item"],
"- Parent\n - Child 1\n- Item 2\n - Nested item",
),
],
)
def test_process_highlights(highlights, expected):
result = process_highlights(highlights)
assert result == expected
class TestProcessAuthors:
@pytest.mark.parametrize(
("authors", "expected"),
[
(["Alice", "Bob", "Charlie"], "Alice, Bob, Charlie"),
(["Single Author"], "Single Author"),
(["A", "B"], "A, B"),
],
)
def test_returns_expected_output(self, authors, expected):
assert process_authors(authors) == expected
@settings(deadline=None)
@given(
authors=st.lists(
st.text(min_size=1, max_size=20).filter(
lambda s: "," not in s and s.strip()
),
min_size=1,
max_size=10,
)
)
def test_comma_count_is_n_minus_one(self, authors: list[str]) -> None:
result = process_authors(authors)
assert result.count(", ") == len(authors) - 1
@settings(deadline=None)
@given(
authors=st.lists(
st.text(min_size=1, max_size=20).filter(lambda s: s.strip()),
min_size=1,
max_size=10,
)
)
def test_all_authors_appear_in_output(self, authors: list[str]) -> None:
result = process_authors(authors)
for author in authors:
assert author in result
@pytest.mark.parametrize(
("authors", "expected"),
[
(["Alice", "Bob", "Charlie"], "Alice, Bob, Charlie"),
(["Single Author"], "Single Author"),
(["A", "B"], "A, B"),
],
)
def test_process_authors(authors, expected):
assert process_authors(authors) == expected
class TestProcessDate:

View File

@@ -1,6 +1,4 @@
import pytest
from hypothesis import given, settings
from hypothesis import strategies as st
from rendercv.schema.models.cv.entries.publication import PublicationEntry
@@ -17,9 +15,3 @@ class TestPublicationEntry:
publication_entry["doi"] = doi
publication_entry = PublicationEntry(**publication_entry)
assert publication_entry.doi_url == expected_doi_url
@settings(deadline=None)
@given(doi=st.from_regex(r"10\.\d{4,9}/[a-zA-Z0-9._-]+", fullmatch=True))
def test_doi_url_always_produces_valid_url(self, doi: str) -> None:
entry = PublicationEntry(title="Paper", authors=["Author"], doi=doi)
assert entry.doi_url == f"https://doi.org/{doi}"