def test_empty_timedata(self): path = os.path.join(self.tmp_root, 'job-name') self.assertFalse(os.path.exists(path)) self.assertFalse(os.path.exists(path + '.tmp')) td = model.JobTimeData(path) self.assertEqual(td.success_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.assertEqual(td.failure_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.assertEqual(td.results, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
def test_save_reload(self): path = os.path.join(self.tmp_root, 'job-name') self.assertFalse(os.path.exists(path)) self.assertFalse(os.path.exists(path + '.tmp')) td = model.JobTimeData(path) self.assertEqual(td.success_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.assertEqual(td.failure_times, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.assertEqual(td.results, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) success_times = [] failure_times = [] results = [] for x in range(10): success_times.append(int(random.random() * 1000)) failure_times.append(int(random.random() * 1000)) results.append(0) results.append(1) random.shuffle(results) s = f = 0 for result in results: if result: td.add(failure_times[f], 'FAILURE') f += 1 else: td.add(success_times[s], 'SUCCESS') s += 1 self.assertEqual(td.success_times, success_times) self.assertEqual(td.failure_times, failure_times) self.assertEqual(td.results, results[10:]) td.save() self.assertTrue(os.path.exists(path)) self.assertFalse(os.path.exists(path + '.tmp')) td = model.JobTimeData(path) td.load() self.assertEqual(td.success_times, success_times) self.assertEqual(td.failure_times, failure_times) self.assertEqual(td.results, results[10:])