0
|
1 '''Integration tests for the GCMS project'''
|
|
2
|
|
3 from pkg_resources import resource_filename # @UnresolvedImport # pylint: disable=E0611
|
|
4 from GCMS import query_metexp
|
|
5 import os.path
|
|
6 import sys
|
|
7 import unittest
|
|
8
|
|
9
|
|
10 class IntegrationTest(unittest.TestCase):
|
|
11
|
|
12
|
|
13 # copied from test_export_to_metexp_tabular.py
|
|
14 # def test_MM_calculations(self):
|
|
15 # '''
|
|
16 # test the implemented method for MM calculations for
|
|
17 # given chemical formulas
|
|
18 # '''
|
|
19 # export_to_metexp_tabular.init_elements_and_masses_map()
|
|
20 #
|
|
21 # formula = "C8H18O3"
|
|
22 # # should be = 12.01*8 + 1.01*18 + 16*3 = 162.26
|
|
23 # result = export_to_metexp_tabular.get_molecular_mass(formula)
|
|
24 # self.assertEqual(162.26, result)
|
|
25 #
|
|
26 # formula = "CH2O3Fe2Ni"
|
|
27 # # should be = 12.01*1 + 1.01*2 + 16*3 + 55.85*2 + 58.71 = 232.44
|
|
28 # result = export_to_metexp_tabular.get_molecular_mass(formula)
|
|
29 # self.assertAlmostEqual(232.44, result, 2)
|
|
30 #
|
|
31 #
|
|
32 #
|
|
33
|
|
34
|
|
35 def test_simple(self):
|
|
36 '''
|
|
37 Simple initial test
|
|
38 '''
|
|
39 # Create out folder
|
|
40 outdir = "output/metexp_query/"
|
|
41 if not os.path.exists(outdir):
|
|
42 os.makedirs(outdir)
|
|
43
|
|
44 #Build up arguments and run
|
|
45
|
|
46 # input_file = sys.argv[1]
|
|
47 # molecular_mass_col = sys.argv[2]
|
|
48 # formula_col = sys.argv[3]
|
|
49 # metexp_dblink_file = sys.argv[4]
|
|
50 # output_result = sys.argv[5]
|
|
51
|
|
52 input_file = resource_filename(__name__, "data/metexp_query_tabular.txt")
|
|
53 casid_col = "CAS"
|
|
54 formula_col = "FORMULA"
|
|
55 molecular_mass_col = "MM"
|
|
56 metexp_dblink_file = resource_filename(__name__, "data/METEXP Test DB.txt")
|
|
57 output_result = resource_filename(__name__, outdir + "metexp_query_results_added.txt")
|
|
58
|
|
59 sys.argv = ['test',
|
|
60 input_file,
|
|
61 casid_col,
|
|
62 formula_col,
|
|
63 molecular_mass_col,
|
|
64 metexp_dblink_file,
|
|
65 'GC',
|
|
66 output_result]
|
|
67
|
|
68 # Execute main function with arguments provided through sys.argv
|
|
69 query_metexp.main()
|
|
70
|
|
71 # TODO - asserts (base them on DB being filled with test data form metexp unit test for upload method)
|
|
72 # PA
|
|
73
|
|
74
|
|
75
|
|
76
|
|
77 def _read_file(filename):
|
|
78 '''
|
|
79 Helper method to quickly read a file
|
|
80 @param filename:
|
|
81 '''
|
|
82 with open(filename) as handle:
|
|
83 return handle.read()
|