예제 #1
0
    def test_time_take_to_generate_each_test_in_output( self ):
        from whip.beagleoptimiser import pretty_time
        with contextlib.nested(
                patch('whip.beagleoptimiser.get_available_beagle_options'),
                patch('whip.beagleoptimiser.estimate_beast_runtime'),
                patch('whip.beagleoptimiser.time'),
            ) as (p1, p2, p3):
            times = [random.random() for i in range(len(self.avail_options))]
            # Have to generate start and end
            gentimes = [i*i for i in range(len(self.avail_options)*2)]
            # Patch in avail options
            p1.return_value = self.avail_options
            # Patch in estimated times
            p2.side_effect = times
            # Patch in beast run times
            p3.time.side_effect = gentimes

            stringstream = StringIO()
            self._C( self.beastfiles[0], stream=stringstream )

            output = stringstream.getvalue()

            # We are only interested in estimate lines
            estlines = []
            for line in output.splitlines():
                if 'estimate:' in line:
                    estlines.append(line)

            # Now calculate all the time differences in gentimes
            gentimesdiff = []
            for i in range(0,len(gentimes),2):
                diff = (gentimes[i+1] - gentimes[i]) / 3600.0
                gentimesdiff.append(diff)

            # Pack up all the inputs with the actual output line
            # and then compare
            for esttime, option, gentime, outline in zip(
                    times, self.avail_options, gentimesdiff, estlines):
                expected = '{0} estimate: {1} (Time to generate: {2})'.format(
                    option, pretty_time(esttime), pretty_time(gentime)
                )
                eq_( expected, outline )
예제 #2
0
    def test_time_take_to_generate_each_test_in_output(self):
        from whip.beagleoptimiser import pretty_time
        with contextlib.nested(
                patch('whip.beagleoptimiser.get_available_beagle_options'),
                patch('whip.beagleoptimiser.estimate_beast_runtime'),
                patch('whip.beagleoptimiser.time'),
        ) as (p1, p2, p3):
            times = [random.random() for i in range(len(self.avail_options))]
            # Have to generate start and end
            gentimes = [i * i for i in range(len(self.avail_options) * 2)]
            # Patch in avail options
            p1.return_value = self.avail_options
            # Patch in estimated times
            p2.side_effect = times
            # Patch in beast run times
            p3.time.side_effect = gentimes

            stringstream = StringIO()
            self._C(self.beastfiles[0], stream=stringstream)

            output = stringstream.getvalue()

            # We are only interested in estimate lines
            estlines = []
            for line in output.splitlines():
                if 'estimate:' in line:
                    estlines.append(line)

            # Now calculate all the time differences in gentimes
            gentimesdiff = []
            for i in range(0, len(gentimes), 2):
                diff = (gentimes[i + 1] - gentimes[i]) / 3600.0
                gentimesdiff.append(diff)

            # Pack up all the inputs with the actual output line
            # and then compare
            for esttime, option, gentime, outline in zip(
                    times, self.avail_options, gentimesdiff, estlines):
                expected = '{0} estimate: {1} (Time to generate: {2})'.format(
                    option, pretty_time(esttime), pretty_time(gentime))
                eq_(expected, outline)
예제 #3
0
 def _C(self, *args, **kwargs):
     from whip.beagleoptimiser import pretty_time
     return pretty_time(*args, **kwargs)
예제 #4
0
 def _C( self, *args, **kwargs ):
     from whip.beagleoptimiser import pretty_time
     return pretty_time( *args, **kwargs )