Ejemplo n.º 1
0
    def test_interval_adjustment(self):
        """Ensure the interval is adjusted to account for task duration"""
        self.num_runs = 3

        now = datetime.datetime.utcnow()
        second = datetime.timedelta(seconds=1)
        smidgen = datetime.timedelta(microseconds=10000)
        timeoverrides = [
            now, now + second - smidgen, now, now + second + second, now,
            now + second + smidgen
        ]

        m = mox.Mox()
        m.StubOutWithMock(greenthread, 'sleep')
        greenthread.sleep(mox.IsAlmost(0.02))
        greenthread.sleep(mox.IsAlmost(0.0))
        greenthread.sleep(mox.IsAlmost(0.0))
        m.ReplayAll()

        try:
            timeutils.set_time_override(timeoverrides)
            timer = loopingcall.LoopingCall(self._wait_for_zero)
            timer.start(interval=1.01).wait()
        finally:
            timeutils.clear_time_override()
            m.UnsetStubs()
            m.VerifyAll()
Ejemplo n.º 2
0
  def testNonNumericTypes(self):
    """Verify that IsAlmost handles non-numeric types properly."""

    self.assertNotEquals(mox.IsAlmost(1.8999999999), '1.9')
    self.assertNotEquals(mox.IsAlmost('1.8999999999'), 1.9)
    self.assertNotEquals(mox.IsAlmost('1.8999999999'), '1.9')
Ejemplo n.º 3
0
 def testEqualityWithPlaces(self):
   """Verify that specifying places has the desired effect."""
   self.assertNotEquals(mox.IsAlmost(1.899), 1.9)
   self.assertEquals(mox.IsAlmost(1.899, places=2), 1.9)
Ejemplo n.º 4
0
 def testEqualityInvalid(self):
   """Verify that == correctly identifies non-equivalent floats."""
   self.assertNotEquals(mox.IsAlmost(1.899), 1.9)
Ejemplo n.º 5
0
def IsSeconds(float_value):
    """Return a mox comparator that checks 6 decimal places, intended to be
    used for comparing seconds."""
    return mox.IsAlmost(float_value, 6)