TestElementsDatabase.py 3.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

''' 
Created on May 29, 2015

@author: Eric C. Pellegrini
'''

import unittest

from MDANSE import ELEMENTS
from MDANSE.Data.ElementsDatabase import ElementsDatabaseError

38
class TestElementsDatabase(unittest.TestCase):
39
    '''
eric pellegrini's avatar
eric pellegrini committed
40
    Unittest for the configurators used to setup an analysis in MDANSE
41
42
43
44
45
46
47
48
49
50
    '''
    
    def setUp(self):
        
        self._types = {float:1.0,int:1,str:"toto"}
    

    def test___contains__(self):
        
        self.assertFalse("fhsdjfsd" in ELEMENTS)
51
        self.assertTrue("h" in ELEMENTS)
52
53
54
55
56
57
        self.assertTrue("H" in ELEMENTS)

    def test___getitem__(self):
                
        for e in ELEMENTS.elements:
            for p in ELEMENTS.properties:
58
                _ = ELEMENTS[e,p]
59
60
61
62

    def test_getelement(self):
        
        for e in ELEMENTS.elements:
63
            _ = ELEMENTS.get_element(e)
64
65
66
67

    def test_get_property(self):
                
        for p in ELEMENTS.properties:
68
            _ = ELEMENTS.get_property(p)
69
70
71

    def test___setitem__(self):
        
72
        ELEMENTS['C','atomic_weight'] = 20.0
73
74
75
76
                                
    def test_add_element(self):
        
        # Otherwise, everything should be OK
77
        ELEMENTS.add_element("element1")
78
79
80
81
82
83
84
        
    def test_add_property(self):
        
        # Adding an already existing property must trigger an error
        self.assertRaises(ElementsDatabaseError, ELEMENTS.add_property, "atomic_weight",0.0)
                
        # Otherwise, everything should be OK
85
86
87
        ELEMENTS.add_property("prop1",'float')
        ELEMENTS.add_property("prop2",'int')
        ELEMENTS.add_property("prop3",'str')
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
        
    def test_has_property(self):
        
        for p in ELEMENTS.properties:
            self.assertTrue(ELEMENTS.has_property(p))
            
        self.assertFalse(ELEMENTS.has_property("gfkljfklsj"))
            
    def test_has_element(self):
        
        for e in ELEMENTS.elements:
            self.assertTrue(ELEMENTS.has_element(e))
            
        self.assertFalse(ELEMENTS.has_element("gfkljfklsj"))
            
def suite():
    loader = unittest.TestLoader()
    s = unittest.TestSuite()
    s.addTest(loader.loadTestsFromTestCase(TestElementsDatabase))
    return s

if __name__ == '__main__':
    unittest.main(verbosity=2)
            
112