Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Tim Chase Newsgroups: comp.lang.python Subject: Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Date: Thu, 24 Dec 2015 14:48:53 -0600 Lines: 44 Message-ID: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <1e0feecd-6292-406d-ac27-d32742a4023a@googlegroups.com> <8297515b-834b-4829-abb4-0191a66222bb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de tE6bLVf19nZDyujY6ouUaAs9umMMoik/6f5dmgqu5l9g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'failing': 0.05; 'test,': 0.05; 'amount:': 0.07; 'none)': 0.07; 'tests,': 0.07; 'subject:help': 0.07; 'raised.': 0.09; 'def': 0.13; 'subject: \n ': 0.15; '"invalid': 0.16; '-tkc': 0.16; '23,': 0.16; 'ah,': 0.16; 'friendlier': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'transaction"': 0.16; 'wrote:': 0.16; 'subject:project': 0.18; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'figure': 0.27; 'error': 0.27; 'checking': 0.27; 'function': 0.28; 'interface': 0.29; 'prints': 0.29; 'code': 0.30; "i'd": 0.31; 'says': 0.32; 'returned': 0.32; 'expected': 0.35; 'sometimes': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'guidance': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'method': 0.37; 'thought': 0.37; 'charset:us- ascii': 0.37; 'skip:s 40': 0.38; 'test': 0.39; 'subject:the': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'some': 0.40; 'your': 0.60; "you'll": 0.61; 'subject:Need': 0.61; 'email addr:gmail.com': 0.62; 'together,': 0.84; 'received:108': 0.93 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1450990257484:3016440845 X-MC-Ingress-Time: 1450990257483 In-Reply-To: X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100830 On 2015-12-24 11:36, malitician@gmail.com wrote: > it is a homework, but we are to figure out the solution first , all > we need is some guidance please and not to be spoon fed like many > thought Ah, with the intended interface as given by the tests, and the code you've already put together, you'll find comp.lang.python is a much friendlier place. > def test_invalid_operation(self): > self.assertEqual(self.my_account.withdraw(1000), "invalid > transaction", msg='Invalid transaction') The test above is failing because your withdraw() method doesn't return "invalid transaction" but rather prints it: > def withdraw(self, amount): > if self.balance>= amount: > self.balance -= amount > else: > print('invalid transaction') as gleaned from this error message: > [{"message": "Failure in line 23, in test_invalid_operation\n > self.assertEqual(self.my_account.withdraw(1000), \"invalid > transaction\", msg='Invalid transaction')\nAssertionError: Invalid > transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, > "time": "0.000080"}} The test says "I expected that calling the function would return "invalid transaction" but it didn't" (a better test-runner would also have let you know that it had returned None) Though frankly, I'd consider that a bad test, since it's an exceptional condition, so it should be checking that a custom InvalidTransactionException was raised. But sometimes you have to work with what you've got. -tkc