~maddevelopers/mg5amcnlo/2.7.1.3

« back to all changes in this revision

Viewing changes to tests/unit_tests/various/test_banner.py

  • Committer: olivier-mattelaer
  • Date: 2017-03-08 22:47:41 UTC
  • mfrom: (269.1.40 2.5.3)
  • Revision ID: olivier-mattelaer-20170308224741-vvle7s0u2541viuw
pass to 2.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
440
440
        read_PY8Card=bannermod.PY8Card(out)
441
441
        self.assertEqual(modified_PY8Card, read_PY8Card)
442
442
 
 
443
import shutil
443
444
class TestRunCard(unittest.TestCase):
444
445
    """ A class to test the TestConfig functionality """
445
446
    # a lot of the funtionality are actually already tested in the child
446
447
    # TESTMadLoopParam and are not repeated here.
447
 
     
 
448
    debugging=False
 
449
 
 
450
    def setUp(self):
 
451
        
 
452
        if not self.debugging:
 
453
            self.tmpdir = tempfile.mkdtemp(prefix='amc')
 
454
            #if os.path.exists(self.tmpdir):
 
455
            #    shutil.rmtree(self.tmpdir)
 
456
            #os.mkdir(self.tmpdir)
 
457
        else:
 
458
            if os.path.exists(pjoin(MG5DIR, 'TEST_AMC')):
 
459
                shutil.rmtree(pjoin(MG5DIR, 'TEST_AMC'))
 
460
            os.mkdir(pjoin(MG5DIR, 'TEST_AMC'))
 
461
            self.tmpdir = pjoin(MG5DIR, 'TEST_AMC')
 
462
            
 
463
    def tearDown(self):
 
464
        if not self.debugging:
 
465
            shutil.rmtree(self.tmpdir)
448
466
        
449
467
    def test_basic(self):
450
468
        """ """
481
499
        self.assertTrue(hasattr(run_card2, 'cuts_parameter'))   
482
500
              
483
501
  
 
502
        self.assertFalse(self.debugging)
 
503
 
484
504
    def test_default(self):
485
505
      
486
506
        run_card = bannermod.RunCard()
487
 
        fsock = tempfile.NamedTemporaryFile(mode = 'w')
 
507
#        fsock = tempfile.NamedTemporaryFile(mode = 'w')
 
508
        fsock = open(pjoin(self.tmpdir,'run_card_test'),'w')
488
509
        run_card.write(fsock)
489
 
      
 
510
        fsock.close()
490
511
        run_card2 = bannermod.RunCard(fsock.name)
491
512
      
492
513
        for key in run_card:
493
514
            self.assertEqual(run_card[key], run_card2[key])
494
515
      
495
516
        run_card = bannermod.RunCardNLO()
496
 
        fsock = tempfile.NamedTemporaryFile(mode = 'w')
 
517
#        fsock = tempfile.NamedTemporaryFile(mode = 'w')
 
518
        fsock = open(pjoin(self.tmpdir,'run_card_test2'),'w')
497
519
        run_card.write(fsock)
498
 
      
 
520
        fsock.close()
499
521
        #card should be identical if we do not run the consistency post-processing
500
522
        run_card2 = bannermod.RunCard(fsock.name, consistency=False)
501
523
        for key in run_card:
518
540
        self.assertTrue(has_userset)
519
541
        
520
542
        #write run_card3 and check that nothing is changed
521
 
        fsock2 = tempfile.NamedTemporaryFile(mode = 'w')
 
543
#        fsock2 = tempfile.NamedTemporaryFile(mode = 'w')
 
544
        fsock2 = open(pjoin(self.tmpdir,'run_card_test3'),'w')
522
545
        run_card3.write(fsock2)
523
 
        
 
546
        fsock2.close()
524
547
        self.assertEqual(open(fsock.name).read(), open(fsock2.name).read())
525
548
            
526
549