Back to index

python-biopython  1.60
test_PopGen_SimCoal_nodepend.py
Go to the documentation of this file.
00001 # Copyright 2006 by Tiago Antao <tiagoantao@gmail.com>.  All rights reserved.
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 import os
00007 import unittest
00008 from Bio.PopGen import SimCoal
00009 from Bio.PopGen.SimCoal.Template import generate_simcoal_from_template
00010 
00011 #Tests simcoal related code. Note: this case doesn't require simcoal
00012 #test_PopGen_SimCoal tests code that requires simcoal
00013 
00014 
00015 class TemplateTest(unittest.TestCase):
00016     def test_template_full(self):
00017         """Full template creation test
00018         """
00019         generate_simcoal_from_template('simple',
00020             [(1, [('SNP', [24, 0.0005, 0.0])])],
00021             [('sample_size', [30]),
00022              ('pop_size', [100])],
00023             'PopGen')
00024         #Confirm the files match (ignoring any switch of line endings
00025         #possible if the input file used a different OS convention)
00026         handle = open(os.path.join('PopGen', 'simple.par'), "rU")
00027         old = handle.readlines()
00028         handle.close()
00029         handle = open(os.path.join('PopGen', 'simple_100_30.par'))
00030         new = handle.readlines()
00031         handle.close()
00032         assert old==new, "Error - Old:\n%s\n\nNew:\n%s\n" % (old, new)
00033         #assert(os.stat('PopGen' + os.sep + 'simple.par').st_size ==
00034         #       os.stat('PopGen' + os.sep + 'simple_100_30.par').st_size)
00035 
00036     def tearDown(self):
00037         if os.path.isfile(os.path.join('PopGen', 'tmp.par')):
00038             #This is a temp file create by the Bio.PopGen.SimCoal.Template
00039             #function generate_simcoal_from_template
00040             os.remove(os.path.join('PopGen', 'tmp.par'))
00041         if os.path.isfile(os.path.join('PopGen', 'simple_100_30.par')):
00042             #This won't exist if the template generation failed:
00043             os.remove(os.path.join('PopGen', 'simple_100_30.par'))
00044 
00045 if __name__ == "__main__":
00046     runner = unittest.TextTestRunner(verbosity = 2)
00047     unittest.main(testRunner=runner)