# Path: bankcsvtoqif/io.py
# class DataManager(object):
#     """ Main class to interact with the user. """
# 
#     def __init__(self, args):
# 
#         self.account_config = bank_dict[args.type]()
#         if args.source_account:
#             self.account_config.default_source_account = args.source_account
#         if args.target_account:
#             self.account_config.default_target_account = args.target_account
#         self.type = args.type
#         self.csv_filename = args.csv_file
#         self.qif_filename = args.qif_file if args.qif_file else args.csv_file[:-3] + 'qif'
#         self.replacements_file = args.replacements
#         self.messenger = Messenger(args.v)
#         self.transactions = []
# 
#     def read_csv(self, f):
#         self.messenger.send_message("Parsing csv-file from" + self.csv_filename + "...", preblanks=1)
#         transaction_factory = TransactionFactory(self.account_config)
#         self.transactions = transaction_factory.read_from_file(f, self.messenger)
# 
#     def relabel_transactions(self, f):
#         self.messenger.send_message("Conducting automatic replacements using " + self.replacements_file + "...", preblanks=1)
#         smart_labeler = SmartLabeler()
#         smart_labeler.load_replacements_from_file(f, self.type)
#         smart_labeler.run_replacements(self.transactions, self.messenger)
# 
#     def write_qif(self, f):
#         self.messenger.send_message("Writing qif-file to " + self.qif_filename + "...", preblanks=1)
#         q = QifFile(self.transactions)
#         f.write('\n'.join(q.get_raw_data()))
# 
#     def print_transactions(self):
#         self.messenger.send_message("Finished! Qif contains the following transactions:", preblanks=1)
#         for transaction in self.transactions:
#             self.messenger.send_message(transaction)
# 
#     def csv_to_qif(self):
#         try:
#             f = open(self.csv_filename, encoding=self.account_config.encoding)
#         except AttributeError:
#             f = open(self.csv_filename)
#         self.read_csv(f)
#         f.close()
#         if self.replacements_file:
#             f = open(self.replacements_file)
#             self.relabel_transactions(f)
#             f.close()
#         f = open(self.qif_filename, 'w')
#         self.write_qif(f)
#         f.close()
#         self.print_transactions()
# 
# Path: bankcsvtoqif/banks/db_giro.py
# class DBGiro(BankAccountConfig):
#     """ Deutsche Bank Girokonto """
# 
#     def __init__(self):
#         BankAccountConfig.__init__(self)
# 
#         self.delimiter = ';'
#         self.quotechar = '"'
#         self.dropped_lines = 5
#         self.default_source_account = 'Assets:Current Assets:Checking Account'
#         self.default_target_account = 'Imbalance-EUR'
# 
#     def get_date(self, line):
#         s = line[0].split('.')
#         return datetime(int(s[2]), int(s[1]), int(s[0]))
# 
#     def get_description(self, line):
#         description = line[2] + ' ' + line[3] + ' ' + line[4]
#         return ' '.join(description.split())
# 
#     def get_debit(self, line):
#         return self.get_absolute_amount(line[14])
# 
#     def get_credit(self, line):
#         return self.get_absolute_amount(line[15])
# 
# Path: bankcsvtoqif/transaction.py
# class Transaction(object):
#     """ Represents a transaction obtained from csv-file. """
# 
#     def __init__(self, date, description, debit, credit, target_account, source_account='Assets:Current Assets:Checking Account'):
#         self.date = date
#         self.description = description
#         self.debit = debit
#         self.credit = credit
#         self.target_account = target_account
#         self.source_account = source_account
# 
#     def __str__(self):
#         return '<Transaction %s, %s, %s, %s, %s>'% (
#             self.date,
#             self.description,
#             self.debit,
#             self.credit,
#             self.target_account
#         )
# 
#     @property
#     def amount(self):
#         return self.credit - self.debit
# 
#     def to_qif_line(self):
#         return [
#             '!Type:Cash',
#             'D' + self.date.strftime('%m/%d/%y'),
#             'S' + self.target_account,
#             'P' + self.description,
#             '$' + '%.2f' % self.amount,
#             '^'
#         ]


    from StringIO import StringIO
    from io import StringIO
from datetime import datetime
from bankcsvtoqif.io import DataManager
from bankcsvtoqif.banks.db_giro import DBGiro
from bankcsvtoqif.transaction import Transaction
import unittest
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

try:
except ImportError:




class MockArgs(object):

    def __init__(self):
        self.type = None
        self.csv_file = ''
        self.qif_file = ''
        self.source_account = 'Assets:Current Assets:Checking Account'
        self.target_account = 'Imbalance-EUR'
        self.replacements = None
        self.v = False
        self.type = 'db_giro'


class TestDataManager(unittest.TestCase):

    def test_create_data_manager(self):
        d = DataManager(MockArgs())
        self.assertEqual(len(d.transactions), 0)

    def test_read_csv(self):

# Path: bankcsvtoqif/io.py
# class DataManager(object):
#     """ Main class to interact with the user. """
# 
#     def __init__(self, args):
# 
#         self.account_config = bank_dict[args.type]()
#         if args.source_account:
#             self.account_config.default_source_account = args.source_account
#         if args.target_account:
#             self.account_config.default_target_account = args.target_account
#         self.type = args.type
#         self.csv_filename = args.csv_file
#         self.qif_filename = args.qif_file if args.qif_file else args.csv_file[:-3] + 'qif'
#         self.replacements_file = args.replacements
#         self.messenger = Messenger(args.v)
#         self.transactions = []
# 
#     def read_csv(self, f):
#         self.messenger.send_message("Parsing csv-file from" + self.csv_filename + "...", preblanks=1)
#         transaction_factory = TransactionFactory(self.account_config)
#         self.transactions = transaction_factory.read_from_file(f, self.messenger)
# 
#     def relabel_transactions(self, f):
#         self.messenger.send_message("Conducting automatic replacements using " + self.replacements_file + "...", preblanks=1)
#         smart_labeler = SmartLabeler()
#         smart_labeler.load_replacements_from_file(f, self.type)
#         smart_labeler.run_replacements(self.transactions, self.messenger)
# 
#     def write_qif(self, f):
#         self.messenger.send_message("Writing qif-file to " + self.qif_filename + "...", preblanks=1)
#         q = QifFile(self.transactions)
#         f.write('\n'.join(q.get_raw_data()))
# 
#     def print_transactions(self):
#         self.messenger.send_message("Finished! Qif contains the following transactions:", preblanks=1)
#         for transaction in self.transactions:
#             self.messenger.send_message(transaction)
# 
#     def csv_to_qif(self):
#         try:
#             f = open(self.csv_filename, encoding=self.account_config.encoding)
#         except AttributeError:
#             f = open(self.csv_filename)
#         self.read_csv(f)
#         f.close()
#         if self.replacements_file:
#             f = open(self.replacements_file)
#             self.relabel_transactions(f)
#             f.close()
#         f = open(self.qif_filename, 'w')
#         self.write_qif(f)
#         f.close()
#         self.print_transactions()
# 
# Path: bankcsvtoqif/banks/db_giro.py
# class DBGiro(BankAccountConfig):
#     """ Deutsche Bank Girokonto """
# 
#     def __init__(self):
#         BankAccountConfig.__init__(self)
# 
#         self.delimiter = ';'
#         self.quotechar = '"'
#         self.dropped_lines = 5
#         self.default_source_account = 'Assets:Current Assets:Checking Account'
#         self.default_target_account = 'Imbalance-EUR'
# 
#     def get_date(self, line):
#         s = line[0].split('.')
#         return datetime(int(s[2]), int(s[1]), int(s[0]))
# 
#     def get_description(self, line):
#         description = line[2] + ' ' + line[3] + ' ' + line[4]
#         return ' '.join(description.split())
# 
#     def get_debit(self, line):
#         return self.get_absolute_amount(line[14])
# 
#     def get_credit(self, line):
#         return self.get_absolute_amount(line[15])
# 
# Path: bankcsvtoqif/transaction.py
# class Transaction(object):
#     """ Represents a transaction obtained from csv-file. """
# 
#     def __init__(self, date, description, debit, credit, target_account, source_account='Assets:Current Assets:Checking Account'):
#         self.date = date
#         self.description = description
#         self.debit = debit
#         self.credit = credit
#         self.target_account = target_account
#         self.source_account = source_account
# 
#     def __str__(self):
#         return '<Transaction %s, %s, %s, %s, %s>'% (
#             self.date,
#             self.description,
#             self.debit,
#             self.credit,
#             self.target_account
#         )
# 
#     @property
#     def amount(self):
#         return self.credit - self.debit
# 
#     def to_qif_line(self):
#         return [
#             '!Type:Cash',
#             'D' + self.date.strftime('%m/%d/%y'),
#             'S' + self.target_account,
#             'P' + self.description,
#             '$' + '%.2f' % self.amount,
#             '^'
#         ]


# Path: bankcsvtoqif/tests/test_io.py
    from StringIO import StringIO
    from io import StringIO
from datetime import datetime
from bankcsvtoqif.io import DataManager
from bankcsvtoqif.banks.db_giro import DBGiro
from bankcsvtoqif.transaction import Transaction
import unittest

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

try:
except ImportError:




class MockArgs(object):

    def __init__(self):
        self.type = None
        self.csv_file = ''
        self.qif_file = ''
        self.source_account = 'Assets:Current Assets:Checking Account'
        self.target_account = 'Imbalance-EUR'
        self.replacements = None
        self.v = False
        self.type = 'db_giro'


class TestDataManager(unittest.TestCase):

    def test_create_data_manager(self):
        d = DataManager(MockArgs())
        self.assertEqual(len(d.transactions), 0)

    def test_read_csv(self):

        d = DataManager(MockArgs())