[Biopython-dev] [Bug 2820] Convert test_PDB.py to unittest

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Thu Apr 23 23:36:28 UTC 2009


http://bugzilla.open-bio.org/show_bug.cgi?id=2820





------- Comment #1 from biopython-bugzilla at maubp.freeserve.co.uk  2009-04-23 19:36 EST -------
(In reply to comment #0)
> The current test script for Bio.PDB uses the print-and-compare approach. I've
> written an equivalent test script using unittest, assuming that style is the
> preferred one.

Yes, in principle the unittest style is prefferred.  In practice I am
pragmatic about this - a print-and-compare test is better than nothing,
and for some things is much easier to write.

> It was written to go with Bug 2754, but now lives on my pdbtidy branch:
> http://github.com/etal/biopython/tree/pdbtidy
> 
> This script could also live alongside the original test_PDB.py for awhile, as
> an additional check on Bio.PDB's error handling.

I've checked in a slightly modified version as test_PDB_unit.py - I think
having both this and the original test_PDB.py is sensible in the short term.

You wrote on Bug 2754 comment 14 that "one of the tests broke during the
merge", was that this one:

    def test_warnings(self):
        """Parse a flawed PDB file in permissive mode, with warnings"""
        # Python 2.6+: rewrite this using warnings.catch_warnings
        parser = PDBParser(PERMISSIVE=1)
        msg_redef_n = r"Atom N defined twice in residue <Residue ARG het=
resseq=2 icode= > at line 19\."
        msg_blank_alt = r"Blank altlocs in duplicate residue SER \(' ', 4, '
'\) at line 41\."
        msg_redef_o = r"Atom O defined twice in residue <Residue HOH het=W
resseq=67 icode= > at line 820\."
        warnings.simplefilter('ignore')
        # NB: Order is important here!
        warnings.filterwarnings('error', msg_redef_n, PDBConstructionWarning)
        self.assertRaises(PDBConstructionWarning,
                parser.get_structure, "example", "PDB/a_structure.pdb")
        warnings.filters.pop(0)
        warnings.filterwarnings('error', msg_blank_alt, PDBConstructionWarning)
        self.assertRaises(PDBConstructionWarning,
                parser.get_structure, "example", "PDB/a_structure.pdb")
        warnings.filters.pop(0)
        warnings.filterwarnings('error', msg_redef_o, PDBConstructionWarning)
        self.assertRaises(PDBConstructionWarning,
                parser.get_structure, "example", "PDB/a_structure.pdb")
        warnings.filters.pop(0)
        warnings.filters.pop(0)

I tried but couldn't get this to work (on Python 2.4.3 on Linux), even with
plenty of warnings.resetwarnings() which seemed cleaner than popping things.

I agree with the idea that we should make sure particular errors do get raised
(this is checked by the print-and-compare test_PDB.py because we capture these
warnings to stdout), but right now how to make it work escapes me.  Maybe after
 a good night's sleep things will make sense ;)

Leaving this bug open to address this point.

Peter


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list