# 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

    class MockSettings:
        DATE_FORMAT = "%Y-%m-%d"

    settings_getter.settings = MockSettings()
    expected = FT.read_file(FT.alpha_unsortedfile)
    with FT.temp_file(expected) as templedgerfile:
        ledgerbil.main(["--file", templedgerfile, "--sort"])
        actual = FT.read_file(templedgerfile)

    assert actual == expected
    settings_getter.settings = settings.Settings()


@mock.patch(__name__ + ".ledgerbil.LedgerFile.write_file")
@mock.patch(__name__ + ".ledgerbil.LedgerFile.sort")
@mock.patch(__name__ + ".ledgerbil.LedgerFile.__init__")
def test_sorting_multiple_files(mock_init, mock_sort, mock_write_file):
    mock_init.return_value = None
    with FT.temp_file("; no data 1") as file1:
        with FT.temp_file("; no data 2") as file2:
            ledgerbil.main(["--file", file1, "--file", file2, "--sort"])

    assert mock_init.call_args_list == [mock.call(file1, None), mock.call(file2, None)]
    # It would be nice to be able to further confirm that each instance
    # of Ledgerfile called these methods
    assert mock_sort.call_args_list == [mock.call(), mock.call()]
    assert mock_write_file.call_args_list == [mock.call(), mock.call()]



# 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


    class MockSettings:
        DATE_FORMAT = "%Y-%m-%d"

    settings_getter.settings = MockSettings()
    expected = FT.read_file(FT.alpha_unsortedfile)
    with FT.temp_file(expected) as templedgerfile:
        ledgerbil.main(["--file", templedgerfile, "--sort"])
        actual = FT.read_file(templedgerfile)

    assert actual == expected
    settings_getter.settings = settings.Settings()


@mock.patch(__name__ + ".ledgerbil.LedgerFile.write_file")
@mock.patch(__name__ + ".ledgerbil.LedgerFile.sort")
@mock.patch(__name__ + ".ledgerbil.LedgerFile.__init__")
def test_sorting_multiple_files(mock_init, mock_sort, mock_write_file):
    mock_init.return_value = None
    with FT.temp_file("; no data 1") as file1:
        with FT.temp_file("; no data 2") as file2:
            ledgerbil.main(["--file", file1, "--file", file2, "--sort"])

    assert mock_init.call_args_list == [mock.call(file1, None), mock.call(file2, None)]
    # It would be nice to be able to further confirm that each instance
    # of Ledgerfile called these methods
    assert mock_sort.call_args_list == [mock.call(), mock.call()]
    assert mock_write_file.call_args_list == [mock.call(), mock.call()]



class MainErrors(Redirector):