How to use level method in Slash

Best Python code snippet using slash

test_edit_card.py

Source:test_edit_card.py Github

copy

Full Screen

1##############################################################################2#3# Copyright (c) 2010 The MadGraph Development team and Contributors4#5# This file is a part of the MadGraph 5 project, an application which 6# automatically generates Feynman diagrams and matrix elements for arbitrary7# high-energy processes in the Standard Model and beyond.8#9# It is subject to the MadGraph license which should accompany this 10# distribution.11#12# For more information, please visit: http://madgraph.phys.ucl.ac.be13#14################################################################################15""" Basic test of the command interface """16import unittest17import madgraph18import madgraph.interface.master_interface as mgcmd19import madgraph.interface.extended_cmd as ext_cmd20import madgraph.interface.madevent_interface as mecmd21import madgraph.interface.common_run_interface as runcmd22import madgraph.iolibs.files as files23import madgraph.various.misc as misc24import os25try:26 import readline27except:28 readline = None29root_path = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0]30root_path = os.path.dirname(root_path)31# root_path is ./tests32pjoin = os.path.join33class FakeInterface(object):34 35 do_define_transfer_fct = ''36 complete_define_transfer_fct = ''37 help_define_transfer_fct = ''38 39 def __init__(self, me_dir):40 self.me_dir = me_dir41 self.inputfile = None42 43class TestEditCardCmd(unittest.TestCase):44 """ check if the ValidCmd works correctly """45 46 def setUp(self):47 """ """48 49 if os.path.exists('/tmp/edit_card'):50 os.system('rm -rf /tmp/edit_card')51 os.system('mkdir /tmp/edit_card;mkdir /tmp/edit_card/Cards;')52 template_path = pjoin(root_path, '..', 'Template')53 card= 'param_card'54 files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s.dat' % card)55 files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s_default.dat' % card)56 57 card = 'run_card'58 import madgraph.various.banner as banner_mod59 card = banner_mod.RunCardLO()60 card.write('/tmp/edit_card/Cards/run_card.dat')61 card.write('/tmp/edit_card/Cards/run_card_default.dat')62 card = 'MadWeight_card'63 files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards')64 files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)65 card = 'shower_card'66 files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards')67 files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)68 69 #MadLoop Card70 files.cp(pjoin(template_path, 'loop_material/StandAlone/Cards/MadLoopParams.dat'), '/tmp/edit_card/Cards')71 72 #Pythia8 73 files.cp(pjoin(template_path, 'LO/Cards/pythia8_card_default.dat'), '/tmp/edit_card/Cards/pythia8_card_default.dat')74 files.cp(pjoin(template_path, 'LO/Cards/pythia8_card_default.dat'), '/tmp/edit_card/Cards/pythia8_card.dat')75 76 fakemother = FakeInterface('/tmp/edit_card/')77 self.cmd = runcmd.AskforEditCard('', cards=['run_card.dat', 'param_card.dat', 'madweight_card.dat', 'shower_card.dat',78 'pythia8_card.dat'],79 mode='auto', mother_interface=fakemother)80 def get_completion(self, text):81 if readline:82 readline.__doc__ = 'libedit'83 data = text.split()84 fct = getattr(self.cmd, 'complete_%s' % (data[0]))85 line = ' '.join(data[1:])86 87 return fct("", text, len(text),len(text))88 89 90 91 92 def test_autocompletion(self):93 """"""94 95 # First Level (set)96 first_level = self.get_completion('set')97 self.assertTrue('MadWeight_card' in first_level)98 self.assertTrue('param_card' in first_level)99 self.assertTrue('run_card' in first_level) 100 self.assertTrue('bjet_is_jet' in first_level) 101 self.assertTrue('13' not in first_level) 102 self.assertTrue('etaj' in first_level)103 self.assertTrue('mass' in first_level)104 self.assertTrue('width' in first_level)105 self.assertTrue('decay' in first_level)106 self.assertTrue('mw_parameter' in first_level) 107 self.assertTrue('default' not in first_level) 108 self.assertTrue('wt' in first_level)109 self.assertTrue('iregimode' in first_level)110 self.assertTrue('MadLoop_card' in first_level)111 112 # MadWeight completion -------------------------------------------------113 # set MadWeight_card114 first_level = self.get_completion('set MadWeight_card')115 self.assertTrue('MadWeight_card' not in first_level)116 self.assertTrue('param_card' not in first_level)117 self.assertTrue('run_card' not in first_level) 118 self.assertTrue('MadLoop_card' not in first_level) 119 self.assertTrue('bjet_is_jet' in first_level) 120 self.assertTrue('13' not in first_level) 121 self.assertTrue('etaj' not in first_level)122 self.assertTrue('mass' not in first_level)123 self.assertTrue('width' not in first_level)124 self.assertTrue('decay' not in first_level)125 self.assertTrue('mw_parameter' in first_level) 126 self.assertTrue('default' in first_level) 127 self.assertTrue('iregimode' not in first_level)128 129 # set MadWeight_card mw_perm130 first_level = self.get_completion('set MadWeight_card mw_perm')131 self.assertTrue('MadWeight_card' not in first_level)132 self.assertTrue('param_card' not in first_level)133 self.assertTrue('run_card' not in first_level)134 self.assertTrue('MadLoop_card' not in first_level) 135 self.assertTrue('bjet_is_jet' in first_level) 136 self.assertTrue('13' not in first_level) 137 self.assertTrue('etaj' not in first_level)138 self.assertTrue('mass' not in first_level)139 self.assertTrue('width' not in first_level)140 self.assertTrue('decay' not in first_level)141 self.assertTrue('mw_parameter' not in first_level) 142 self.assertTrue('default' not in first_level) 143 self.assertTrue('iregimode' not in first_level)144 145 # set MadWeight_card mw_perm bjet_is_jet146 first_level = self.get_completion('set MadWeight_card mw_per bjet_is_jet')147 self.assertTrue('MadWeight_card' not in first_level)148 self.assertTrue('param_card' not in first_level)149 self.assertTrue('run_card' not in first_level) 150 self.assertTrue('MadLoop_card' not in first_level) 151 self.assertTrue('bjet_is_jet' not in first_level) 152 self.assertTrue('13' not in first_level) 153 self.assertTrue('etaj' not in first_level)154 self.assertTrue('mass' not in first_level)155 self.assertTrue('width' not in first_level)156 self.assertTrue('decay' not in first_level)157 self.assertTrue('mw_parameter' not in first_level) 158 self.assertTrue('default' in first_level) 159 self.assertTrue('iregimode' not in first_level)160 # set MadWeight_card mw_parameter161 first_level = self.get_completion('set MadWeight_card mw_parameter')162 self.assertTrue('MadWeight_card' not in first_level)163 self.assertTrue('param_card' not in first_level)164 self.assertTrue('run_card' not in first_level)165 self.assertTrue('MadLoop_card' not in first_level) 166 self.assertTrue('bjet_is_jet' not in first_level) 167 self.assertTrue('13' in first_level) 168 self.assertTrue('etaj' not in first_level)169 self.assertTrue('mass' not in first_level)170 self.assertTrue('width' not in first_level)171 self.assertTrue('decay' not in first_level)172 self.assertTrue('mw_parameter' not in first_level) 173 self.assertTrue('default' not in first_level)174 self.assertTrue('iregimode' not in first_level) 175 176 177 # MadEvent completion -------------------------------------------------178 first_level = self.get_completion('set param_card ')179 self.assertTrue('MadWeight_card' not in first_level)180 self.assertTrue('param_card' not in first_level)181 self.assertTrue('run_card' not in first_level)182 self.assertTrue('MadLoop_card' not in first_level) 183 self.assertTrue('bjet_is_jet' not in first_level) 184 self.assertTrue('6' not in first_level) 185 self.assertTrue('etaj' not in first_level)186 self.assertTrue('mass' in first_level)187 self.assertTrue('width' in first_level)188 self.assertTrue('decay' in first_level)189 self.assertTrue('wt' in first_level)190 self.assertTrue('mh' in first_level)191 self.assertTrue('as' in first_level)192 self.assertTrue('mw_parameter' not in first_level) 193 self.assertTrue('default' in first_level)194 self.assertTrue('iregimode' not in first_level) 195 first_level = self.get_completion('set param_card wolfenstein')196 self.assertTrue('MadWeight_card' not in first_level)197 self.assertTrue('param_card' not in first_level)198 self.assertTrue('run_card' not in first_level)199 self.assertTrue('MadLoop_card' not in first_level) 200 self.assertTrue('bjet_is_jet' not in first_level) 201 self.assertTrue('6' not in first_level) 202 self.assertTrue('1' in first_level) 203 self.assertTrue('etaj' not in first_level)204 self.assertTrue('mass' not in first_level)205 self.assertTrue('width' not in first_level)206 self.assertTrue('decay' not in first_level)207 self.assertTrue('wt' not in first_level)208 self.assertTrue('mh' not in first_level)209 self.assertTrue('etaws' in first_level)210 self.assertTrue('mw_parameter' not in first_level) 211 self.assertTrue('default' not in first_level)212 self.assertTrue('iregimode' not in first_level)213 first_level = self.get_completion('set param_card wolfenstein etaws')214 self.assertTrue('MadWeight_card' not in first_level)215 self.assertTrue('param_card' not in first_level)216 self.assertTrue('run_card' not in first_level)217 self.assertTrue('MadLoop_card' not in first_level) 218 self.assertTrue('bjet_is_jet' not in first_level) 219 self.assertTrue('6' not in first_level) 220 self.assertTrue('1' not in first_level) 221 self.assertTrue('etaj' not in first_level)222 self.assertTrue('mass' not in first_level)223 self.assertTrue('width' not in first_level)224 self.assertTrue('decay' not in first_level)225 self.assertTrue('wt' not in first_level)226 self.assertTrue('mh' not in first_level)227 self.assertTrue('etaws' not in first_level)228 self.assertTrue('mw_parameter' not in first_level) 229 self.assertTrue('default' in first_level)230 self.assertTrue('Auto' not in first_level)231 self.assertTrue('iregimode' not in first_level) 232 first_level = self.get_completion('set param_card decay')233 self.assertTrue('MadWeight_card' not in first_level)234 self.assertTrue('param_card' not in first_level)235 self.assertTrue('run_card' not in first_level)236 self.assertTrue('MadLoop_card' not in first_level) 237 self.assertTrue('bjet_is_jet' not in first_level) 238 self.assertTrue('6' in first_level) 239 self.assertTrue('1' not in first_level) 240 self.assertTrue('etaj' not in first_level)241 self.assertTrue('mass' not in first_level)242 self.assertTrue('width' not in first_level)243 self.assertTrue('decay' not in first_level)244 self.assertTrue('wt' in first_level)245 self.assertTrue('mh' not in first_level)246 self.assertTrue('etaws' not in first_level)247 self.assertTrue('mw_parameter' not in first_level) 248 self.assertTrue('default' not in first_level)249 self.assertTrue('Auto' not in first_level)250 self.assertTrue('iregimode' not in first_level)251 252 first_level = self.get_completion('set param_card width')253 self.assertTrue('MadWeight_card' not in first_level)254 self.assertTrue('param_card' not in first_level)255 self.assertTrue('run_card' not in first_level)256 self.assertTrue('MadLoop_card' not in first_level) 257 self.assertTrue('bjet_is_jet' not in first_level) 258 self.assertTrue('6' in first_level) 259 self.assertTrue('1' not in first_level) 260 self.assertTrue('etaj' not in first_level)261 self.assertTrue('mass' not in first_level)262 self.assertTrue('width' not in first_level)263 self.assertTrue('decay' not in first_level)264 self.assertTrue('wt' in first_level)265 self.assertTrue('mh' not in first_level)266 self.assertTrue('etaws' not in first_level)267 self.assertTrue('mw_parameter' not in first_level) 268 self.assertTrue('default' not in first_level)269 self.assertTrue('Auto' not in first_level)270 self.assertTrue('iregimode' not in first_level)271 272 first_level = self.get_completion('set param_card width wt')273 self.assertTrue('MadWeight_card' not in first_level)274 self.assertTrue('param_card' not in first_level)275 self.assertTrue('run_card' not in first_level)276 self.assertTrue('MadLoop_card' not in first_level) 277 self.assertTrue('bjet_is_jet' not in first_level) 278 self.assertTrue('6' not in first_level) 279 self.assertTrue('1' not in first_level) 280 self.assertTrue('etaj' not in first_level)281 self.assertTrue('mass' not in first_level)282 self.assertTrue('width' not in first_level)283 self.assertTrue('decay' not in first_level)284 self.assertTrue('wt' not in first_level)285 self.assertTrue('mh' not in first_level)286 self.assertTrue('etaws' not in first_level)287 self.assertTrue('mw_parameter' not in first_level) 288 self.assertTrue('default' in first_level)289 self.assertTrue('Auto' in first_level)290 self.assertTrue('Auto@NLO' in first_level)291 self.assertTrue('iregimode' not in first_level)292 293 first_level = self.get_completion('set param_card width 6')294 self.assertTrue('MadWeight_card' not in first_level)295 self.assertTrue('param_card' not in first_level)296 self.assertTrue('run_card' not in first_level)297 self.assertTrue('MadLoop_card' not in first_level) 298 self.assertTrue('bjet_is_jet' not in first_level) 299 self.assertTrue('6' not in first_level) 300 self.assertTrue('1' not in first_level) 301 self.assertTrue('etaj' not in first_level)302 self.assertTrue('mass' not in first_level)303 self.assertTrue('width' not in first_level)304 self.assertTrue('decay' not in first_level)305 self.assertTrue('wt' not in first_level)306 self.assertTrue('mh' not in first_level)307 self.assertTrue('etaws' not in first_level)308 self.assertTrue('mw_parameter' not in first_level) 309 self.assertTrue('default' in first_level)310 self.assertTrue('Auto' in first_level)311 self.assertTrue('Auto@NLO' in first_level)312 self.assertTrue('iregimode' not in first_level) 313 314 # Run_card completion -------------------------------------------------315 first_level = self.get_completion('set run_card ')316 self.assertTrue('MadWeight_card' not in first_level)317 self.assertTrue('param_card' not in first_level)318 self.assertTrue('run_card' not in first_level)319 self.assertTrue('MadLoop_card' not in first_level) 320 self.assertTrue('bjet_is_jet' not in first_level) 321 self.assertTrue('6' not in first_level) 322 self.assertTrue('etaj' in first_level)323 self.assertTrue('mass' not in first_level)324 self.assertTrue('width' not in first_level)325 self.assertTrue('decay' not in first_level)326 self.assertTrue('wt' not in first_level)327 self.assertTrue('mh' not in first_level)328 self.assertTrue('as' not in first_level)329 self.assertTrue('mw_parameter' not in first_level) 330 self.assertTrue('default' in first_level)331 self.assertTrue('Auto@NLO' not in first_level)332 self.assertTrue('iregimode' not in first_level) 333 334 first_level = self.get_completion('set run_card htjmax')335 self.assertTrue('MadWeight_card' not in first_level)336 self.assertTrue('param_card' not in first_level)337 self.assertTrue('run_card' not in first_level)338 self.assertTrue('MadLoop_card' not in first_level) 339 self.assertTrue('bjet_is_jet' not in first_level) 340 self.assertTrue('6' not in first_level) 341 self.assertTrue('etaj' not in first_level)342 self.assertTrue('mass' not in first_level)343 self.assertTrue('width' not in first_level)344 self.assertTrue('decay' not in first_level)345 self.assertTrue('wt' not in first_level)346 self.assertTrue('mh' not in first_level)347 self.assertTrue('as' not in first_level)348 self.assertTrue('mw_parameter' not in first_level) 349 self.assertTrue('default' in first_level)350 self.assertTrue('iregimode' not in first_level)351 352 # ML_card completion --------------------------------------------------- 353 first_level = self.get_completion('set MadLoop_card')354 self.assertTrue('MadWeight_card' not in first_level)355 self.assertTrue('param_card' not in first_level)356 self.assertTrue('run_card' not in first_level) 357 self.assertTrue('MadLoop_card' not in first_level) 358 self.assertTrue('bjet_is_jet' not in first_level) 359 self.assertTrue('6' not in first_level) 360 self.assertTrue('etaj' not in first_level)361 self.assertTrue('mass' not in first_level)362 self.assertTrue('width' not in first_level)363 self.assertTrue('decay' not in first_level)364 self.assertTrue('wt' not in first_level)365 self.assertTrue('mh' not in first_level)366 self.assertTrue('as' not in first_level)367 self.assertTrue('mw_parameter' not in first_level) 368 self.assertTrue('default' in first_level)369 self.assertTrue('iregimode' in first_level) 370 371 first_level = self.get_completion('set MadLoop_card iregimode')372 self.assertTrue('MadWeight_card' not in first_level)373 self.assertTrue('param_card' not in first_level)374 self.assertTrue('run_card' not in first_level)375 self.assertTrue('MadLoop_card' not in first_level) 376 self.assertTrue('bjet_is_jet' not in first_level) 377 self.assertTrue('6' not in first_level) 378 self.assertTrue('etaj' not in first_level)379 self.assertTrue('mass' not in first_level)380 self.assertTrue('width' not in first_level)381 self.assertTrue('decay' not in first_level)382 self.assertTrue('wt' not in first_level)383 self.assertTrue('mh' not in first_level)384 self.assertTrue('as' not in first_level)385 self.assertTrue('mw_parameter' not in first_level) 386 self.assertTrue('default' in first_level)387 self.assertTrue('iregimode' not in first_level) 388 389 390 def test_modif_param_card(self):391 """ """392 393 param = self.cmd.param_card394 wt = param['decay'].get((6,)).value395 self.cmd.do_set('width wt 100')396 self.assertEqual(param['decay'].get((6,)).value, 100)397 self.cmd.do_set('wt default') 398 self.assertEqual(param['decay'].get((6,)).value, wt)399 self.cmd.do_set('param_card width 6 Auto') 400 self.assertEqual(param['decay'].get((6,)).value, 'Auto') 401 self.cmd.do_set('param_card width 6 Auto@NLO') 402 self.assertEqual(param['decay'].get((6,)).value, 'Auto@NLO') 403 self.cmd.do_set('param_card width 6 auto@nLo') 404 self.assertEqual(param['decay'].get((6,)).value, 'Auto@NLO') 405 406 def test_modif_run_card(self):407 """ """408 run = self.cmd.run_card409 ptj = run['ptj']410 self.cmd.do_set('ptj 100')411 self.assertEqual(run['ptj'], 100)412 self.cmd.do_set('run_card ptj default') 413 self.assertEqual(run['ptj'], ptj)414 415 run.list_parameter['ptj'] = float416 self.cmd.do_set('ptj 100, 300')417 self.assertEqual(run['ptj'], [100, 300])418 self.cmd.do_set('ptj 100 200.1')419 self.assertEqual(run['ptj'], [100, 200.1])420 self.cmd.do_set('ptj 100 200.1, 3e3')421 self.assertEqual(run['ptj'], [100, 200.1, 3000])422 def test_modif_ML_card(self):423 ML = self.cmd.MLcard 424 iregimode = self.cmd.MLcard['IREGIMODE']425 426 #check that nothing change if type is not correct427 self.cmd.do_set('IREGIMODE True') #should do nothrin428 self.assertEqual(iregimode, self.cmd.MLcard['IREGIMODE'])429 self.assertTrue('iregimode' not in ML.user_set)430 431 #check that we change it correctly when an input is given432 self.cmd.do_set('IREGIMODE %s' % (iregimode+1))433 self.assertEqual(iregimode+1, self.cmd.MLcard['IREGIMODE'])434 self.assertTrue('iregimode' in ML.user_set) 435 #check that we change it correctly when going back to default436 self.cmd.do_set('IREGIMODE default')437 self.assertEqual(iregimode, self.cmd.MLcard['IREGIMODE'])438 self.assertTrue('iregimode' not in ML.user_set)439 440 # check that the full change is ok441 self.cmd.do_set('madloop_card IREGIMODE %s' % (iregimode+1))442 self.assertEqual(iregimode+1, self.cmd.MLcard['IREGIMODE'])443 self.assertTrue('iregimode' in ML.user_set) 444 445 IREGIRECY = self.cmd.MLcard['IREGIRECY'] 446 self.cmd.do_set('madloop_card IREGIRECY F')447 self.assertEqual(False, self.cmd.MLcard['iregirecy'])448 self.assertTrue(self.cmd.MLcard['iregirecy'] is self.cmd.MLcard['IREGIRECY'])449 450 self.cmd.do_set('madloop_card default') 451 self.assertEqual(iregimode, self.cmd.MLcard['IREGIMODE'])452 self.assertTrue('iregimode' not in self.cmd.MLcard.user_set) 453 self.assertEqual(IREGIRECY, self.cmd.MLcard['IREGIRECY'])454 self.assertTrue('iregimode' not in self.cmd.MLcard.user_set)455 self.assertTrue('iregirecy' not in self.cmd.MLcard.user_set)456 457 def test_modif_madweight_card(self):458 """ """ 459 460 mw = self.cmd.mw_card461 nb_event_by_node = mw['mw_run']['nb_event_by_node']462 self.cmd.do_set('nb_event_by_node 53')463 self.assertEqual(mw['mw_run']['nb_event_by_node'], '53')464 self.cmd.do_set('MadWeight_card nb_event_by_node default')465 self.assertEqual(mw['mw_run']['nb_event_by_node'], nb_event_by_node)466 467 # check that we can add block468 self.cmd.do_set('MadWeight_card mw_select E True')469 self.assertEqual(mw['mw_select']['e'].lower(), 'true')470 # check that we can add more than one value + add item471 self.cmd.do_set('mw_select F 1 2 3')472 self.assertEqual(mw['mw_select']['f'], ['1', '2','3'])473 474 def test_modif_shower_card(self):475 """ """476 477 shower = self.cmd.shower_card478 nevents = shower['nevents']479 self.cmd.do_set('shower_card nevents 199')480 self.assertEqual(shower['nevents'], 199)481 self.cmd.do_set('shower_card nevents default') 482 self.assertEqual(shower['nevents'], -1)483 self.cmd.do_set('mup_stable true')484 self.assertEqual(shower['mup_stable'], True)485 self.cmd.do_set('mup_stable F')486 self.assertEqual(shower['mup_stable'], False)487 self.cmd.do_set('mup_stable .true.')488 self.assertEqual(shower['mup_stable'], True)489 self.cmd.do_set('analyse a.o b.o C.o d.o')490 self.assertEqual(shower['analyse'], 'a.o b.o C.o d.o')491 self.cmd.do_set('shower_card analyse a.o b.o c.o f.o')492 self.assertEqual(shower['analyse'], 'a.o b.o c.o f.o')493 self.cmd.do_set('extrapaths extra/1 ex/t/ra2 EXtra3')494 self.assertEqual(shower['extrapaths'], 'extra/1 ex/t/ra2 EXtra3')495 self.cmd.do_set('includepaths extra/1 ex/t/ra2 EXtra3')496 self.assertEqual(shower['includepaths'], 'extra/1 ex/t/ra2 EXtra3')497 self.cmd.do_set('extralibs lib1 liB2 lIB3')498 self.assertEqual(shower['extralibs'], 'lib1 liB2 lIB3')499 # finally reload the default shower card500 # and check that, when any variable is set, the others correspond to the new shower_card501 # (Bug 1708113)502 self.cmd.copy_file('/tmp/edit_card/Cards/shower_card_default.dat')503 # check that we have the default504 shower = self.cmd.shower_card505 self.assertEqual(shower['nevents'], -1)506 self.cmd.do_set('shower_card nevents 150')507 self.assertEqual(shower['analyse'], '')508 def test_modif_pythia8_card(self):509 """ """ 510 511 py8 = self.cmd.PY8Card512 qcut = py8['JetMatching:qCut']513 self.cmd.do_set('jetmatching:qcut 53')514 self.assertEqual(py8['JetMatching:qCut'], 53.)515 516 self.cmd.copy_file('/tmp/edit_card/Cards/pythia8_card_default.dat')517 self.assertNotEqual(py8['JetMatching:qCut'], 53.)518 self.assertEqual(py8['JetMatching:qCut'], qcut)519 520 self.cmd.do_set('JetMatching:nJetMax 2')521 self.assertEqual(py8['JetMatching:qCut'], qcut)522 self.assertEqual(py8['JetMatching:nJetMax'], 2)...

Full Screen

Full Screen

levels.py

Source:levels.py Github

copy

Full Screen

...300 for i in range(24 - y_dim):301 m.append([0 if x not in [0, 61] else -1 for x in range(62)])302 m.insert(0, [-1 for _ in range(62)])303 return m304def choose_level(current_level):305 levels_init = [306 level_1_init, level_2_init, level_3_init, level_4_init, level_5_init, level_6_init,307 level_7_init, level_8_init, level_9_init, level_10_init,308 ]309 y_dim, matrix, level, prizes_level, lift = levels_init[current_level-1]()310 return y_dim, matrix, level, prizes_level, lift311if __name__ == '__main__':...

Full Screen

Full Screen

magicuser.py

Source:magicuser.py Github

copy

Full Screen

1import bflib.items.weapons.melee.staves2from bflib import dice3from bflib import restrictions4from bflib.characters import abilityscores5from bflib.characters import specialabilities6from bflib.characters.classes.base import CharacterClass7from bflib.characters.classes.level import Level, LevelTable8from bflib.characters.savingthrows import SavingThrowSet9from bflib.items import armor10from bflib.spells import SpellSlotSet11class MagicUser(CharacterClass):12 name = "Magic-User"13 restriction_set = restrictions.RestrictionSet(14 ability_score=restrictions.AbilityScoreRestrictionSet(15 minimum_set=abilityscores.AbilityScoreSet(intelligence=9)16 ),17 armor=restrictions.ArmorRestrictionSet(included=(armor.types.Clothing, ), shields=False),18 weapons=restrictions.WeaponRestrictionSet(19 included=(20 bflib.items.weapons.melee.daggers.Dagger,21 bflib.items.weapons.melee.maces.Cudgel,22 bflib.items.weapons.melee.staves.WalkingStaff,23 )24 )25 )26 special_abilities = specialabilities.SpecialAbilitySet(27 special_abilities=(28 specialabilities.ArcaneCaster,29 specialabilities.ReadMagic30 )31 )32 level_table = LevelTable(33 levels=(34 Level(35 value=1,36 attack_bonus=1,37 experience_required=0,38 hit_dice=dice.D4(1),39 saving_throws_set=SavingThrowSet(40 death_poison=13,41 dragon_breath=16,42 paralysis_stone=13,43 spells=15,44 wands=1445 ),46 spell_slots_set=SpellSlotSet(level_1=1)47 ),48 Level(49 value=2,50 attack_bonus=1,51 experience_required=2500,52 hit_dice=dice.D4(2),53 saving_throws_set=SavingThrowSet(54 death_poison=13,55 dragon_breath=15,56 paralysis_stone=13,57 spells=14,58 wands=1459 ),60 spell_slots_set=SpellSlotSet(level_1=2)61 ),62 Level(63 value=3,64 attack_bonus=1,65 experience_required=5000,66 hit_dice=dice.D4(3),67 saving_throws_set=SavingThrowSet(68 death_poison=13,69 dragon_breath=15,70 paralysis_stone=13,71 spells=14,72 wands=1473 ),74 spell_slots_set=SpellSlotSet(level_1=2, level_2=1)75 ),76 Level(77 value=4,78 attack_bonus=2,79 experience_required=10000,80 hit_dice=dice.D4(4),81 saving_throws_set=SavingThrowSet(82 death_poison=12,83 dragon_breath=15,84 paralysis_stone=12,85 spells=13,86 wands=1387 ),88 spell_slots_set=SpellSlotSet(level_1=2, level_2=2)89 ),90 Level(91 value=5,92 attack_bonus=2,93 experience_required=20000,94 hit_dice=dice.D4(5),95 saving_throws_set=SavingThrowSet(96 death_poison=12,97 dragon_breath=15,98 paralysis_stone=12,99 spells=13,100 wands=13101 ),102 spell_slots_set=SpellSlotSet(level_1=2, level_2=2, level_3=1)103 ),104 Level(105 value=6,106 attack_bonus=3,107 experience_required=40000,108 hit_dice=dice.D4(6),109 saving_throws_set=SavingThrowSet(110 death_poison=12,111 dragon_breath=14,112 paralysis_stone=11,113 spells=13,114 wands=12115 ),116 spell_slots_set=SpellSlotSet(level_1=3, level_2=2, level_3=2)117 ),118 Level(119 value=7,120 attack_bonus=3,121 experience_required=80000,122 hit_dice=dice.D4(7),123 saving_throws_set=SavingThrowSet(124 death_poison=12,125 dragon_breath=14,126 paralysis_stone=11,127 spells=13,128 wands=12129 ),130 spell_slots_set=SpellSlotSet(level_1=3, level_2=2, level_3=2, level_4=1)131 ),132 Level(133 value=8,134 attack_bonus=3,135 experience_required=150000,136 hit_dice=dice.D4(8),137 saving_throws_set=SavingThrowSet(138 death_poison=11,139 dragon_breath=14,140 paralysis_stone=10,141 spells=12,142 wands=11143 ),144 spell_slots_set=SpellSlotSet(level_1=3, level_2=3, level_3=2, level_4=2)145 ),146 Level(147 value=9,148 attack_bonus=4,149 experience_required=300000,150 hit_dice=dice.D4(9),151 saving_throws_set=SavingThrowSet(152 death_poison=11,153 dragon_breath=14,154 paralysis_stone=10,155 spells=12,156 wands=11157 ),158 spell_slots_set=SpellSlotSet(level_1=3, level_2=3, level_3=2, level_4=2, level_5=1)159 ),160 Level(161 value=10,162 attack_bonus=4,163 experience_required=450000,164 hit_dice=dice.D4(9),165 hit_dice_flat_bonus=1,166 saving_throws_set=SavingThrowSet(167 death_poison=11,168 dragon_breath=13,169 paralysis_stone=9,170 spells=11,171 wands=10172 ),173 spell_slots_set=SpellSlotSet(level_1=4, level_2=3, level_3=3, level_4=2, level_5=2)174 ),175 Level(176 value=11,177 attack_bonus=4,178 experience_required=600000,179 hit_dice=dice.D4(9),180 hit_dice_flat_bonus=2,181 saving_throws_set=SavingThrowSet(182 death_poison=11,183 dragon_breath=13,184 paralysis_stone=9,185 spells=11,186 wands=10187 ),188 spell_slots_set=SpellSlotSet(level_1=4, level_2=4, level_3=3, level_4=2, level_5=2, level_6=1)189 ),190 Level(191 value=12,192 attack_bonus=4,193 experience_required=750000,194 hit_dice=dice.D4(9),195 hit_dice_flat_bonus=3,196 saving_throws_set=SavingThrowSet(197 death_poison=10,198 dragon_breath=13,199 paralysis_stone=9,200 spells=11,201 wands=10202 ),203 spell_slots_set=SpellSlotSet(level_1=4, level_2=4, level_3=3, level_4=3, level_5=2, level_6=2)204 ),205 Level(206 value=13,207 attack_bonus=5,208 experience_required=900000,209 hit_dice=dice.D4(9),210 hit_dice_flat_bonus=4,211 saving_throws_set=SavingThrowSet(212 death_poison=10,213 dragon_breath=13,214 paralysis_stone=9,215 spells=11,216 wands=10217 ),218 spell_slots_set=SpellSlotSet(level_1=4, level_2=4, level_3=4, level_4=3, level_5=2, level_6=2)219 ),220 Level(221 value=14,222 attack_bonus=5,223 experience_required=1050000,224 hit_dice=dice.D4(9),225 hit_dice_flat_bonus=5,226 saving_throws_set=SavingThrowSet(227 death_poison=10,228 dragon_breath=12,229 paralysis_stone=8,230 spells=10,231 wands=9232 ),233 spell_slots_set=SpellSlotSet(level_1=4, level_2=4, level_3=4, level_4=3, level_5=3, level_6=2)234 ),235 Level(236 value=15,237 attack_bonus=5,238 experience_required=1200000,239 hit_dice=dice.D4(9),240 hit_dice_flat_bonus=6,241 saving_throws_set=SavingThrowSet(242 death_poison=10,243 dragon_breath=12,244 paralysis_stone=8,245 spells=10,246 wands=9247 ),248 spell_slots_set=SpellSlotSet(level_1=5, level_2=4, level_3=4, level_4=3, level_5=3, level_6=2)249 ),250 Level(251 value=16,252 attack_bonus=6,253 experience_required=1350000,254 hit_dice=dice.D4(9),255 hit_dice_flat_bonus=7,256 saving_throws_set=SavingThrowSet(257 death_poison=9,258 dragon_breath=12,259 paralysis_stone=7,260 spells=9,261 wands=8262 ),263 spell_slots_set=SpellSlotSet(level_1=5, level_2=5, level_3=4, level_4=3, level_5=3, level_6=2)264 ),265 Level(266 value=17,267 attack_bonus=6,268 experience_required=1500000,269 hit_dice=dice.D4(9),270 hit_dice_flat_bonus=8,271 saving_throws_set=SavingThrowSet(272 death_poison=9,273 dragon_breath=12,274 paralysis_stone=7,275 spells=9,276 wands=8277 ),278 spell_slots_set=SpellSlotSet(level_1=5, level_2=5, level_3=4, level_4=4, level_5=3, level_6=3)279 ),280 Level(281 value=18,282 attack_bonus=6,283 experience_required=1650000,284 hit_dice=dice.D4(9),285 hit_dice_flat_bonus=9,286 saving_throws_set=SavingThrowSet(287 death_poison=9,288 dragon_breath=11,289 paralysis_stone=6,290 spells=9,291 wands=7292 ),293 spell_slots_set=SpellSlotSet(level_1=6, level_2=5, level_3=4, level_4=4, level_5=3, level_6=3)294 ),295 Level(296 value=19,297 attack_bonus=7,298 experience_required=1800000,299 hit_dice=dice.D4(9),300 hit_dice_flat_bonus=10,301 saving_throws_set=SavingThrowSet(302 death_poison=9,303 dragon_breath=11,304 paralysis_stone=6,305 spells=9,306 wands=7307 ),308 spell_slots_set=SpellSlotSet(level_1=6, level_2=5, level_3=5, level_4=4, level_5=3, level_6=3)309 ),310 Level(311 value=20,312 attack_bonus=7,313 experience_required=1950000,314 hit_dice=dice.D4(9),315 hit_dice_flat_bonus=11,316 saving_throws_set=SavingThrowSet(317 death_poison=8,318 dragon_breath=11,319 paralysis_stone=5,320 spells=8,321 wands=6322 ),323 spell_slots_set=SpellSlotSet(level_1=6, level_2=5, level_3=5, level_4=4, level_5=4, level_6=3)324 )325 )...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...15import json16# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!17Window.size = (720*0.7, 1280*0.7)18# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!19def load_level(index):20 try:21 with open("data/levels.json") as f:22 levels = json.load(f)23 return levels[str(index)]24 except Exception as e:25 print("error loading levels", e)26def get_save_data():27 try:28 with open("data/save.json") as f:29 d = json.load(f)30 return [d["index_of_actual_level"], d["maximum_level"]]31 except Exception as e:32 print("error loading data", e)33def save_data(index, max_):34 try:35 with open("data/save.json", "w") as f:36 d = {37 "index_of_actual_level":index,38 "maximum_level":max_39 }40 json.dump(d, f, indent=2)41 except Exception as e:42 print("error saving data", e) 43level_index = 144SOUNDS = {45 "btn":SoundLoader.load("data/sounds/debili/btn.wav"),46 "restart":SoundLoader.load("data/sounds/debili/restart.wav"),47 "win":SoundLoader.load("data/sounds/debili/win.wav"),48 "step":SoundLoader.load("data/sounds/debili/step.wav")49}50class GamePad:51 def __init__(self, sc, par=None):52 self.source="data/images/gamepad.png"53 self.size=sc[0]*0.554 self.pos=[sc[0]*0.25, sc[1]*0.1]55 self.par=par56 def update(self):57 Rectangle(source=self.source, pos=self.pos, size=[self.size, self.size])58 def on_touch(self, touch):59 pos=touch.pos60 size_of_btn=self.size/361 if ((pos[0] > self.pos[0]+size_of_btn) and (pos[0] < self.pos[0]+size_of_btn*2) and62 (pos[1] > self.pos[1]+size_of_btn*2) and (pos[1] < self.pos[1]+self.size)):63 self.par.move("w",0,1)64 if ((pos[0] > self.pos[0]+size_of_btn) and (pos[0] < self.pos[0]+size_of_btn*2) and65 (pos[1] > self.pos[1]) and (pos[1] < self.pos[1]+size_of_btn)):66 self.par.move("s",0,-1)67 if ((pos[0] > self.pos[0]+size_of_btn*2) and (pos[0] < self.pos[0]+self.size) and68 (pos[1] > self.pos[1]+size_of_btn) and (pos[1] < self.pos[1]+size_of_btn*2)):69 self.par.move("d",1,0)70 if ((pos[0] > self.pos[0]) and (pos[0] < self.pos[0]+size_of_btn) and71 (pos[1] > self.pos[1]+size_of_btn) and (pos[1] < self.pos[1]+size_of_btn*2)):72 self.par.move("a",-1,0)73class GameWindow(Screen):74 def __init__(self, **kwargs):75 super().__init__(**kwargs)76 self.sc = Window.size77 self.update_all = False78 self.level_id, self.max_level = level_index, get_save_data()[1]79 self.level = load_level(self.level_id)80 self.level["map"].reverse()81 self.blocks = {"g":0, "p":7, "w":4, "b":2, "c":9, "e":3}82 self.gp = GamePad(sc=self.sc, par=self)83 self.button = {"pos":(0, self.sc[1]*0.95), "size":(self.sc[0]*0.1, self.sc[1]*0.05), "source":"data/images/button.png"}84 self.button__menu_content = BoxLayout(orientation='vertical')85 self.button__menu_content.add_widget(Button(text="restart", size_hint=(1, 0.5), on_press=self.restart))86 self.button__menu_content.add_widget(Button(text="menu",size_hint=(1, 0.5), on_press=self.menu))87 self.button_menu = Popup(title='Options:',content=self.button__menu_content, size_hint=(0.6,0.4))88 Clock.schedule_interval(self.update,1/30)89 def on_enter(self, *args):90 super().on_enter(*args)91 self.level_id=level_index92 self.set_level()93 self.update_all = True94 def update(self, dt):95 if self.update_all:96 self.clear_widgets()97 self.canvas.clear()98 # print(1/dt)99 with self.canvas:100 for i in range(self.level["size"][0]):101 for j in range(self.level["size"][1]):102 if self.level["map"][i][j] != self.blocks["e"]:103 if self.level["map"][i][j] == self.blocks["g"]:104 t = "g"105 elif self.level["map"][i][j] == self.blocks["p"]:106 t = "p"107 elif self.level["map"][i][j] == self.blocks["w"]:108 t = "w"109 elif self.level["map"][i][j] == self.blocks["b"]:110 t = "b"111 elif self.level["map"][i][j] == self.blocks["c"]:112 t = "c"113 source = f"data/images/{t}.png"114 # source = f"data/images/debili/{t}.png"115 Rectangle(source=source, size=self.tile_size, 116 pos=[self.tile_offset[0]+self.tile_size[0]*j, self.tile_offset[1]+self.tile_size[1]*i])117 Rectangle(pos=self.button["pos"], size=self.button["size"], source=self.button["source"])118 self.gp.update()119 if self.check():120 SOUNDS["win"].play()121 if self.level_id<self.max_level:122 self.level_id+=1123 self.set_level()124 if get_save_data()[0]<self.max_level and self.level_id>get_save_data()[0]:125 save_data(self.level_id, self.max_level)126 else:127 self.menu()128 def check(self):129 box_right_count = 0130 box_places = self.level["box_places"]131 level = self.level["map"]132 for b_p in box_places:133 if level[b_p[0]][b_p[1]]==self.blocks["b"]:134 box_right_count+=1135 136 if box_right_count==(len(box_places)):137 return True138 return False139 def set_level(self):140 self.level = load_level(self.level_id)141 self.level["map"].reverse()142 if self.level["size"][0]>self.level["size"][1]:143 self.tile_size = [144 self.sc[0]*(1/(self.level["size"][0]+2)),145 self.sc[0]*(1/(self.level["size"][0]+2))146 ]147 else:148 self.tile_size = [149 self.sc[0]*(1/(self.level["size"][1]+2)),150 self.sc[0]*(1/(self.level["size"][1]+2))151 ]152 self.tile_offset = [153 (self.sc[0]*0.5)-((self.level["size"][1])*self.tile_size[0])*0.5,154 self.sc[1]*0.4+((self.sc[1]*0.6)*0.5)-(self.level["size"][0]*self.tile_size[1])*0.5155 ]156 157 def get_obj(self, x, y):158 pl_pos = self.level["player_pos"]159 return self.level["map"][pl_pos[0]+y][pl_pos[1]+x]160 def move_all(self, x, y, box_pos=[0, 0], box=False):161 pl_pos = self.level["player_pos"]162 box_places = self.level["box_places"]163 level = self.level["map"]164 if box:165 level[pl_pos[0]+box_pos[1]][pl_pos[1]+box_pos[0]] = self.blocks["b"]166 level[pl_pos[0]][pl_pos[1]] = self.blocks["g"]167 level[pl_pos[0]+y][pl_pos[1]+x] = self.blocks["p"]168 self.level["player_pos"] = [pl_pos[0]+y, pl_pos[1]+x]169 SOUNDS["step"].play()170 for box_place in box_places:171 if (level[box_place[0]][box_place[1]] == self.blocks["b"]) or (level[box_place[0]][box_place[1]] == self.blocks["p"]):172 pass173 else:174 level[box_place[0]][box_place[1]] = self.blocks["c"]175 def move(self, dr, x, y, *a):176 obj = self.get_obj(x, y)177 if obj == self.blocks["g"] or obj == self.blocks["c"]:178 self.move_all(x, y)179 elif obj == self.blocks["b"]:180 if dr == "a":181 if self.get_obj(-2, 0) == self.blocks["g"] or self.get_obj(-2, 0) == self.blocks["c"]:182 self.move_all(-1, 0, box=True, box_pos=[-2, 0])183 elif dr == "d":184 if self.get_obj(2, 0) == self.blocks["g"] or self.get_obj(2, 0) == self.blocks["c"]:185 self.move_all(1, 0, box=True, box_pos=[2, 0])186 elif dr == "w":187 if self.get_obj(0, 2) == self.blocks["g"] or self.get_obj(0, 2) == self.blocks["c"]:188 self.move_all(0, 1, box=True, box_pos=[0, 2])189 190 elif dr == "s":191 if self.get_obj(0, -2) == self.blocks["g"] or self.get_obj(0, -2) == self.blocks["c"]:192 self.move_all(0, -1, box=True, box_pos=[0, -2])193 def restart(self, *a):194 self.button_menu.dismiss()195 self.level = load_level(self.level_id)196 self.level["map"].reverse()197 SOUNDS["btn"].play()198 def menu(self, *a):199 self.button_menu.dismiss()200 self.parent.current = "menu"201 self.update_all=False202 self.restart()203 SOUNDS["btn"].play()204 def on_touch_down(self, touch):205 super().on_touch_down(touch)206 self.gp.on_touch(touch=touch)207 if ((touch.pos[0]>self.button["pos"][0] and touch.pos[0]<self.button["pos"][0]+self.button["size"][0]) and208 (touch.pos[1]>self.button["pos"][1] and touch.pos[1]<self.button["pos"][1]+self.button["size"][1])):209 self.button_menu.open()210 SOUNDS["btn"].play()211class LevelWindow(Screen):212 levels_layout = ObjectProperty(None)213 def __init__(self, **kw):214 super().__init__(**kw)215 self.sc = Window.size216 def on_enter(self):217 self.levels_layout.clear_widgets()218 unlocked_level, level_count = get_save_data()219 for level_index in range(level_count):220 if level_index+1>unlocked_level:221 l = "Locked"222 else:223 l = "Unlocked"224 self.levels_layout.add_widget(Button(font_size=self.sc[0]//18,text=f"Level:{level_index+1}\n{l}", 225 on_press=partial(self.play_level, level_index+1, l)))226 def play_level(self, li, l, *a):227 if l == "Unlocked":228 global level_index229 self.parent.current="game"230 level_index=li231 self.play_music()232 233 def play_music(self):234 SOUNDS["btn"].play()235class MenuWindow(Screen):236 def __init__(self, **kw):237 super().__init__(**kw)238 def play_music(self):239 SOUNDS["btn"].play()240class WindowManager(ScreenManager):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful