Merge lp:~flimm/wxbanker/none-bugfix into lp:wxbanker

Proposed by David D Lowe
Status: Merged
Approved by: Michael Rooney
Approved revision: 828
Merged at revision: 833
Proposed branch: lp:~flimm/wxbanker/none-bugfix
Merge into: lp:wxbanker
Diff against target: 55 lines (+19/-3)
2 files modified
wxbanker/bankobjects/account.py (+4/-3)
wxbanker/tests/modeltests.py (+15/-0)
To merge this branch: bzr merge lp:~flimm/wxbanker/none-bugfix
Reviewer Review Type Date Requested Status
Michael Rooney Approve
Review via email: mp+63147@code.launchpad.net

This proposal supersedes a proposal from 2010-10-02.

To post a comment you must log in.
Revision history for this message
Michael Rooney (mrooney) wrote : Posted in a previous version of this proposal

This is pretty reasonable, though I'm worried about what is causing it in the first place, as I'd not like to ignore that. However, it still seems fine to defend against. Instead of the ternary though, it is probably best to just use a simple expression like "self.Currency = currency or 0" for each.

I will happily merge this if you wouldn't mind just:
 * switching them to just using 'or'
 * add a comment above briefly mentioning why (to defend against None) and mentioned the LP #
 * add a simple test in tests/modeltests.py that creates an account by passing None as currency and balance and makes sure the object ends up with 0 and 0.0

Let me know if you need any tips or help! The comment will make it clear to anyone else looking at it later why the logic is there, and the test will make sure there isn't a regression later. It probably isn't obvious enough how to run the tests, but from the root run "python -m wxbanker/runtests". To test you won't be able to just model.CreateAccount, but instead import Account from wxbanker.bankobjects and directly instantiate.

review: Needs Fixing
Revision history for this message
Michael Rooney (mrooney) wrote : Posted in a previous version of this proposal

PS I see you've added my Jabber so feel free to IM there as I'm usually available and IM is often good for discussion back and forth.

Revision history for this message
Michael Rooney (mrooney) wrote :

Sorry for the delay, looks great, I'll merge this in now :]

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'wxbanker/bankobjects/account.py'
2--- wxbanker/bankobjects/account.py 2010-08-09 00:31:45 +0000
3+++ wxbanker/bankobjects/account.py 2011-06-01 17:56:28 +0000
4@@ -41,8 +41,9 @@
5 self._Transactions = None
6 self._RecurringTransactions = []
7 self._preTransactions = []
8- self.Currency = currency
9- self.Balance = balance
10+ # Make sure that Currency and Balance are not None (bug #653716)
11+ self.Currency = currency or 0
12+ self.Balance = balance or 0.0
13 self.MintId = mintId
14 self.IsFrozen = False
15
16@@ -350,4 +351,4 @@
17 RecurringTransactions = property(GetRecurringTransactions)
18 Currency = property(GetCurrency, SetCurrency)
19 MintId = property(GetMintId, SetMintId)
20- CurrentBalance = property(GetCurrentBalance)
21\ No newline at end of file
22+ CurrentBalance = property(GetCurrentBalance)
23
24=== modified file 'wxbanker/tests/modeltests.py'
25--- wxbanker/tests/modeltests.py 2010-08-09 00:31:45 +0000
26+++ wxbanker/tests/modeltests.py 2011-06-01 17:56:28 +0000
27@@ -22,6 +22,7 @@
28 import os, datetime, unittest
29 from wxbanker import controller, bankexceptions, currencies
30 from wx.lib.pubsub import Publisher
31+from wxbanker.bankobjects.account import Account
32
33 from wxbanker.tests.testbase import today, yesterday, tomorrow
34
35@@ -541,6 +542,20 @@
36 self.assertEqual(a.Balance, 2)
37 self.assertEqual(a.CurrentBalance, 1)
38
39+ def testAccountBalanceAndCurrencyNotNone(self):
40+ model = self.Model
41+ accounts = [
42+ Account(model, None, "Foo"),
43+ Account(model, None, "Bar", currency=None),
44+ Account(model, None, "Food", balance=None),
45+ Account(model, None, "Pub", currency=None, balance=None)
46+ ]
47+
48+ for account in accounts:
49+ self.assertEqual(account.Currency, currencies.CurrencyList[0]())
50+ self.assertEqual(account.Balance, 0.0)
51+ self.assertTrue(type(account.Balance) is float)
52+
53
54
55 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches

to all changes: