def setUp(self): super(TestStatisticsManager, self).setUp() self.tmpfile = tempfile.gettempdir() + "/tstLibraTestStatsMgr.tmp" self.mgr = StatisticsManager(self.tmpfile)
class TestStatisticsManager(TestCase): def setUp(self): super(TestStatisticsManager, self).setUp() self.tmpfile = tempfile.gettempdir() + "/tstLibraTestStatsMgr.tmp" self.mgr = StatisticsManager(self.tmpfile) def tearDown(self): if os.path.exists(self.tmpfile): os.remove(self.tmpfile) super(TestStatisticsManager, self).tearDown() def testReadNoStatsFile(self): self.assertEquals(self.mgr.get_start(), None) self.assertEquals(self.mgr.get_end(), None) self.assertEquals(self.mgr.get_last_tcp_bytes(), 0) self.assertEquals(self.mgr.get_last_http_bytes(), 0) self.assertEquals(self.mgr.get_unreported_tcp_bytes(), 0) self.assertEquals(self.mgr.get_unreported_http_bytes(), 0) def testSave(self): start_ts = datetime.datetime(2013, 1, 31, 12, 10, 30, 123456) end_ts = start_ts + datetime.timedelta(minutes=5) tcp_bytes = 1024 http_bytes = 2048 unreported_tcp_bytes = 3000 unreported_http_bytes = 4000 self.mgr.save(start_ts, end_ts, tcp_bytes=tcp_bytes, http_bytes=http_bytes) self.mgr.read() self.assertEquals(self.mgr.get_start(), start_ts) self.assertEquals(self.mgr.get_end(), end_ts) self.assertEquals(self.mgr.get_last_tcp_bytes(), tcp_bytes) self.assertEquals(self.mgr.get_last_http_bytes(), http_bytes) self.assertEquals(self.mgr.get_unreported_tcp_bytes(), 0) self.assertEquals(self.mgr.get_unreported_http_bytes(), 0) self.mgr.save(start_ts, end_ts, unreported_tcp_bytes=unreported_tcp_bytes, unreported_http_bytes=unreported_http_bytes) self.mgr.read() self.assertEquals(self.mgr.get_start(), start_ts) self.assertEquals(self.mgr.get_end(), end_ts) self.assertEquals(self.mgr.get_last_tcp_bytes(), 0) self.assertEquals(self.mgr.get_last_http_bytes(), 0) self.assertEquals(self.mgr.get_unreported_tcp_bytes(), unreported_tcp_bytes) self.assertEquals(self.mgr.get_unreported_http_bytes(), unreported_http_bytes) self.mgr.save(start_ts, end_ts, tcp_bytes=tcp_bytes, http_bytes=http_bytes, unreported_tcp_bytes=unreported_tcp_bytes, unreported_http_bytes=unreported_http_bytes) self.mgr.read() self.assertEquals(self.mgr.get_start(), start_ts) self.assertEquals(self.mgr.get_end(), end_ts) self.assertEquals(self.mgr.get_last_tcp_bytes(), tcp_bytes) self.assertEquals(self.mgr.get_last_http_bytes(), http_bytes) self.assertEquals(self.mgr.get_unreported_tcp_bytes(), unreported_tcp_bytes) self.assertEquals(self.mgr.get_unreported_http_bytes(), unreported_http_bytes)