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

dockonsurf / tests / test_dos_input.py @ 9fd1daa6

Historique | Voir | Annoter | Télécharger (5,58 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 TestGoodInput(unittest.TestCase):
22
    read_input('good.inp')
23

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

    
53
    # TODO add single tests for subm_script and project_name
54

    
55
    def test_run_type(self):
56
        self.assertEqual(get_run_type(), (True, True, True))
57

    
58
    def test_code(self):
59
        self.assertEqual(get_code(), 'cp2k')
60

    
61
    def test_batch_q_sys(self):
62
        self.assertEqual(get_batch_q_sys(), 'sge')
63

    
64
    def test_relaunch_err(self):
65
        self.assertEqual(get_relaunch_err(), 'geo_not_conv')
66

    
67
    def test_max_qw(self):
68
        self.assertEqual(get_max_qw(), 5)
69

    
70
    def test_special_atoms(self):
71
        self.assertEqual(get_special_atoms(), [('Fe1', 'Fe'), ('Fe2', 'Fe'),
72
                                               ('O1', 'O')])
73

    
74
    def test_isol_inp_file(self):
75
        self.assertEqual(get_isol_inp_file(), 'isolated.inp')
76

    
77
    def test_molec_file(self):
78
        print(os.getcwd())
79
        self.assertEqual(get_molec_file(), 'acetic.xyz')
80

    
81
    def test_cluster_magns(self):
82
        self.assertEqual(get_cluster_magns(), ['energy', 'moi'])
83

    
84
    def test_num_conformers(self):
85
        self.assertEqual(get_num_conformers(), 100)
86

    
87
    def test_min_confs(self):
88
        self.assertEqual(get_min_confs(), False)
89

    
90
    def test_screen_inp_file(self):
91
        self.assertEqual(get_screen_inp_file(), 'screen.inp')
92

    
93
    def test_sites(self):
94
        self.assertEqual(get_sites(), [128, [135, 138, 141]])
95

    
96
    def test_molec_ads_ctrs(self):
97
        self.assertEqual(get_molec_ads_ctrs(), [178, [185, 187]])
98

    
99
    def test_try_disso(self):
100
        self.assertEqual(get_try_disso(), True)
101

    
102
    def test_pts_per_angle(self):
103
        self.assertEqual(get_pts_per_angle(), 4)
104

    
105
    def test_coll_thrsld(self):
106
        self.assertEqual(get_coll_thrsld(), 0.9)
107

    
108
    def test_coll_bottom_z(self):
109
        self.assertEqual(get_coll_bottom_z(), 5.2)
110

    
111
    def test_refine_inp_file(self):
112
        self.assertEqual(get_refine_inp_file(), 'refine.inp')
113

    
114
    def test_energy_cutoff(self):
115
        self.assertEqual(get_energy_cutoff(), 1.0)
116

    
117

    
118
class TestBadInput(unittest.TestCase):
119
    dos_inp.read('wrong.inp')
120

    
121
    def test_run_type(self):
122
        self.assertRaises(ValueError, get_run_type)
123

    
124
    def test_code(self):
125
        self.assertRaises(ValueError, get_code)
126

    
127
    def test_batch_q_sys(self):
128
        self.assertRaises(ValueError, get_batch_q_sys)
129

    
130
    def test_relaunch_err(self):
131
        self.assertRaises(ValueError, get_relaunch_err)
132

    
133
    def test_max_qw(self):
134
        self.assertRaises(ValueError, get_max_qw)
135

    
136
    def test_special_atoms(self):
137
        self.assertRaises(ValueError, get_special_atoms)
138

    
139
    def test_isol_inp_file(self):
140
        self.assertRaises(FileNotFoundError, get_isol_inp_file)
141

    
142
    def test_cluster_magns(self):
143
        self.assertRaises(ValueError, get_cluster_magns)
144

    
145
    def test_num_conformers(self):
146
        self.assertRaises(ValueError, get_num_conformers)
147

    
148
    def test_min_confs(self):
149
        self.assertRaises(ValueError, get_min_confs)
150

    
151
    def test_screen_inp_file(self):
152
        self.assertRaises(FileNotFoundError, get_screen_inp_file)
153

    
154
    def test_sites(self):
155
        self.assertRaises(ValueError, get_sites)
156

    
157
    def test_molec_ads_ctrs(self):
158
        self.assertRaises(ValueError, get_molec_ads_ctrs)
159

    
160
    def test_try_disso(self):
161
        self.assertRaises(ValueError, get_try_disso)
162

    
163
    def test_pts_per_angle(self):
164
        self.assertRaises(ValueError, get_pts_per_angle)
165

    
166
    def test_coll_thrsld(self):
167
        self.assertRaises(ValueError, get_coll_thrsld)
168

    
169
    def test_coll_bottom_z(self):
170
        self.assertRaises(ValueError, get_coll_bottom_z)
171

    
172
    def test_refine_inp_file(self):
173
        self.assertRaises(FileNotFoundError, get_refine_inp_file)
174

    
175
    def test_energy_cutoff(self):
176
        self.assertRaises(ValueError, get_energy_cutoff)
177

    
178

    
179
if __name__ == '__main__':
180
    unittest.main()