def test_ETAMeter(self): first_time = 1.0 second_time = 3.0 meter = optim.ETAMeter(1) meter.update(first_time) actual = meter.count desired = 0 self.assertEqual(actual, desired) actual = meter.last_time desired = first_time self.assertEqual(actual, desired) meter.update(second_time) actual = meter.count desired = 1 self.assertEqual(actual, desired) actual = meter.last_time desired = second_time self.assertEqual(actual, desired) actual = meter.last_val desired = second_time - first_time self.assertEqual(actual, desired)
def test_ETAMeter(): first_time = 1.0 second_time = 3.0 meter = optim.ETAMeter(1) meter.update(first_time) actual = meter.count desired = 0 assert actual == desired actual = meter.last_time desired = first_time assert actual == desired meter.update(second_time) actual = meter.count desired = 1 assert actual == desired actual = meter.last_time desired = second_time assert actual == desired actual = meter.last_val desired = second_time - first_time assert actual == desired
def test_ETAMeter_str_smoke(self): for show_local_eta in (True, False): meter = optim.ETAMeter(1, show_local_eta=show_local_eta) self.assertIsInstance(str(meter), str) meter.update(0.0) self.assertIsInstance(str(meter), str) meter.update(0.0) self.assertIsInstance(str(meter), str)
def test_ETAMeter_calculate_eta(self): meter = optim.ETAMeter(1) time_diff = 10.0 actual = meter.calculate_eta(time_diff) desired = datetime.now() + timedelta(seconds=time_diff) self.assertAlmostEqual(actual, desired, delta=timedelta(seconds=1.0)) meter.update(1.0) meter.update(2.0) actual = meter.calculate_eta(time_diff) desired = datetime.now() self.assertAlmostEqual(actual, desired, delta=timedelta(seconds=1.0))
def test_ETAMeter_calculate_eta(): meter = optim.ETAMeter(1) time_diff = 10.0 delta = time_diff / 2 actual = meter.calculate_eta(time_diff) desired = datetime.now() + timedelta(seconds=time_diff) assert_datetime_almost_equal(actual, desired, delta) meter.update(1.0) meter.update(2.0) actual = meter.calculate_eta(time_diff) desired = datetime.now() assert_datetime_almost_equal(actual, desired, delta)
def test_ProgressMeter_str_smoke(self): for name in (None, "progress_meter"): meter = optim.ETAMeter(1, name=name) self.assertIsInstance(str(meter), str) meter.update(0.0) self.assertIsInstance(str(meter), str)