# Path: ledgerbil/ledgerbilexceptions.py
# ERROR_RETURN_VALUE = 1
# 
# Path: ledgerbil/tests/helpers.py
# class Redirector(TestCase):
#     def setUp(self):
#         self.savestdout = sys.stdout
#         self.reset_redirect()
# 
#         self.savestderr = sys.stderr
#         self.reset_err_redirect()
# 
#     def tearDown(self):
#         self.redirect.close()
#         sys.stdout = self.savestdout
# 
#         self.redirecterr.close()
#         sys.stderr = self.savestderr
# 
#     def reset_redirect(self):
#         self.redirect = StringIO()
#         sys.stdout = self.redirect
# 
#     def reset_err_redirect(self):
#         self.redirecterr = StringIO()
#         sys.stderr = self.redirecterr
# 
# Path: ledgerbil/tests/test_schedulefile.py
# def test_next_scheduled_transaction():
# def test_next_scheduled_transaction_no_next():
# def test_add_thing_with_no_lines():


from datetime import date
from textwrap import dedent
from unittest import mock
from dateutil.relativedelta import relativedelta
from ..ledgerbilexceptions import ERROR_RETURN_VALUE
from . import filetester as FT
from .helpers import Redirector
from .test_schedulefile import schedule_testdata
from .. import (  # noqa: F401 (stuff used in patches) isort:skip
    ledgerbil,
    reconciler,
    scheduler,
    settings,
    settings_getter,
    util,
)
import pytest
        """
        2017/11/28 zombie investments
            a: 401k: bonds idx            12.357 qwrty @   $20.05
            i: investment: adjustment

        2017/11/28 zombie investments
            a: 401k: bonds idx
            i: investment: adjustment     $100,000
    """
    )
    with FT.temp_file(ledgerfile_data) as tempfilename:
        ledgerbil.main(["--file", tempfilename, "--reconcile", "bonds"])
    expected = 'Unhandled shares with non-shares: "a: 401k: bonds idx"'
    mock_handle_error.assert_called_once_with(expected)


def test_reconciler_exception_return_value():
    ledgerfile_data = dedent(
        """
        2017/11/28 zombie investments
            a: 401k: bonds idx            12.357 qwrty @   $20.05
            i: investment: adjustment

        2017/11/28 zombie investments
            a: 401k: bonds idx
            i: investment: adjustment     $100,000
    """
    )
    with FT.temp_file(ledgerfile_data) as tempfilename:
        return_value = ledgerbil.main(["--file", tempfilename, "--reconcile", "bonds"])

# Path: ledgerbil/ledgerbilexceptions.py
# ERROR_RETURN_VALUE = 1
# 
# Path: ledgerbil/tests/helpers.py
# class Redirector(TestCase):
#     def setUp(self):
#         self.savestdout = sys.stdout
#         self.reset_redirect()
# 
#         self.savestderr = sys.stderr
#         self.reset_err_redirect()
# 
#     def tearDown(self):
#         self.redirect.close()
#         sys.stdout = self.savestdout
# 
#         self.redirecterr.close()
#         sys.stderr = self.savestderr
# 
#     def reset_redirect(self):
#         self.redirect = StringIO()
#         sys.stdout = self.redirect
# 
#     def reset_err_redirect(self):
#         self.redirecterr = StringIO()
#         sys.stderr = self.redirecterr
# 
# Path: ledgerbil/tests/test_schedulefile.py
# def test_next_scheduled_transaction():
# def test_next_scheduled_transaction_no_next():
# def test_add_thing_with_no_lines():


# Path: ledgerbil/tests/test_ledgerbil.py
from datetime import date
from textwrap import dedent
from unittest import mock
from dateutil.relativedelta import relativedelta
from ..ledgerbilexceptions import ERROR_RETURN_VALUE
from . import filetester as FT
from .helpers import Redirector
from .test_schedulefile import schedule_testdata
from .. import (  # noqa: F401 (stuff used in patches) isort:skip
    ledgerbil,
    reconciler,
    scheduler,
    settings,
    settings_getter,
    util,
)
import pytest

        """
        2017/11/28 zombie investments
            a: 401k: bonds idx            12.357 qwrty @   $20.05
            i: investment: adjustment

        2017/11/28 zombie investments
            a: 401k: bonds idx
            i: investment: adjustment     $100,000
    """
    )
    with FT.temp_file(ledgerfile_data) as tempfilename:
        ledgerbil.main(["--file", tempfilename, "--reconcile", "bonds"])
    expected = 'Unhandled shares with non-shares: "a: 401k: bonds idx"'
    mock_handle_error.assert_called_once_with(expected)


def test_reconciler_exception_return_value():
    ledgerfile_data = dedent(
        """
        2017/11/28 zombie investments
            a: 401k: bonds idx            12.357 qwrty @   $20.05
            i: investment: adjustment

        2017/11/28 zombie investments
            a: 401k: bonds idx
            i: investment: adjustment     $100,000
    """
    )
    with FT.temp_file(ledgerfile_data) as tempfilename:
        return_value = ledgerbil.main(["--file", tempfilename, "--reconcile", "bonds"])

    assert return_value == ERROR_RETURN_VALUE