annotate test/test_query_metexp.py @ 0:dffc38727496

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