view test/test_query_metexp_LARGE.py @ 55:543958f75e83

small fix
author pieter.lukasse@wur.nl
date Thu, 11 Dec 2014 14:45:28 +0100
parents 19d8fd10248e
children
line wrap: on
line source

'''Integration tests for the GCMS project'''

from pkg_resources import resource_filename  # @UnresolvedImport # pylint: disable=E0611
from GCMS import query_metexp
import os.path
import sys
import unittest


class IntegrationTest(unittest.TestCase):


#     def test_MM_calculations(self):
#         '''
#         test the implemented method for MM calculations for 
#         given chemical formulas
#         '''
#         export_to_metexp_tabular.init_elements_and_masses_map()
#         
#         formula = "C8H18O3"
#         # should be = 12.01*8 + 1.01*18 + 16*3 = 162.26
#         result = export_to_metexp_tabular.get_molecular_mass(formula)
#         self.assertEqual(162.26, result)
#         
#         formula = "CH2O3Fe2Ni"
#         # should be = 12.01*1 + 1.01*2 + 16*3 + 55.85*2 + 58.71 = 232.44
#         result = export_to_metexp_tabular.get_molecular_mass(formula)
#         self.assertAlmostEqual(232.44, result, 2)
#         
#         
#         
        

    def test_large(self):
        '''
        Simple test, but on larger set, last test executed in 28s
        '''
        # Create out folder
        outdir = "output/metexp_query/"
        if not os.path.exists(outdir):
            os.makedirs(outdir)

        #Build up arguments and run
        
        #         input_file = sys.argv[1]
        #         molecular_mass_col = sys.argv[2]
        #         formula_col = sys.argv[3]
        #         metexp_dblink_file = sys.argv[4]
        #         output_result = sys.argv[5]
        
        input_file = resource_filename(__name__, "data/metexp_query_tabular_large.txt")
        casid_col = "CAS"
        formula_col = "FORMULA"
        molecular_mass_col = "MM"
        metexp_dblink_file = resource_filename(__name__, "data/METEXP Test DB.txt")
        output_result = resource_filename(__name__, outdir + "metexp_query_results_added_LARGE.txt")
    
        sys.argv = ['test',
                    input_file,
                    casid_col,
                    formula_col, 
                    molecular_mass_col,
                    metexp_dblink_file,
                    'GC',
                    output_result]
        
        # Execute main function with arguments provided through sys.argv
        query_metexp.main()

        
   

def _read_file(filename):
    '''
    Helper method to quickly read a file
    @param filename:
    '''
    with open(filename) as handle:
        return handle.read()