1
1
##############################################################################
3
# Copyright (c) 2010 The MadGraph Development team and Contributors
3
# Copyright (c) 2010 The MadGraph5_aMC@NLO Development team and Contributors
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.
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
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
14
14
################################################################################
15
15
""" Basic test of the command interface """
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
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 """
31
if not hasattr(self, 'cmd'):
32
TestValidCmd.cmd = cmd.MasterCmd()
29
34
def wrong(self,*opt):
30
35
self.assertRaises(madgraph.MadGraph5Error, *opt)
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'])
74
79
goal = """set cluster_queue 2
93
98
generate p p > go go
95
100
history = [l.strip() for l in history.split('\n')]
96
self.cmd.history = history
101
self.cmd.history[:] = history
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'])
101
106
# Test the call present in do_import model
123
128
history = [l.strip() for l in history.split('\n')]
124
self.cmd.history = history
129
self.cmd.history[:] = history
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')
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)
144
def test_InvalidCmd(self):
145
"""test that the Invalid Command are dealt with correctly"""
147
master = cmd.MasterCmd()
148
self.assertRaises(master.InvalidCmd, master.do_generate,('aa'))
151
except Exception, error:
153
self.assertTrue(False, 'error are not treated correctly')
156
master = ms_cmd.MadSpinInterface()
157
self.assertRaises(Exception, master.do_define,('aa'))
159
with misc.MuteLogger(['fatalerror'], [40],['/tmp/fatalerror.log'], keep=False):
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)
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
163
190
categories_nb[cat] = 1
165
target = set(['Not in help'])
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)
194
self.assertEqual(categories_nb['Not in help'], 25)
198
@test_aloha.set_global()
172
199
def test_check_generate(self):
173
200
"""check if generate format are correctly supported"""
237
265
self.assertEqual(main.child, None)
238
266
#ret = main.do_quit('')
239
267
#self.assertEqual(ret, True)
269
class TestMadSpinFCT_in_interface(unittest.TestCase):
270
""" check if the ValidCmd works correctly """
273
if not hasattr(self, 'cmd'):
274
TestMadSpinFCT_in_interface.cmd = cmd.MasterCmd()
275
TestMadSpinFCT_in_interface.cmd.exec_cmd('import model sm')
278
def test_get_final_part(self):
281
output = self.cmd.get_final_part(' p p > e+ e-')
282
self.assertEqual(output, set([-11, 11]))
284
output = self.cmd.get_final_part(' p p > e+ e- QED=2')
285
self.assertEqual(output, set([-11, 11]))
287
output = self.cmd.get_final_part(' p p > z > e+ e-')
288
self.assertEqual(output, set([-11, 11]))
290
output = self.cmd.get_final_part(' p p > z > e+ e- / a')
291
self.assertEqual(output, set([-11, 11]))
293
output = self.cmd.get_final_part(' p p > z > e+ e- [QCD]')
294
self.assertEqual(output, set([-11, 11]))
296
output = self.cmd.get_final_part(' p p > z > e+ e- [ QCD ]')
297
self.assertEqual(output, set([-11, 11]))
299
output = self.cmd.get_final_part(' p p > z > e+ e- [ all = QCD ]')
300
self.assertEqual(output, set([-11, 11]))
302
output = self.cmd.get_final_part(' p p > z > l+ l- [ all = QCD ]')
303
self.assertEqual(output, set([-11, 11, -13, 13]))
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]))
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]))