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
=== modified file 'wxbanker/bankobjects/account.py'
--- wxbanker/bankobjects/account.py 2010-08-09 00:31:45 +0000
+++ wxbanker/bankobjects/account.py 2011-06-01 17:56:28 +0000
@@ -41,8 +41,9 @@
41 self._Transactions = None41 self._Transactions = None
42 self._RecurringTransactions = []42 self._RecurringTransactions = []
43 self._preTransactions = []43 self._preTransactions = []
44 self.Currency = currency44 # Make sure that Currency and Balance are not None (bug #653716)
45 self.Balance = balance45 self.Currency = currency or 0
46 self.Balance = balance or 0.0
46 self.MintId = mintId47 self.MintId = mintId
47 self.IsFrozen = False48 self.IsFrozen = False
4849
@@ -350,4 +351,4 @@
350 RecurringTransactions = property(GetRecurringTransactions)351 RecurringTransactions = property(GetRecurringTransactions)
351 Currency = property(GetCurrency, SetCurrency)352 Currency = property(GetCurrency, SetCurrency)
352 MintId = property(GetMintId, SetMintId)353 MintId = property(GetMintId, SetMintId)
353 CurrentBalance = property(GetCurrentBalance)
354\ No newline at end of file354\ No newline at end of file
355 CurrentBalance = property(GetCurrentBalance)
355356
=== modified file 'wxbanker/tests/modeltests.py'
--- wxbanker/tests/modeltests.py 2010-08-09 00:31:45 +0000
+++ wxbanker/tests/modeltests.py 2011-06-01 17:56:28 +0000
@@ -22,6 +22,7 @@
22import os, datetime, unittest22import os, datetime, unittest
23from wxbanker import controller, bankexceptions, currencies23from wxbanker import controller, bankexceptions, currencies
24from wx.lib.pubsub import Publisher24from wx.lib.pubsub import Publisher
25from wxbanker.bankobjects.account import Account
2526
26from wxbanker.tests.testbase import today, yesterday, tomorrow27from wxbanker.tests.testbase import today, yesterday, tomorrow
2728
@@ -541,6 +542,20 @@
541 self.assertEqual(a.Balance, 2)542 self.assertEqual(a.Balance, 2)
542 self.assertEqual(a.CurrentBalance, 1)543 self.assertEqual(a.CurrentBalance, 1)
543 544
545 def testAccountBalanceAndCurrencyNotNone(self):
546 model = self.Model
547 accounts = [
548 Account(model, None, "Foo"),
549 Account(model, None, "Bar", currency=None),
550 Account(model, None, "Food", balance=None),
551 Account(model, None, "Pub", currency=None, balance=None)
552 ]
553
554 for account in accounts:
555 self.assertEqual(account.Currency, currencies.CurrencyList[0]())
556 self.assertEqual(account.Balance, 0.0)
557 self.assertTrue(type(account.Balance) is float)
558
544 559
545 560
546if __name__ == "__main__":561if __name__ == "__main__":

Subscribers

People subscribed via source and target branches

to all changes: