コード例 #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'})