libra/tests/test_lbstats.py
David Shrewsbury af6bc02041 Worker stats should be longs not ints.
Change-Id: I2acb08d8de924a127c34e0667eea19c836066e98
2012-11-27 10:22:03 -05:00

40 lines
1.3 KiB
Python

import datetime
import unittest
from libra.common.lbstats import LBStatistics
class TestLBStatistics(unittest.TestCase):
def setUp(self):
self.stats = LBStatistics()
def tearDown(self):
pass
def testInitValues(self):
now = datetime.datetime.utcnow()
ts = self.stats.utc_timestamp
self.assertEquals(ts.year, now.year)
self.assertEquals(ts.month, now.month)
self.assertEquals(ts.day, now.day)
self.assertEquals(ts.hour, now.hour)
self.assertEquals(self.stats.bytes_out, 0L)
self.assertEquals(self.stats.bytes_in, 0L)
def testSetBytesIn(self):
self.stats.bytes_in = 99L
self.assertEquals(self.stats.bytes_in, 99L)
with self.assertRaises(TypeError):
self.stats.bytes_in = "NaN"
def testSetBytesOut(self):
self.stats.bytes_out = 100L
self.assertEquals(self.stats.bytes_out, 100L)
with self.assertRaises(TypeError):
self.stats.bytes_out = "NaN"
def testSetUTCTimestamp(self):
ts = datetime.datetime.utcnow()
self.stats.utc_timestamp = ts
self.assertEquals(self.stats.utc_timestamp, ts)
with self.assertRaises(TypeError):
self.stats.utc_timestamp = "2012-01-01 12:00:00"