[MERGE] Before actually using encoding need to check that Python has corresponding codec (v.2)

John Arbash Meinel john at arbash-meinel.com
Tue Jan 2 17:24:19 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aaron Bentley wrote:
> Alexander Belchenko wrote:

...

>> Yes, I did. I copy approach of John Meinel from TestTerminalEncoding
>> where instead of self.tearDown() method is used
>> self.addCleanup(self._reset).
> 
> Ah.  I missed it because I looked at the wrong _reset.
> 
>> I should admit that I don't completely understand difference between
>> .tearDown and ._reset, but I think it's related to problems with
>> test cleanup when error in test raised.
> 
> We use addCleanup rather than extending tearDown, but I don't remember
> the rationale.  _reset isn't a special name, it's the use of addCleanup
> that makes it special.
> 


We use addCleanup because if you override tearDown() it is easy to
forget to call the super classes tearDown() and then the test stops
cleaning up after itself. You notice if setUp() isn't called, because
then the test fails, but if you forget tearDown(), then it just doesn't
clean up log files, etc.

This was actually Martin's recommendation.

As far as 'self._reset()' goes, I usually create a local function
something like:

foo = self.create_foo()
def cleanup():
  # do cleanup here
  foo.reset()

self.addCleanup(cleanup)

I've called it reset() or cleanup().

In this case, I think I'm using a member function because I'm using
member variables to save the original state. I think we could just as
easily do:

orig_stdin = sys.stdin
...

def cleanup():
  sys.stdin = orig_stdin

self.addCleanup(cleanup)

I'm not sure which is more obvious, but I kind of like the local
function because it keeps everything together.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFmpVDJdeBCYSNAAMRAtdpAJ4zwSv3IbKh/sUhyMwlD+enOHo5KwCfY4cV
7DpwbebFdMRcP5xnpZAswhk=
=iQKS
-----END PGP SIGNATURE-----




More information about the bazaar mailing list