コード例 #1
0
def load_account_from_csv(filename):
    """ Read an account from a CSV file
    """
    dt = [('Date', "S10"), ('Action', 'S9'), ('Amount', 'S6'),
          ('Balance', 'S6'), ('comment', 'S24'), ('f1', '<f8'), ('f2', '<f8')]
    data = genfromtxt(filename,
                      dtype=dt,
                      comments="#",
                      delimiter="\t",
                      skip_header=1)
    transactions = []
    for trans in data:
        mm, dd, yy = trans["Date"].split("/")
        if trans["Action"].lower().startswith("withdraw"):
            kind = "withdrawal"
        elif trans["Action"].lower().startswith("allow"):
            kind = "allowance"
        elif trans["Action"].lower().startswith("inter"):
            kind = "interest"
        elif trans["Action"].lower().startswith("dep"):
            kind = "deposit"
        transactions.append(
            Transaction(
                time_stamp=date(int(yy), int(mm), int(dd)),
                amount=float(trans["Amount"].replace("$", "")),
                kind=kind,
                comment=str(trans["comment"]),
            ))
    account = Account(transactions=transactions, )
    return account
コード例 #2
0
ファイル: test_account.py プロジェクト: ERAnderson/bankofdad
 def setUp(self):
     self.person = Person(
         name="4 yr old",
         DOB=date.today() - timedelta(365 * 4 + 2),
     )
     self.account = Account(
         owner=self.person
     )
コード例 #3
0
ファイル: test_account.py プロジェクト: ERAnderson/bankofdad
class TestAccount(unittest.TestCase):
    """ test the bank of dad.
    """
    def setUp(self):
        self.person = Person(
            name="4 yr old",
            DOB=date.today() - timedelta(365 * 4 + 2),
        )
        self.account = Account(
            owner=self.person
        )

    def test_empty_account_balance(self):
        "test an ampty account class"
        self.assertEqual(self.account.balance, 0.0,
                         "An empty account should have a zero balance.")

    def test_adding_a_deposit(self):
        deposit_amount = 1.0
        self.account.make_deposit(deposit_amount)
        self.assertEqual(self.account.balance, deposit_amount)
        self.account.make_deposit(100)
        self.assertEqual(self.account.balance, 101)

    def test_apply_allowance(self):
        self.account.apply_allowance(date.today())
        self.assertEqual(self.account.balance, self.person.age / 2)

    def test_apply_interest(self):
        deposit_amount = 100.
        self.account.make_deposit(deposit_amount)
        self.account.apply_interest(date.today())
        self.assertEqual(self.account.balance,
                         deposit_amount * (1 + savings_interest_rate))

    def test_deposit_withdraw(self):
        self.account.make_deposit(100)
        self.assertEqual(self.account.balance, 100)
        self.account.make_withdrawal(100)
        self.assertEqual(self.account.balance, 0)
コード例 #4
0
ファイル: __main__.py プロジェクト: ERAnderson/bankofdad
def main():
    account = Account()
    account.configure_traits()
コード例 #5
0
ファイル: test_account.py プロジェクト: ERAnderson/bankofdad
class TestAccount(unittest.TestCase):
    """ test the bank of dad.
    """
    def setUp(self):
        self.person = Person(
            name="4 yr old",
            DOB=date.today() - timedelta(365 * 4 + 2),
        )
        self.account = Account(owner=self.person)

    def test_empty_account_balance(self):
        "test an ampty account class"
        self.assertEqual(self.account.balance, 0.0,
                         "An empty account should have a zero balance.")

    def test_adding_a_deposit(self):
        deposit_amount = 1.0
        self.account.make_deposit(deposit_amount)
        self.assertEqual(self.account.balance, deposit_amount)
        self.account.make_deposit(100)
        self.assertEqual(self.account.balance, 101)

    def test_apply_allowance(self):
        self.account.apply_allowance(date.today())
        self.assertEqual(self.account.balance, self.person.age / 2)

    def test_apply_interest(self):
        deposit_amount = 100.
        self.account.make_deposit(deposit_amount)
        self.account.apply_interest(date.today())
        self.assertEqual(self.account.balance,
                         deposit_amount * (1 + savings_interest_rate))

    def test_deposit_withdraw(self):
        self.account.make_deposit(100)
        self.assertEqual(self.account.balance, 100)
        self.account.make_withdrawal(100)
        self.assertEqual(self.account.balance, 0)
コード例 #6
0
ファイル: test_account.py プロジェクト: ERAnderson/bankofdad
 def setUp(self):
     self.person = Person(
         name="4 yr old",
         DOB=date.today() - timedelta(365 * 4 + 2),
     )
     self.account = Account(owner=self.person)