def test_raise_on_float(self): derived_cumulative = cumulative.DerivedLongCumulative( Mock(), Mock(), Mock(), []) mock_fn = Mock() mock_fn.return_value = 1.125 point = derived_cumulative.create_default_time_series(mock_fn) with self.assertRaises(ValueError): point.get_value()
def test_point_value_increases(self): derived_cumulative = cumulative.DerivedLongCumulative( Mock(), Mock(), Mock(), []) mock_fn = Mock() point = derived_cumulative.create_default_time_series(mock_fn) mock_fn.return_value = -10 self.assertEqual(point.get_value(), 0) mock_fn.return_value = 10 self.assertEqual(point.get_value(), 10) mock_fn.return_value = 9 self.assertEqual(point.get_value(), 10)
def test_get_metric(self): derived_cumulative = cumulative.DerivedLongCumulative( Mock(), Mock(), Mock(), []) mock_fn = Mock() mock_fn.return_value = 123 derived_cumulative.create_default_time_series(mock_fn) now1 = Mock() [ts] = derived_cumulative.get_metric(now1).time_series [ts_point] = ts.points self.assertEqual(ts_point.timestamp, now1) self.assertEqual(ts_point.value.value, 123) self.assertIsInstance(ts_point.value, value_module.ValueLong)
def test_ts_point_type(self): derived_cumulative = cumulative.DerivedLongCumulative( Mock(), Mock(), Mock(), [Mock(), Mock]) mock_fn = Mock() default_point = derived_cumulative.create_default_time_series(mock_fn) self.assertIsInstance(default_point, gauge.DerivedGaugePoint) self.assertIsInstance(default_point.gauge_point, cumulative.CumulativePointLong) mock_fn.assert_not_called() point = derived_cumulative.create_time_series( [Mock(), Mock()], mock_fn) self.assertIsInstance(point, gauge.DerivedGaugePoint) self.assertIsInstance(point.gauge_point, cumulative.CumulativePointLong) mock_fn.assert_not_called()