Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53621
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-09-04 05:14 -0700 |
| References | <l051gb$li5$1@dont-email.me> <mailman.17.1378242095.5461.python-list@python.org> <l06ocs$vo2$2@dont-email.me> |
| Message-ID | <148ea321-c4e3-457b-bcc8-865f480c80b6@googlegroups.com> (permalink) |
| Subject | Re: to be pythonic: should caller or callee log? |
| From | Xaxa Urtiz <urtizvereaxaxa@gmail.com> |
Le mercredi 4 septembre 2013 09:44:27 UTC+2, Gildor Oronar a écrit :
> Thanks:
>
>
>
> El 04/09/13 05:01, Terry Reedy escribió:
>
>
>
> > I would expect that every account class has a transaction method.
>
> > * If so, just call it, but
>
> > assertIsNot(DebitAccount.transaction, AbstractAccount.transaction)
>
> > for every subclass in your test suite.
>
> > * If not, perhaps you need an abstract subclass TransAccount. Then use
>
> > hasattr in production code and the isnot test in test code.
>
>
>
> I would assume that you categorize this as a unit test problem, because
>
> you consider an Acount not implementing Transaction is a bug, right?
>
>
>
> There are two occassions an account is intended not having Transaction
>
> function, both not test-related:
>
>
>
> 1. The acount doesn't offer this feature. e.g. Certificate of Deposit.
>
> This can be in TransAccount.
>
>
>
> 2. The 3rd-party account offer this feature but doesn't qualify the
>
> software's requirement, e.g. not returning the result in 3 seconds, and
>
> is avoided when planning the deal (I am writing an auto-trade software).
>
> This case you cannot categorize those who can into TransAccount,
>
> beacause 1) that naming imply other accounts don't do transaction but
>
> they do, just not good enough; 2) when other accounts becomes good
>
> enough, the change (to inheritance) is a bit too invasive.
Hello,
and what about something like that :
class AbsctractAccount():
def transaction(self, amount, target):
logging.info("Start transaction of %s to %s" % (amount, target))
self.DoTransaction(amount,target)
def DoTransaction(self,amount,target):
pass # or raise notimplemented or do not implement this methods in the abstract class
...
class DebitAccount(AbstractAccount):
def DoTransaction(self, amount, target):
...
class SomeOtherAccount(...)
....
like that you only have to write the logging function once.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-04 00:07 +0800
Re: to be pythonic: should caller or callee log? Terry Reedy <tjreedy@udel.edu> - 2013-09-03 17:01 -0400
Re: to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-04 15:44 +0800
Re: to be pythonic: should caller or callee log? Xaxa Urtiz <urtizvereaxaxa@gmail.com> - 2013-09-04 05:14 -0700
Re: to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-06 23:05 +0800
Re: to be pythonic: should caller or callee log? Ethan Furman <ethan@stoneleaf.us> - 2013-09-03 19:26 -0700
Re: to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-04 15:44 +0800
csiph-web