Ejemplo n.º 1
0
 def test_get_to_point_value_gcd(self):
     get_10 = lambda: 10  # noqa
     point = gauge.DerivedGaugePoint(get_10, gauge.GaugePointLong())
     del get_10
     gc.collect()
     deleted_long_value = point.to_point_value()
     self.assertIsNone(deleted_long_value)
Ejemplo n.º 2
0
    def test_get_value_gcd(self):
        """Check handling deletion of the underlying func."""
        get_10 = lambda: 10  # noqa
        point = gauge.DerivedGaugePoint(get_10, gauge.GaugePointLong())

        value = point.get_value()
        self.assertEqual(value, 10)
        self.assertEqual(point.gauge_point.value, 10)

        del get_10
        gc.collect()
        deleted_value = point.get_value()
        self.assertIsNone(deleted_value)
        # Check that we don't null out the underlying point value
        self.assertEqual(point.gauge_point.value, 10)
Ejemplo n.º 3
0
    def test_get_value(self):
        mock_fn = Mock()
        mock_value = Mock(spec=int)
        mock_fn.return_value = mock_value

        point = gauge.DerivedGaugePoint(mock_fn, gauge.GaugePointLong())
        mock_fn.assert_not_called()

        value = point.get_value()
        self.assertEqual(value, mock_value)
        self.assertEqual(point.gauge_point.value, mock_value)
        mock_fn.assert_called_once()

        value = point.get_value()
        self.assertEqual(value, mock_value)
        self.assertEqual(point.gauge_point.value, mock_value)
        self.assertEqual(mock_fn.call_count, 2)