File size: 3,007 Bytes
532111b be97847 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | """The ATS score is computed in Python, so it is fully testable without an API."""
import re
import pytest
from ats import ATSAnalysis, MatchedKeyword, MissingKeyword, PriorityFix, format_ats_report
def analysis(matched=0, missing=0, fixes=()):
return ATSAnalysis(
matched=[MatchedKeyword(keyword=f"K{i}", evidence=f"project {i}") for i in range(matched)],
missing=[MissingKeyword(keyword=f"M{i}", closest="no adjacent experience") for i in range(missing)],
priority_fixes=list(fixes),
)
def score_of(report):
return int(re.search(r"ATS score: (\d+)%", report).group(1))
@pytest.mark.parametrize(
"matched,missing,expected",
[(15, 8, 65), (10, 0, 100), (0, 10, 0), (1, 2, 33), (2, 1, 67), (7, 7, 50), (1, 1, 50)],
)
def test_score_is_matched_over_total(matched, missing, expected):
assert score_of(format_ats_report(analysis(matched, missing))) == expected
@pytest.mark.parametrize("matched,missing", [(15, 8), (3, 9), (0, 4), (6, 0)])
def test_score_always_agrees_with_the_rendered_lists(matched, missing):
"""The regression this design exists to prevent: score disagreeing with its own lists."""
report = format_ats_report(analysis(matched, missing))
listed_matched = len(re.findall(r"^\d+\. \*\*K", report, re.M))
listed_missing = len(re.findall(r"^\d+\. \*\*M", report, re.M))
total = listed_matched + listed_missing
assert listed_matched == matched
assert listed_missing == missing
assert score_of(report) == round(100 * listed_matched / total)
def test_empty_analysis_does_not_divide_by_zero():
report = format_ats_report(analysis(0, 0))
assert "No keywords" in report
assert "%" not in report
def test_counts_appear_in_headings_and_summary():
report = format_ats_report(analysis(4, 6))
assert "## Matched keywords (4)" in report
assert "## Missing keywords (6)" in report
assert "**4 of 10**" in report
def test_priority_fixes_distinguish_honest_from_must_learn():
fixes = [
PriorityFix(keyword="SQL", can_honestly_add=True, note="surface it"),
PriorityFix(keyword="Rust", can_honestly_add=False, note="learn it"),
]
report = format_ats_report(analysis(1, 1, fixes))
assert "can surface honestly" in report
assert "requires actually learning it" in report
def test_priority_section_omitted_when_there_are_no_fixes():
assert "## Priority fixes" not in format_ats_report(analysis(2, 2))
def test_rewrites_are_rendered_before_and_after():
from ats import BulletRewrite
result = analysis(1, 1)
result.rewrites = [BulletRewrite(original="Built a pipeline", rewritten="Built a Kafka pipeline")]
report = format_ats_report(result)
assert "## Suggested rewrites" in report
assert "**Before:** Built a pipeline" in report
assert "**After:** Built a Kafka pipeline" in report
def test_rewrites_section_omitted_when_there_are_none():
assert "## Suggested rewrites" not in format_ats_report(analysis(2, 2))
|