# 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
        f"{the_date} bananas unlimited\n"
        "    e: misc\n"
        "    l: credit card                     $-50\n\n"
    )


def test_scheduler():
    lastmonth = date.today() - relativedelta(months=1)
    testdate = date(lastmonth.year, lastmonth.month, 15)
    schedule = "monthly ;; every 2 months"

    schedulefiledata = get_schedule_file(util.get_date_string(testdate), schedule)
    with FT.temp_file(schedulefiledata) as tempschedulefile:
        with FT.temp_file("") as templedgerfile:
            ledgerbil.main(["--file", templedgerfile, "--schedule", tempschedulefile])

            schedulefile_actual = FT.read_file(tempschedulefile)
            schedulefile_expected = get_schedule_file(
                util.get_date_string(testdate + relativedelta(months=2)), schedule
            )
            assert schedulefile_actual == schedulefile_expected

            ledgerfile_actual = FT.read_file(templedgerfile)
            ledgerfile_expected = get_ledger_file(util.get_date_string(testdate))
            assert ledgerfile_actual == ledgerfile_expected


class Scheduler(Redirector):
    @mock.patch(__name__ + ".ledgerbil.LedgerFile")
    def test_next_scheduled_date(self, mock_ledgerfile):

# 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

        f"{the_date} bananas unlimited\n"
        "    e: misc\n"
        "    l: credit card                     $-50\n\n"
    )


def test_scheduler():
    lastmonth = date.today() - relativedelta(months=1)
    testdate = date(lastmonth.year, lastmonth.month, 15)
    schedule = "monthly ;; every 2 months"

    schedulefiledata = get_schedule_file(util.get_date_string(testdate), schedule)
    with FT.temp_file(schedulefiledata) as tempschedulefile:
        with FT.temp_file("") as templedgerfile:
            ledgerbil.main(["--file", templedgerfile, "--schedule", tempschedulefile])

            schedulefile_actual = FT.read_file(tempschedulefile)
            schedulefile_expected = get_schedule_file(
                util.get_date_string(testdate + relativedelta(months=2)), schedule
            )
            assert schedulefile_actual == schedulefile_expected

            ledgerfile_actual = FT.read_file(templedgerfile)
            ledgerfile_expected = get_ledger_file(util.get_date_string(testdate))
            assert ledgerfile_actual == ledgerfile_expected


class Scheduler(Redirector):
    @mock.patch(__name__ + ".ledgerbil.LedgerFile")
    def test_next_scheduled_date(self, mock_ledgerfile):

        with FT.temp_file(schedule_testdata) as tempfile: