Example #1
0
    def testEvent(self):
        result = []

        def callback(rate):
            result.append(rate)

        time = MockTime()
        band = Bandwidth(time)
        band.update_event.subscribe(callback)
        # rate should be 0
        band.calculate()

        band.increase(20)
        time.now = 2
        # rate should be 10
        band.calculate()

        self.assertAlmostEqual(result[0], 0)
        self.assertAlmostEqual(result[1], 10)
Example #2
0
    def testRate(self):
        time = MockTime()
        band = Bandwidth(time)
        # make sure first calculate should not generate error
        band.calculate()
        self.assertEqual(band.byte_rate, 0)

        band.increase(80)
        time.now = 2
        band.calculate()
        # 80/2 should be 40 Bps
        self.assertAlmostEqual(band.byte_rate, 40)

        bytes = 1000000
        time.now = 3
        band.increase(bytes)
        band.calculate()
        bits = bytes * 8
        mbps = bits / 1000000.0
        self.assertAlmostEqual(band.mbps, mbps)