diff --git a/tests/test_data_account.py b/tests/test_data_account.py index c7a21b2fe724786bc51f8c0fae963416b76dbc5c..d67bd67fa62974b5898cc67dfa6a58b695ecd85e 100644 --- a/tests/test_data_account.py +++ b/tests/test_data_account.py @@ -115,3 +115,93 @@ def test_is_credit_card(acct_name, expected): ]) def test_is_opening_equity(acct_name, expected): assert data.Account(acct_name).is_opening_equity() == expected + +@pytest.mark.parametrize('acct_name', [ + 'Assets:Cash', + 'Assets:Receivable:Accounts', + 'Expenses:Other', + 'Equity:Funds:Restricted', + 'Income:Other', + 'Liabilities:CreditCard', + 'Liabilities:Payable:Accounts', +]) +def test_slice_parts_no_args(acct_name): + account = data.Account(acct_name) + assert account.slice_parts() == acct_name.split(':') + +@pytest.mark.parametrize('acct_name', [ + 'Assets:Cash', + 'Assets:Receivable:Accounts', + 'Expenses:Other', + 'Equity:Funds:Restricted', + 'Income:Other', + 'Liabilities:CreditCard', + 'Liabilities:Payable:Accounts', +]) +def test_slice_parts_index(acct_name): + account = data.Account(acct_name) + parts = acct_name.split(':') + for index, expected in enumerate(parts): + assert account.slice_parts(index) == expected + with pytest.raises(IndexError): + account.slice_parts(index + 1) + +@pytest.mark.parametrize('acct_name', [ + 'Assets:Cash', + 'Assets:Receivable:Accounts', + 'Expenses:Other', + 'Equity:Funds:Restricted', + 'Income:Other', + 'Liabilities:CreditCard', + 'Liabilities:Payable:Accounts', +]) +def test_slice_parts_range(acct_name): + account = data.Account(acct_name) + parts = acct_name.split(':') + for start, stop in zip([0, 0, 1, 1], [2, 3, 2, 3]): + assert account.slice_parts(start, stop) == parts[start:stop] + +@pytest.mark.parametrize('acct_name', [ + 'Assets:Cash', + 'Assets:Receivable:Accounts', + 'Expenses:Other', + 'Equity:Funds:Restricted', + 'Income:Other', + 'Liabilities:CreditCard', + 'Liabilities:Payable:Accounts', +]) +def test_slice_parts_slice(acct_name): + account = data.Account(acct_name) + parts = acct_name.split(':') + for start, stop in zip([0, 0, 1, 1], [2, 3, 2, 3]): + sl = slice(start, stop) + assert account.slice_parts(sl) == parts[start:stop] + +@pytest.mark.parametrize('acct_name', [ + 'Assets:Cash', + 'Assets:Receivable:Accounts', + 'Expenses:Other', + 'Equity:Funds:Restricted', + 'Income:Other', + 'Liabilities:CreditCard', + 'Liabilities:Payable:Accounts', +]) +def test_count_parts(acct_name): + account = data.Account(acct_name) + assert account.count_parts() == acct_name.count(':') + 1 + +@pytest.mark.parametrize('acct_name', [ + 'Assets:Cash', + 'Assets:Receivable:Accounts', + 'Expenses:Other', + 'Equity:Funds:Restricted', + 'Income:Other', + 'Liabilities:CreditCard', + 'Liabilities:Payable:Accounts', +]) +def test_root_part(acct_name): + account = data.Account(acct_name) + parts = acct_name.split(':') + assert account.root_part() == parts[0] + assert account.root_part(1) == parts[0] + assert account.root_part(2) == ':'.join(parts[:2])