Back to index

python-biopython  1.60
Public Member Functions
test_PDB.A_ExceptionTest Class Reference

List of all members.

Public Member Functions

def test_1_warnings
def test_2_strict
def test_3_bad_xyz

Detailed Description

Errors and warnings while parsing of flawed PDB files.

These tests must be executed because of the way Python's warnings module
works -- a warning is only logged the first time it is encountered.

Definition at line 35 of file test_PDB.py.


Member Function Documentation

Check warnings: Parse a flawed PDB file in permissive mode.

NB: The try/finally block is adapted from the warnings.catch_warnings
context manager in the Python 2.6 standard library.

Definition at line 41 of file test_PDB.py.

00041 
00042     def test_1_warnings(self):
00043         """Check warnings: Parse a flawed PDB file in permissive mode.
00044 
00045         NB: The try/finally block is adapted from the warnings.catch_warnings
00046         context manager in the Python 2.6 standard library.
00047         """
00048         warnings.simplefilter('always', PDBConstructionWarning)
00049         try:
00050             # Equivalent to warnings.catch_warnings -- hackmagic
00051             orig_showwarning = warnings.showwarning
00052             all_warns = []
00053             def showwarning(*args, **kwargs):
00054                 all_warns.append(args[0])
00055             warnings.showwarning = showwarning
00056             # Trigger warnings
00057             p = PDBParser(PERMISSIVE=True)
00058             p.get_structure("example", "PDB/a_structure.pdb")
00059             self.assertEqual(len(all_warns), 14)
00060             for wrn, msg in zip(all_warns, [
00061                 # Expected warning messages:
00062                 "Used element 'N' for Atom (name=N) with given element ''",
00063                 "Used element 'C' for Atom (name=CA) with given element ''",
00064                 "Atom names ' CA ' and 'CA  ' differ only in spaces at line 17.",
00065                 "Used element 'CA' for Atom (name=CA  ) with given element ''",
00066                 'Atom N defined twice in residue <Residue ARG het=  resseq=2 icode= > at line 21.',
00067                 'disordered atom found with blank altloc before line 33.',
00068                 "Residue (' ', 4, ' ') redefined at line 43.",
00069                 "Blank altlocs in duplicate residue SER (' ', 4, ' ') at line 43.",
00070                 "Residue (' ', 10, ' ') redefined at line 75.",
00071                 "Residue (' ', 14, ' ') redefined at line 106.",
00072                 "Residue (' ', 16, ' ') redefined at line 135.",
00073                 "Residue (' ', 80, ' ') redefined at line 633.",
00074                 "Residue (' ', 81, ' ') redefined at line 646.",
00075                 'Atom O defined twice in residue <Residue HOH het=W resseq=67 icode= > at line 822.'
00076                 ]):
00077                 self.assertTrue(msg in str(wrn), str(wrn))
00078         finally:
00079             warnings.showwarning = orig_showwarning

Check error: Parse a flawed PDB file in strict mode.

Definition at line 80 of file test_PDB.py.

00080 
00081     def test_2_strict(self):
00082         """Check error: Parse a flawed PDB file in strict mode."""
00083         warnings.simplefilter('ignore', PDBConstructionWarning)
00084         try:
00085             parser = PDBParser(PERMISSIVE=False)
00086             self.assertRaises(PDBConstructionException,
00087                    parser.get_structure, "example", "PDB/a_structure.pdb")
00088         finally:
00089             warnings.filters.pop()
     
Check error: Parse an entry with bad x,y,z value.

Definition at line 90 of file test_PDB.py.

00090 
00091     def test_3_bad_xyz(self):
00092         """Check error: Parse an entry with bad x,y,z value."""
00093         data = "ATOM      9  N   ASP A 152      21.554  34.953  27.691  1.00 19.26           N\n"
00094         parser = PDBParser(PERMISSIVE=False)
00095         s = parser.get_structure("example", StringIO(data))
00096         data = "ATOM      9  N   ASP A 152      21.ish  34.953  27.691  1.00 19.26           N\n"
00097         self.assertRaises(PDBConstructionException,
00098                 parser.get_structure, "example", StringIO(data))       
00099 


The documentation for this class was generated from the following file: