~maddevelopers/mg5amcnlo/2.9.4

« back to all changes in this revision

Viewing changes to tests/unit_tests/interface/test_cmd.py

pass to v2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
##############################################################################
2
2
#
3
 
# Copyright (c) 2010 The MadGraph Development team and Contributors
 
3
# Copyright (c) 2010 The MadGraph5_aMC@NLO Development team and Contributors
4
4
#
5
 
# This file is a part of the MadGraph 5 project, an application which 
 
5
# This file is a part of the MadGraph5_aMC@NLO project, an application which 
6
6
# automatically generates Feynman diagrams and matrix elements for arbitrary
7
7
# high-energy processes in the Standard Model and beyond.
8
8
#
9
 
# It is subject to the MadGraph license which should accompany this 
 
9
# It is subject to the MadGraph5_aMC@NLO license which should accompany this 
10
10
# distribution.
11
11
#
12
 
# For more information, please visit: http://madgraph.phys.ucl.ac.be
 
12
# For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch
13
13
#
14
14
################################################################################
15
15
""" Basic test of the command interface """
17
17
import unittest
18
18
import madgraph
19
19
import madgraph.interface.master_interface as cmd
 
20
import MadSpin.interface_madspin as ms_cmd
20
21
import madgraph.interface.extended_cmd as ext_cmd
 
22
import madgraph.various.misc as misc
21
23
import os
22
 
 
23
 
 
 
24
import logging
 
25
 
 
26
import tests.unit_tests.various.test_aloha as test_aloha
24
27
class TestValidCmd(unittest.TestCase):
25
28
    """ check if the ValidCmd works correctly """
26
29
    
27
 
    cmd = cmd.MasterCmd()
 
30
    def setUp(self):
 
31
        if not hasattr(self, 'cmd'):
 
32
            TestValidCmd.cmd = cmd.MasterCmd()
28
33
    
29
34
    def wrong(self,*opt):
30
35
        self.assertRaises(madgraph.MadGraph5Error, *opt)
67
72
        display particles
68
73
        generate p p > go go"""
69
74
        history = [l.strip() for l in  history.split('\n')]
70
 
        self.cmd.history = history
71
 
        self.cmd.clean_history(remove_bef_last='generate', keep_switch=True,
 
75
        self.cmd.history[:] = history
 
76
        self.cmd.history.clean(remove_bef_last='generate', keep_switch=True,
72
77
                     allow_for_removal= ['generate', 'add process', 'output'])
73
78
 
74
79
        goal = """set cluster_queue 2
93
98
        generate p p > go go
94
99
        import heft"""
95
100
        history = [l.strip() for l in  history.split('\n')]
96
 
        self.cmd.history = history        
 
101
        self.cmd.history[:] = history        
97
102
        
98
 
        self.cmd.clean_history(remove_bef_last='import', keep_switch=True,
 
103
        self.cmd.history.clean(remove_bef_last='import', keep_switch=True,
99
104
                        allow_for_removal=['generate', 'add process', 'output'])
100
105
 
101
106
        # Test the call present in do_import model
121
126
        launch
122
127
        output"""
123
128
        history = [l.strip() for l in  history.split('\n')]
124
 
        self.cmd.history = history         
 
129
        self.cmd.history[:] = history         
125
130
        
126
 
        self.cmd.clean_history(allow_for_removal = ['output'], keep_switch=True,
 
131
        self.cmd.history.clean(allow_for_removal = ['output'], keep_switch=True,
127
132
                           remove_bef_last='output')
128
133
 
129
134
        goal="""set cluster_queue 2
136
141
        goal = [l.strip() for l in  goal.split('\n')]
137
142
        self.assertEqual(self.cmd.history, goal)
138
143
    
139
 
    
140
 
    
141
 
    
 
144
    def test_InvalidCmd(self):
 
145
        """test that the Invalid Command are dealt with correctly"""
 
146
        
 
147
        master = cmd.MasterCmd()
 
148
        self.assertRaises(master.InvalidCmd, master.do_generate,('aa'))
 
149
        try:
 
150
            master.run_cmd('aa')
 
151
        except Exception, error:
 
152
            print error
 
153
            self.assertTrue(False, 'error are not treated correctly')
 
154
        
 
155
        # Madspin
 
156
        master = ms_cmd.MadSpinInterface()
 
157
        self.assertRaises(Exception, master.do_define,('aa'))
 
158
        
 
159
        with misc.MuteLogger(['fatalerror'], [40],['/tmp/fatalerror.log'], keep=False):
 
160
            try:
 
161
                master.run_cmd('define aa')
 
162
            except Exception, error:
 
163
                self.assertTrue(False, 'error are not treated correctly: %s' % error)
 
164
            text = open('/tmp/fatalerror.log').read()
 
165
            self.assertTrue('{' not in text)
 
166
            self.assertTrue('MS_debug' in text)
 
167
 
 
168
 
142
169
    def test_help_category(self):
143
170
        """Check that no help category are introduced by mistake.
144
171
           If this test fails, this is due to a un-expected ':' in a command of
161
188
                        categories_nb[cat] += 1
162
189
                    else:
163
190
                        categories_nb[cat] = 1
164
 
                
165
 
        target = set(['Not in help'])
 
191
 
 
192
        target = set(['Not in help', 'Main commands', 'Documented commands'])
166
193
        self.assertEqual(target, category)
167
 
        self.assertEqual(categories_nb['Not in help'], 2)
168
 
    
169
 
    
170
 
    
171
 
    
 
194
        self.assertEqual(categories_nb['Not in help'], 25)
 
195
    
 
196
    
 
197
    
 
198
    @test_aloha.set_global()
172
199
    def test_check_generate(self):
173
200
        """check if generate format are correctly supported"""
174
201
    
193
220
        self.wrong(cmd.check_process_format, 'e+ > ')
194
221
        self.wrong(cmd.check_process_format, 'e+ >')
195
222
        
 
223
    @test_aloha.set_global()
196
224
    def test_output_default(self):
197
225
        """check that if a export_dir is define before an output
198
226
           a new one is propose"""
237
265
        self.assertEqual(main.child, None)
238
266
        #ret = main.do_quit('')
239
267
        #self.assertEqual(ret, True)        
240
 
         
 
268
 
 
269
class TestMadSpinFCT_in_interface(unittest.TestCase):
 
270
    """ check if the ValidCmd works correctly """
241
271
    
242
 
 
 
272
    def setUp(self):
 
273
        if not hasattr(self, 'cmd'):
 
274
            TestMadSpinFCT_in_interface.cmd = cmd.MasterCmd()
 
275
            TestMadSpinFCT_in_interface.cmd.exec_cmd('import model sm')
 
276
            
 
277
            
 
278
    def test_get_final_part(self):
 
279
        """ """
 
280
        
 
281
        output = self.cmd.get_final_part(' p p > e+ e-')
 
282
        self.assertEqual(output, set([-11, 11]))
 
283
 
 
284
        output = self.cmd.get_final_part(' p p > e+ e- QED=2')
 
285
        self.assertEqual(output, set([-11, 11]))
 
286
        
 
287
        output = self.cmd.get_final_part(' p p > z > e+ e-')
 
288
        self.assertEqual(output, set([-11, 11]))        
 
289
          
 
290
        output = self.cmd.get_final_part(' p p > z > e+ e- / a')
 
291
        self.assertEqual(output, set([-11, 11]))
 
292
 
 
293
        output = self.cmd.get_final_part(' p p > z > e+ e- [QCD]')
 
294
        self.assertEqual(output, set([-11, 11]))
 
295
        
 
296
        output = self.cmd.get_final_part(' p p > z > e+ e- [ QCD ]')
 
297
        self.assertEqual(output, set([-11, 11]))
 
298
        
 
299
        output = self.cmd.get_final_part(' p p > z > e+ e- [ all = QCD ]')
 
300
        self.assertEqual(output, set([-11, 11]))
 
301
        
 
302
        output = self.cmd.get_final_part(' p p > z > l+ l- [ all = QCD ]')
 
303
        self.assertEqual(output, set([-11, 11, -13, 13]))
 
304
        
 
305
        output = self.cmd.get_final_part(' p p > z j, z > l+ l- [ all = QCD ]')
 
306
        self.assertEqual(output, set([-11, 11, -13, 13, 1, 2, 3, 4, 21, -1, -2,-3,-4]))
 
307
        
 
308
        output = self.cmd.get_final_part(' p p > t t~ [ all = QCD ] , (t > b z, z > l+ l-) ')
 
309
        self.assertEqual(output, set([-11, 11, -13, 13, -6, 5]))        
 
310
        
 
311