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
def setUp(self): self.person = Person( name="4 yr old", DOB=date.today() - timedelta(365 * 4 + 2), ) self.account = Account( owner=self.person )
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)
def main(): account = Account() account.configure_traits()
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)
def setUp(self): self.person = Person( name="4 yr old", DOB=date.today() - timedelta(365 * 4 + 2), ) self.account = Account(owner=self.person)