def testTurbiniaStatsAddTask(self): """Tests TurbiniaStats.add_task() method.""" test_task = {'run_time': None, 'last_update': None} stats = TurbiniaStats() stats.add_task(test_task) self.assertIn(test_task, stats.tasks) self.assertEqual(stats.count, 1)
def testTurbiniaStatsCalculateStats(self): """Tests TurbiniaStats.calculateStats() method.""" last_update = datetime.now() test_task1 = { 'run_time': timedelta(minutes=3), 'last_update': last_update } test_task2 = { 'run_time': timedelta(minutes=5), 'last_update': last_update } test_task3 = { 'run_time': timedelta(minutes=1), 'last_update': last_update } stats = TurbiniaStats() stats.add_task(test_task1) stats.add_task(test_task2) stats.add_task(test_task3) stats.calculate_stats() self.assertEqual(stats.min, timedelta(minutes=1)) self.assertEqual(stats.mean, timedelta(minutes=3)) self.assertEqual(stats.max, timedelta(minutes=5)) self.assertEqual(stats.count, 3)
def testTurbiniaStatsFormatStatsCsv(self): """Tests TurbiniaStats.format_stats() returns valid CSV output.""" test_output = ('Test Task Results, 1, 0:03:00, 0:03:00, 0:03:00') test_task1 = { 'run_time': timedelta(minutes=3), 'last_update': datetime.now() } stats = TurbiniaStats('Test Task Results') stats.add_task(test_task1) stats.calculate_stats() report = stats.format_stats_csv() self.assertEqual(report, test_output)