Statistiques
| Branche: | Tag: | Révision :

dockonsurf / tests / test_dos_input.py @ 03fab2dd

Historique | Voir | Annoter | Télécharger (5,82 ko)

1
import sys
2
import unittest
3
sys.path.extend(['../', '../modules', '../examples'])
4

    
5
from dos_input import *
6

    
7

    
8
class TestStr2Lst(unittest.TestCase):
9
    def test_norm_behav(self):
10
        self.assertEqual(str2lst('45'), [45])
11
        self.assertEqual(str2lst('(78, 9)'), [[78, 9]])
12
        self.assertEqual(str2lst('128,(135 138;141) 87 {45 68}'),
13
                         [128, 87, [135, 138, 141], [45, 68]])
14

    
15
    def test_exceptions(self):
16
        self.assertRaises(AttributeError, str2lst, 6)
17
        self.assertRaises(ValueError, str2lst, 'hola')
18
        self.assertRaises(ValueError, str2lst, '3 ((6 7) 8) 4')
19

    
20

    
21
class TestCheckInpFile(unittest.TestCase):
22
    def test_good(self):
23
        self.assertEqual(check_inp_file('cp2k.inp', 'cp2k'), None)
24

    
25
    def test_bad(self):
26
        self.assertRaises(UnboundLocalError, check_inp_file, 'cp2k.sub', 'cp2k')
27

    
28

    
29
class TestGoodInput(unittest.TestCase):
30
    read_input('good.inp')
31

    
32
    def test_all_good(self):
33
        exp_dict = {'project_name': 'example',
34
                    'isolated': True,
35
                    'screening': True,
36
                    'refinement': True,
37
                    'code': 'cp2k',
38
                    'batch_q_sys': 'sge',
39
                    'subm_script': 'cp2k.sub',
40
                    'relaunch_err': 'geo_not_conv',
41
                    'max_qw': 5,
42
                    'special_atoms': [('Fe1', 'Fe'), ('Fe2', 'Fe'),
43
                                      ('O1', 'O')],
44
                    'isol_inp_file': 'cp2k.inp',
45
                    'molec_file': 'acetic.xyz',
46
                    'cluster_magns': ['energy', 'moi'],
47
                    'num_conformers': 100,
48
                    'min_confs': False,
49
                    'screen_inp_file': 'screen.inp',
50
                    'sites': [128, [135, 138, 141]],
51
                    'molec_ads_ctrs': [178, [185, 187]],
52
                    'try_disso': True,
53
                    'sample_points_per_angle': 4,
54
                    'collision_threshold': 0.9,
55
                    'collision_bottom_z': 5.2,
56
                    'refine_inp_file': 'refine.inp',
57
                    'energy_cutoff': 1.0
58
                    }
59
        self.assertEqual(read_input('good.inp'), exp_dict)
60

    
61
    # TODO add single tests for subm_script and project_name
62

    
63
    def test_run_type(self):
64
        self.assertEqual(get_run_type(), (True, True, True))
65

    
66
    def test_code(self):
67
        self.assertEqual(get_code(), 'cp2k')
68

    
69
    def test_batch_q_sys(self):
70
        self.assertEqual(get_batch_q_sys(), 'sge')
71

    
72
    def test_relaunch_err(self):
73
        self.assertEqual(get_relaunch_err(), 'geo_not_conv')
74

    
75
    def test_max_qw(self):
76
        self.assertEqual(get_max_qw(), 5)
77

    
78
    def test_special_atoms(self):
79
        self.assertEqual(get_special_atoms(), [('Fe1', 'Fe'), ('Fe2', 'Fe'),
80
                                               ('O1', 'O')])
81

    
82
    def test_isol_inp_file(self):
83
        self.assertEqual(get_isol_inp_file(), 'isolated.inp')
84

    
85
    def test_molec_file(self):
86
        print(os.getcwd())
87
        self.assertEqual(get_molec_file(), 'acetic.xyz')
88

    
89
    def test_cluster_magns(self):
90
        self.assertEqual(get_cluster_magns(), ['energy', 'moi'])
91

    
92
    def test_num_conformers(self):
93
        self.assertEqual(get_num_conformers(), 100)
94

    
95
    def test_min_confs(self):
96
        self.assertEqual(get_min_confs(), False)
97

    
98
    def test_screen_inp_file(self):
99
        self.assertEqual(get_screen_inp_file(), 'screen.inp')
100

    
101
    def test_sites(self):
102
        self.assertEqual(get_sites(), [128, [135, 138, 141]])
103

    
104
    def test_molec_ads_ctrs(self):
105
        self.assertEqual(get_molec_ads_ctrs(), [178, [185, 187]])
106

    
107
    def test_try_disso(self):
108
        self.assertEqual(get_try_disso(), True)
109

    
110
    def test_pts_per_angle(self):
111
        self.assertEqual(get_pts_per_angle(), 4)
112

    
113
    def test_coll_thrsld(self):
114
        self.assertEqual(get_coll_thrsld(), 0.9)
115

    
116
    def test_coll_bottom_z(self):
117
        self.assertEqual(get_coll_bottom_z(), 5.2)
118

    
119
    def test_refine_inp_file(self):
120
        self.assertEqual(get_refine_inp_file(), 'refine.inp')
121

    
122
    def test_energy_cutoff(self):
123
        self.assertEqual(get_energy_cutoff(), 1.0)
124

    
125

    
126
class TestBadInput(unittest.TestCase):
127
    dos_inp.read('wrong.inp')
128

    
129
    def test_run_type(self):
130
        self.assertRaises(ValueError, get_run_type)
131

    
132
    def test_code(self):
133
        self.assertRaises(ValueError, get_code)
134

    
135
    def test_batch_q_sys(self):
136
        self.assertRaises(ValueError, get_batch_q_sys)
137

    
138
    def test_relaunch_err(self):
139
        self.assertRaises(ValueError, get_relaunch_err)
140

    
141
    def test_max_qw(self):
142
        self.assertRaises(ValueError, get_max_qw)
143

    
144
    def test_special_atoms(self):
145
        self.assertRaises(ValueError, get_special_atoms)
146

    
147
    def test_isol_inp_file(self):
148
        self.assertRaises(FileNotFoundError, get_isol_inp_file)
149

    
150
    def test_cluster_magns(self):
151
        self.assertRaises(ValueError, get_cluster_magns)
152

    
153
    def test_num_conformers(self):
154
        self.assertRaises(ValueError, get_num_conformers)
155

    
156
    def test_min_confs(self):
157
        self.assertRaises(ValueError, get_min_confs)
158

    
159
    def test_screen_inp_file(self):
160
        self.assertRaises(FileNotFoundError, get_screen_inp_file)
161

    
162
    def test_sites(self):
163
        self.assertRaises(ValueError, get_sites)
164

    
165
    def test_molec_ads_ctrs(self):
166
        self.assertRaises(ValueError, get_molec_ads_ctrs)
167

    
168
    def test_try_disso(self):
169
        self.assertRaises(ValueError, get_try_disso)
170

    
171
    def test_pts_per_angle(self):
172
        self.assertRaises(ValueError, get_pts_per_angle)
173

    
174
    def test_coll_thrsld(self):
175
        self.assertRaises(ValueError, get_coll_thrsld)
176

    
177
    def test_coll_bottom_z(self):
178
        self.assertRaises(ValueError, get_coll_bottom_z)
179

    
180
    def test_refine_inp_file(self):
181
        self.assertRaises(FileNotFoundError, get_refine_inp_file)
182

    
183
    def test_energy_cutoff(self):
184
        self.assertRaises(ValueError, get_energy_cutoff)
185

    
186

    
187
if __name__ == '__main__':
188
    unittest.main()