Back to index

python-biopython  1.60
Functions
check_output Namespace Reference

Functions

def do_comparison
def write_format

Function Documentation

def check_output.do_comparison (   good_record,
  test_record 
)
Compare two records to see if they are the same.

Ths compares the two GenBank record, and will raise an AssertionError
if two lines do not match, showing the non-matching lines.

Definition at line 20 of file check_output.py.

00020 
00021 def do_comparison(good_record, test_record):
00022     """Compare two records to see if they are the same.
00023 
00024     Ths compares the two GenBank record, and will raise an AssertionError
00025     if two lines do not match, showing the non-matching lines.
00026     """
00027     good_handle = cStringIO.StringIO(good_record)
00028     test_handle = cStringIO.StringIO(test_record)
00029 
00030     while 1:
00031         good_line = good_handle.readline()
00032         test_line = test_handle.readline()
00033 
00034         if not(good_line) and not(test_line):
00035             break
00036 
00037         if not(good_line):
00038             if good_line.strip():
00039                 raise AssertionError("Extra info in Test: `%s`" % test_line)
00040         if not(test_line):
00041             if test_line.strip():
00042                 raise AssertionError("Extra info in Expected: `%s`"
00043                                      % good_line)
00044 
00045         assert test_line == good_line, \
00046                "Expected does not match Test.\nExpect:`%s`\nTest  :`%s`\n" % \
00047                (good_line, test_line)
    

Here is the caller graph for this function:

def check_output.write_format (   file)

Definition at line 48 of file check_output.py.

00048 
00049 def write_format(file):
00050     record_parser = GenBank.RecordParser(debug_level = 2)
00051 
00052     print "Testing GenBank writing for %s..." % os.path.basename(file)
00053     # be able to handle gzipped files
00054     if file.find(".gz") >= 0:
00055         cur_handle = gzip.open(file, "r")
00056         compare_handle = gzip.open(file, "r")
00057     else:
00058         cur_handle = open(file, "r")
00059         compare_handle = open(file, "r")
00060 
00061     iterator = GenBank.Iterator(cur_handle, record_parser)
00062     compare_iterator = GenBank.Iterator(compare_handle)
00063         
00064     while 1:
00065         cur_record = iterator.next()
00066         compare_record = compare_iterator.next()
00067             
00068         if cur_record is None or compare_record is None:
00069             break
00070 
00071         # print "\tTesting for %s" % cur_record.version
00072 
00073         output_record = str(cur_record) + "\n"
00074         try:
00075             do_comparison(compare_record, output_record)
00076         except AssertionError, msg:
00077             print "\tTesting for %s" % cur_record.version
00078             print msg
00079 
00080     cur_handle.close()
00081     compare_handle.close()

Here is the call graph for this function: