示例#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'})
示例#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'})
示例#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'})
示例#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'})
示例#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'})
示例#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'})
示例#7
0
 def test_success(self):
   counter = mock.Mock(metrics.CounterMetric)
   with helpers.ScopedIncrementCounter(counter):
     pass
   counter.increment.assert_called_once_with({'status': 'success'})