diff --git a/conservancy_beancount/reports/accrual.py b/conservancy_beancount/reports/accrual.py index 07c154f7c2287d63169291d4c777400cef3bf2a6..9c960fc739da43b7d8e3b011285e965bc1350209 100644 --- a/conservancy_beancount/reports/accrual.py +++ b/conservancy_beancount/reports/accrual.py @@ -623,13 +623,6 @@ class ReportType(enum.Enum): OUT = OUTGOING OUTGOINGS = OUTGOING - @classmethod - def by_name(cls, name: str) -> 'ReportType': - try: - return cls[name.upper()] - except KeyError: - raise ValueError(f"unknown report type {name!r}") from None - def filter_search(postings: Iterable[data.Posting], search_terms: Iterable[cliutil.SearchTerm], @@ -644,12 +637,14 @@ def parse_arguments(arglist: Optional[Sequence[str]]=None) -> argparse.Namespace parser = argparse.ArgumentParser(prog=PROGNAME) cliutil.add_version_argument(parser) cliutil.add_rewrite_rules_argument(parser) + report_type_arg = cliutil.EnumArgument(ReportType) parser.add_argument( '--report-type', '-t', metavar='NAME', - type=ReportType.by_name, - help="""The type of report to generate, one of `aging`, `balance`, or -`outgoing`. If not specified, the default is `aging` when no search terms are + type=report_type_arg.enum_type, + help=f"""The type of report to generate. +Choices are {report_type_arg.choices_str()}. +If not specified, the default is `aging` when no search terms are given, `outgoing` for search terms that return a single outstanding payable, and `balance` any other time. """) diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index ecfa8ece0e576c08bc5f8e676ed1406d83d3e0f3..2f48915603b76ecf371454f1787196a25c1e6eb6 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -242,30 +242,6 @@ def test_filter_search(accrual_postings, search_terms, expect_count, check_func) for post in actual: assert check_func(post) -@pytest.mark.parametrize('arg,expected', [ - ('aging', accrual.AgingReport), - ('balance', accrual.BalanceReport), - ('outgoing', accrual.OutgoingReport), - ('age', accrual.AgingReport), - ('bal', accrual.BalanceReport), - ('out', accrual.OutgoingReport), - ('outgoings', accrual.OutgoingReport), -]) -def test_report_type_by_name(arg, expected): - assert accrual.ReportType.by_name(arg.lower()).value is expected - assert accrual.ReportType.by_name(arg.title()).value is expected - assert accrual.ReportType.by_name(arg.upper()).value is expected - -@pytest.mark.parametrize('arg', [ - 'unknown', - 'blance', - 'outgong', -]) -def test_report_type_by_unknown_name(arg): - # Raising ValueError helps argparse generate good messages. - with pytest.raises(ValueError): - accrual.ReportType.by_name(arg) - @pytest.mark.parametrize('acct_name,invoice,day', testutil.combine_values( INVOICE_ACCOUNTS, ['FIXME', '', None, *testutil.NON_STRING_METADATA_VALUES],