Exemple #1
0
 def testNonNumber(self):
     """Tests the function with non-numeric arguments."""
     try:
         util.stringFromTimePeriod('foo')
     except TypeError:
         pass
     else:
         self.fail()
Exemple #2
0
 def testNegative(self):
     """Tests the function with negative arguments."""
     for argument in (-1, -0.1):
         try:
             util.stringFromTimePeriod(argument)
         except ValueError:
             pass
         else:
             self.fail()
Exemple #3
0
    def _update(self):
        """
        Updates the progress widgets with the latest progress information.
        """
        if self._calibrationManager == None:
            return False   # We're done; the timeout can be removed.

        progress = self._calibrationManager.getExtendedProgress()
        stageProgress, stageTimeLeft, totalProgress, totalTimeLeft = progress

        state = self._calibrationManager.state

        if state == STATE_MOVING_HEATER:
            action = gettext('Moving the heater forwards')
        elif state in (STATE_HEATING, STATE_WAITING_FOR_TEMPERATURE):
            current = self._calibrationManager.system.heatingCurrent
            current = util.stringFromFloat(current, 8, True)
            action = gettext('Heating with %s mA') % current
        else:
            assert False

        assert 0.0 <= stageProgress <= 1.0
        assert 0.0 <= totalProgress <= 1.0

        stageProgressText = '%d%%' % (round(stageProgress * 100))
        totalProgressText = '%d%%' % (round(totalProgress * 100))

        for bar, showText in self.stageProgressBars:
            bar.set_fraction(stageProgress)
            if showText:
                bar.set_text(stageProgressText)

        for bar, showText in self.totalProgressBars:
            bar.set_fraction(totalProgress)
            if showText:
                bar.set_text(totalProgressText)

        if stageTimeLeft == None:
            stageTimeLeftText = gettext('unknown')
        else:
            stageTimeLeftText = util.stringFromTimePeriod(stageTimeLeft)

        if totalTimeLeft == None:
            totalTimeLeftText = gettext('unknown')
        else:
            totalTimeLeftText = util.stringFromTimePeriod(totalTimeLeft)

        substitutions = {
            'action':        action,
            'stageProgress': stageProgressText,
            'stageTimeLeft': stageTimeLeftText,
            'totalProgress': totalProgressText,
            'totalTimeLeft': totalTimeLeftText,
            'emptyString':   ''}

        for label, template, noTimeTemplate in self.progressLabels:
            if stageTimeLeft == None or totalTimeLeft == None:
                label.set_text(noTimeTemplate % substitutions)
            else:
                label.set_text(template % substitutions)

        return True   # This method should be called again.
Exemple #4
0
 def testFloat(self):
     """Tests the function with float arguments."""
     for seconds, expected in self.TESTS:
         if seconds > 0:
             seconds -= 0.9
             self.assertEqual(util.stringFromTimePeriod(seconds), expected)
Exemple #5
0
 def testInteger(self):
     """Tests the function with integer arguments."""
     for seconds, expected in self.TESTS:
         self.assertEqual(util.stringFromTimePeriod(seconds), expected)