[Biopython-dev] Biopython under PyPy

Peter Cock p.j.a.cock at googlemail.com
Mon Sep 19 12:33:47 EDT 2011


On Fri, Sep 16, 2011 at 1:07 PM, Peter Cock wrote:
>>>> What is interesting is running the full test suite reports some
>>>> false positives (tests which when run on their own, or as part
>>>> of a smaller group pass), and the test suite itself never finishes:
>>>> error: Too many open files
>>>>
>>>> I'm not sure what this is from... I fixed an obvious handle leak:
>>>>
>>>>
>>>> https://github.com/biopython/biopython/commit/f7ce81b3751745970c32cc813836507e93da3c30
>>>>
>>>> I suspect the problem is some of the individual tests are
>>>> leaking handles - which we know already from warnings
>>>> under Python 3 etc.

Adding a gc.collect() call after each test_XXX.py is run
seems to solve that in as much as run_tests.py finishes.

We're down to these failures,

test_CAPS.py
test_Pathway.py
test_Restriction.py
test_SeqIO_index.py - leaking handles

I'll look at test_SeqIO_index.py a bit more, but the others
are more curious. They could indicate some fragile code
in Biopython which is implementation specific, or perhaps
they hit a bug in PyPy. Is anyone interested in finding out?

Otherwise we can skip them for now, so that the whole
test suite passes, and get PyPy added to the BuildBot
for nightly regression testing.

On Sat, Sep 17, 2011 at 3:37 AM, Eric Talevich wrote:
> On Fri, Sep 16, 2011 at 6:56 PM, Peter Cock wrote:
>> Yeah - in the example above can you put the with statement
>> inside an if?
>
> In runTest it's a little strange because the open() call depends on the
> Python version. So we could do:
>
> if sys.version_info[0] >= 3:
>     #Python 3 problem: Can't use utf8 on output/test_geo
>     #due to micro (\xb5) and degrees (\xb0) symbols
>     open_kwargs = {'encoding': 'latin'}
> else:
>     open_kwargs = {'mode': 'rU'}
> with open(outputfile, **kwargs) as expected:
>     # Everything else...
>
>
> But then we lose the try/except block that catches the missing-file error.
> The cleanest solution would be a separate context handler:
>
> @contextlib.contextmanager
> def open_outputfile(fname):
>     try:
>         if sys.version_info[0] >= 3:
>             #Python 3 problem: Can't use utf8 on output/test_geo
>             #due to micro (\xb5) and degrees (\xb0) symbols
>             expected = open(outputfile, encoding="latin")
>         else:
>             expected = open(outputfile, 'rU')
>         yield expected
>     except IOError:
>         self.fail("Warning: Can't open %s for test %s" % (outputfile,
> self.name))
>     finally:
>         expected.close()
>
>
> I think that would do everything we want.

Yeah... frankly I find the explicit open/close easier to read here.

We can at least get rid of one level of try/except nesting now
we've dropped Python 2.4 support...

Peter



More information about the Biopython-dev mailing list