test: add us-cpa module coverage and citations

This commit is contained in:
Stefano Fiorini
2026-03-15 03:11:24 -05:00
parent fb39fe76cb
commit 1be0317192
5 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from us_cpa.document_extractors import extract_document_facts
class DocumentExtractorTests(unittest.TestCase):
def test_extracts_common_w2_fields(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir) / "w2.txt"
path.write_text(
"Form W-2 Wage and Tax Statement\n"
"Employee: Jane Doe\n"
"Box 1 Wages, tips, other compensation 50000\n"
"Box 2 Federal income tax withheld 6000\n"
"Box 16 State wages, tips, etc. 50000\n"
"Box 17 State income tax 1200\n"
"Box 3 Social security wages 50000\n"
"Box 5 Medicare wages and tips 50000\n"
)
extracted = extract_document_facts(path)
self.assertEqual(extracted["taxpayer.fullName"], "Jane Doe")
self.assertEqual(extracted["wages"], 50000.0)
self.assertEqual(extracted["federalWithholding"], 6000.0)
self.assertEqual(extracted["stateWages"], 50000.0)
self.assertEqual(extracted["stateWithholding"], 1200.0)
self.assertEqual(extracted["socialSecurityWages"], 50000.0)
self.assertEqual(extracted["medicareWages"], 50000.0)
def test_extracts_common_1099_patterns(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
div_path = Path(temp_dir) / "1099-div.txt"
div_path.write_text("Form 1099-DIV\nRecipient: Jane Doe\nBox 1a Total ordinary dividends 250\n")
ret_path = Path(temp_dir) / "1099-r.txt"
ret_path.write_text("Form 1099-R\nRecipient: Jane Doe\nBox 1 Gross distribution 10000\n")
misc_path = Path(temp_dir) / "1099-misc.txt"
misc_path.write_text("Form 1099-MISC\nRecipient: Jane Doe\nBox 3 Other income 900\n")
self.assertEqual(extract_document_facts(div_path)["ordinaryDividends"], 250.0)
self.assertEqual(extract_document_facts(ret_path)["retirementDistribution"], 10000.0)
self.assertEqual(extract_document_facts(misc_path)["otherIncome"], 900.0)
def test_extracts_prior_year_return_summary_values(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir) / "prior-return.txt"
path.write_text(
"2024 Form 1040 Summary\n"
"Adjusted gross income 72100\n"
"Taxable income 49800\n"
"Refund 2100\n"
)
extracted = extract_document_facts(path)
self.assertEqual(extracted["priorYear.adjustedGrossIncome"], 72100.0)
self.assertEqual(extracted["priorYear.taxableIncome"], 49800.0)
self.assertEqual(extracted["priorYear.refund"], 2100.0)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,25 @@
from __future__ import annotations
import unittest
from us_cpa.tax_years import supported_tax_years, tax_year_rules
class TaxYearRuleTests(unittest.TestCase):
def test_supported_years_are_listed(self) -> None:
self.assertEqual(supported_tax_years(), [2024, 2025])
def test_tax_year_rules_include_source_citations(self) -> None:
rules = tax_year_rules(2025)
self.assertIn("sourceCitations", rules)
self.assertIn("standardDeduction", rules["sourceCitations"])
self.assertIn("ordinaryIncomeBrackets", rules["sourceCitations"])
def test_unsupported_tax_year_raises_clear_error(self) -> None:
with self.assertRaisesRegex(ValueError, "Unsupported tax year 2023"):
tax_year_rules(2023)
if __name__ == "__main__":
unittest.main()