Back to index

python-biopython  1.60
Public Member Functions
test_SeqIO_write.WriterTests Class Reference

List of all members.

Public Member Functions

def check
def check_simple
def check_write_fails

Detailed Description

Cunning unit test where methods are added at run time.

Definition at line 79 of file test_SeqIO_write.py.


Member Function Documentation

def test_SeqIO_write.WriterTests.check (   self,
  records,
  format 
)
General test function with with a little format specific information.

This has some general expected exceptions hard coded!

Definition at line 81 of file test_SeqIO_write.py.

00081 
00082     def check(self, records, format):
00083         """General test function with with a little format specific information.
00084 
00085         This has some general expected exceptions hard coded!
00086         """
00087         #TODO - Check the exception messages?
00088         lengths = len(set(len(r) for r in records))
00089         if not records and format in ["stockholm", "phylip", "phylip-relaxed",
00090                                       "phylip-sequential", "nexus", "clustal",
00091                                       "sff"]:
00092             self.check_write_fails(records, format, ValueError,
00093                                    "Must have at least one sequence")
00094         elif lengths > 1 and format in AlignIO._FormatToWriter:
00095             self.check_write_fails(records, format, ValueError,
00096                                    "Sequences must all be the same length")
00097         elif records and format in ["fastq", "fastq-sanger", "fastq-solexa",
00098                                     "fastq-illumina", "qual", "phd"]:
00099             self.check_write_fails(records, format, ValueError,
00100                                    "No suitable quality scores found in "
00101                                    "letter_annotations of SeqRecord "
00102                                    "(id=%s)." % records[0].id)
00103         elif records and format == "sff":
00104             self.check_write_fails(records, format, ValueError,
00105                                    "Missing SFF flow information")
00106         else:
00107             self.check_simple(records, format)

Here is the call graph for this function:

Here is the caller graph for this function:

def test_SeqIO_write.WriterTests.check_simple (   self,
  records,
  format 
)

Definition at line 108 of file test_SeqIO_write.py.

00108 
00109     def check_simple(self, records, format):
00110         if format in SeqIO._BinaryFormats:
00111             handle = BytesIO()
00112         else:
00113             handle = StringIO()
00114         count = SeqIO.write(records, handle, format)
00115         self.assertEqual(count, len(records))
00116         #Now read them back...
00117         handle.seek(0)
00118         new_records = list(SeqIO.parse(handle, format))
00119         self.assertEqual(len(new_records), len(records))
00120         for record, new_record in zip(records, new_records):
00121             #Using compare_record(record, new_record) is too strict
00122             if format == "nexus":
00123                 #The nexus parser will dis-ambiguate repeated record ids.
00124                 self.assertTrue(record.id == new_record.id or \
00125                                 new_record.id.startswith(record.id+".copy"))
00126             else:
00127                 self.assertEqual(record.id, new_record.id)
00128             self.assertEqual(record.seq.tostring(), new_record.seq.tostring())
00129         handle.close()

Here is the caller graph for this function:

def test_SeqIO_write.WriterTests.check_write_fails (   self,
  records,
  format,
  err_type,
  err_msg = "" 
)

Definition at line 130 of file test_SeqIO_write.py.

00130 
00131     def check_write_fails(self, records, format, err_type, err_msg=""):
00132         if format in SeqIO._BinaryFormats:
00133             handle = BytesIO()
00134         else:
00135             handle = StringIO()
00136         if err_msg:
00137             try:
00138                 SeqIO.write(records, handle, format)
00139             except err_type, err:
00140                 self.assertEqual(str(err), err_msg)
00141         else:
00142             self.assertRaises(err_type, SeqIO.write, records, handle, format)
00143         handle.close()

Here is the caller graph for this function:


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