Example #1
0
 def test_custom_status_and_exception(self):
   counter = mock.Mock(metrics.CounterMetric)
   with self.assertRaises(Exception):
     with helpers.ScopedIncrementCounter(counter) as sc:
       sc.set_status('foo')
       raise Exception()
   counter.increment.assert_called_once_with({'status': 'foo'})
Example #2
0
 def test_custom_label_exception(self):
   counter = mock.Mock(metrics.CounterMetric)
   with self.assertRaises(Exception):
     with helpers.ScopedIncrementCounter(counter, 'a', 'b', 'c'):
       raise Exception()
   counter.increment.assert_called_once_with({'a': 'c'})
Example #3
0
 def test_custom_label_success(self):
   counter = mock.Mock(metrics.CounterMetric)
   with helpers.ScopedIncrementCounter(counter, 'a', 'b', 'c'):
     pass
   counter.increment.assert_called_once_with({'a': 'b'})
Example #4
0
 def test_multiple_custom_status_calls(self):
   counter = mock.Mock(metrics.CounterMetric)
   with helpers.ScopedIncrementCounter(counter) as sc:
     sc.set_status('foo')
     sc.set_status('bar')
   counter.increment.assert_called_once_with({'status': 'bar'})
Example #5
0
 def test_set_failure(self):
   counter = mock.Mock(metrics.CounterMetric)
   with helpers.ScopedIncrementCounter(counter) as sc:
     sc.set_failure()
   counter.increment.assert_called_once_with({'status': 'failure'})
Example #6
0
 def test_exception(self):
   counter = mock.Mock(metrics.CounterMetric)
   with self.assertRaises(Exception):
     with helpers.ScopedIncrementCounter(counter):
       raise Exception()
   counter.increment.assert_called_once_with({'status': 'failure'})
Example #7
0
 def test_success(self):
   counter = mock.Mock(metrics.CounterMetric)
   with helpers.ScopedIncrementCounter(counter):
     pass
   counter.increment.assert_called_once_with({'status': 'success'})