@@ -559,65 +559,97 @@ def test_list_easyblocks(self):
559559 def test_search (self ):
560560 """Test searching for easyconfigs."""
561561
562- fd , dummylogfn = tempfile .mkstemp (prefix = 'easybuild-dummy' , suffix = '.log' )
563- os .close (fd )
562+ test_easyconfigs_dir = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'easyconfigs' )
564563
564+ # simple search
565565 args = [
566566 '--search=gzip' ,
567- '--robot=%s' % os .path .join (os .path .dirname (__file__ ), 'easyconfigs' ),
568- '--unittest-file=%s' % self .logfile ,
567+ '--robot=%s' % test_easyconfigs_dir ,
569568 ]
570- self .eb_main (args , logfile = dummylogfn )
571- logtxt = read_file (self .logfile )
569+ self .mock_stdout (True )
570+ self .eb_main (args , testing = False )
571+ txt = self .get_stdout ()
572+ self .mock_stdout (False )
572573
573574 info_msg = r"Searching \(case-insensitive\) for 'gzip' in"
574- self .assertTrue (re .search (info_msg , logtxt ), "Info message when searching for easyconfigs in '%s'" % logtxt )
575+ self .assertTrue (re .search (info_msg , txt ), "Info message when searching for easyconfigs in '%s'" % txt )
575576 for ec in ["gzip-1.4.eb" , "gzip-1.4-GCC-4.6.3.eb" ]:
576- self .assertTrue (re .search (r" \* \S*%s$" % ec , logtxt , re .M ), "Found easyconfig %s in '%s'" % (ec , logtxt ))
577-
578- if os .path .exists (dummylogfn ):
579- os .remove (dummylogfn )
580-
581- write_file (self .logfile , '' )
577+ regex = re .compile (r" \* \S*%s$" % ec , re .M )
578+ self .assertTrue (regex .search (txt ), "Found pattern '%s' in: %s" % (regex .pattern , txt ))
582579
580+ # search w/ regex
583581 args = [
584582 '--search=^gcc.*2.eb' ,
585- '--robot=%s' % os .path .join (os .path .dirname (__file__ ), 'easyconfigs' ),
586- '--unittest-file=%s' % self .logfile ,
583+ '--robot=%s' % test_easyconfigs_dir ,
587584 ]
588- self .eb_main (args , logfile = dummylogfn )
589- logtxt = read_file (self .logfile )
585+ self .mock_stdout (True )
586+ self .eb_main (args , testing = False )
587+ txt = self .get_stdout ()
588+ self .mock_stdout (False )
590589
591590 info_msg = r"Searching \(case-insensitive\) for '\^gcc.\*2.eb' in"
592- self .assertTrue (re .search (info_msg , logtxt ), "Info message when searching for easyconfigs in '%s'" % logtxt )
591+ self .assertTrue (re .search (info_msg , txt ), "Info message when searching for easyconfigs in '%s'" % txt )
593592 for ec in ['GCC-4.7.2.eb' , 'GCC-4.8.2.eb' , 'GCC-4.9.2.eb' ]:
594- self .assertTrue (re .search (r" \* \S*%s$" % ec , logtxt , re .M ), "Found easyconfig %s in '%s'" % (ec , logtxt ))
593+ regex = re .compile (r" \* \S*%s$" % ec , re .M )
594+ self .assertTrue (regex .search (txt ), "Found pattern '%s' in: %s" % (regex .pattern , txt ))
595595
596- if os .path .exists (dummylogfn ):
597- os .remove (dummylogfn )
596+ gcc_ecs = [
597+ 'GCC-4.6.3.eb' ,
598+ 'GCC-4.6.4.eb' ,
599+ 'GCC-4.7.2.eb' ,
600+ 'GCC-4.8.2.eb' ,
601+ 'GCC-4.8.3.eb' ,
602+ 'GCC-4.9.2.eb' ,
603+ ]
598604
599- write_file (self .logfile , '' )
605+ # test --search-filename
606+ args = [
607+ '--search-filename=^gcc' ,
608+ '--robot=%s' % test_easyconfigs_dir ,
609+ ]
610+ self .mock_stdout (True )
611+ self .eb_main (args , testing = False )
612+ txt = self .get_stdout ()
613+ self .mock_stdout (False )
614+
615+ for ec in gcc_ecs :
616+ regex = re .compile (r"^ \* %s$" % ec , re .M )
617+ self .assertTrue (regex .search (txt ), "Found pattern '%s' in: %s" % (regex .pattern , txt ))
600618
619+ # test --search-filename --terse
620+ args = [
621+ '--search-filename=^gcc' ,
622+ '--terse' ,
623+ '--robot=%s' % test_easyconfigs_dir ,
624+ ]
625+ self .mock_stdout (True )
626+ self .eb_main (args , testing = False )
627+ txt = self .get_stdout ()
628+ self .mock_stdout (False )
629+
630+ for ec in gcc_ecs :
631+ regex = re .compile (r"^%s$" % ec , re .M )
632+ self .assertTrue (regex .search (txt ), "Found pattern '%s' in: %s" % (regex .pattern , txt ))
633+
634+ # also test --search-short/-S
601635 for search_arg in ['-S' , '--search-short' ]:
602- open (self .logfile , 'w' ).write ('' )
603636 args = [
604637 search_arg ,
605638 'toy-0.0' ,
606639 '-r' ,
607- os .path .join (os .path .dirname (__file__ ), 'easyconfigs' ),
608- '--unittest-file=%s' % self .logfile ,
640+ test_easyconfigs_dir ,
609641 ]
610- self .eb_main (args , logfile = dummylogfn , raise_error = True , verbose = True )
611- logtxt = read_file (self .logfile )
642+ self .mock_stdout (True )
643+ self .eb_main (args , raise_error = True , verbose = True , testing = False )
644+ txt = self .get_stdout ()
645+ self .mock_stdout (False )
612646
613647 info_msg = r"Searching \(case-insensitive\) for 'toy-0.0' in"
614- self .assertTrue (re .search (info_msg , logtxt ), "Info message when searching for easyconfigs in '%s'" % logtxt )
615- self .assertTrue (re .search ('INFO CFGS\d+=' , logtxt ), "CFGS line message found in '%s'" % logtxt )
648+ self .assertTrue (re .search (info_msg , txt ), "Info message when searching for easyconfigs in '%s'" % txt )
649+ self .assertTrue (re .search ('^ CFGS\d+=' , txt , re . M ), "CFGS line message found in '%s'" % txt )
616650 for ec in ["toy-0.0.eb" , "toy-0.0-multiple.eb" ]:
617- self .assertTrue (re .search (" \* \$CFGS\d+/*%s" % ec , logtxt ), "Found easyconfig %s in '%s'" % (ec , logtxt ))
618-
619- if os .path .exists (dummylogfn ):
620- os .remove (dummylogfn )
651+ regex = re .compile (r" \* \$CFGS\d+/*%s" % ec , re .M )
652+ self .assertTrue (regex .search (txt ), "Found pattern '%s' in: %s" % (regex .pattern , txt ))
621653
622654 def test_dry_run (self ):
623655 """Test dry run (long format)."""
0 commit comments