[rfc] [patch] small cleanups
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 11 23:03:43 GMT 2006
Denys Duchier wrote:
> I modified the test to ony catch OSError and to raise BzrError if not weird file
> type could be created. This means that someone _will_ have to adapt the test
> for Windows.
>
>
> ------------------------------------------------------------
> revno: 1498
> committer: Denys Duchier <denys.duchier at mozart-oz.org>
> branch nick: bzr.tests
> timestamp: Wed 2006-01-11 23:53:57 +0100
> message:
> test_hashcache_raise: complain if no weird file type can be created
>
>
You could also do it in a for loop with:
ok = False
for func in (os.mkfifo, os.mknod, os.mkdev):
try:
func('a')
except OSError, e:
if e.errno != errno.E???:
raise
else:
ok = True
if ok:
...
That way it only catches the exact error that we are avoiding. And we
only have one line to fix for Windows.
John
=:->
>
> ------------------------------------------------------------------------
>
> === modified file 'bzrlib/tests/test_hashcache.py'
> --- bzrlib/tests/test_hashcache.py
> +++ bzrlib/tests/test_hashcache.py
> @@ -127,19 +127,23 @@
> os.mkdir('.bzr')
> hc = HashCache(u'.')
> ok = False
> + # make a best effort to create a weird kind of file
> try:
> os.mkfifo('a')
> ok=True
> - except:
> + except OSError:
> try:
> os.mknod('a')
> ok=True
> - except:
> + except OSError:
> try:
> os.mkdev('a')
> ok=True
> - except:
> + except OSError:
> pass
> +
> + from bzrlib.errors import BzrError
> if ok:
> - from bzrlib.errors import BzrError
> self.assertRaises(BzrError, hc.get_sha1, 'a')
> + else:
> + raise BzrError("no weird file type could be created: extend this test case for your os")
>
>
>
> ------------------------------------------------------------------------
>
>
>
> --Denys
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060111/2532cf28/attachment.pgp
More information about the bazaar
mailing list