OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 import mock | 7 import mock |
8 | 8 |
9 from infra_libs.ts_mon import helpers | 9 try: |
10 from infra_libs.ts_mon import metrics | 10 from infra_libs.ts_mon.common import metrics |
| 11 from infra_libs.ts_mon.common import helpers |
| 12 except ImportError: # pragma: no cover |
| 13 from common import metrics |
| 14 from common import helpers |
11 | 15 |
12 | 16 |
13 class ScopedIncrementCounterTest(unittest.TestCase): | 17 class ScopedIncrementCounterTest(unittest.TestCase): |
14 | 18 |
15 def test_success(self): | 19 def test_success(self): |
16 counter = mock.Mock(metrics.CounterMetric) | 20 counter = mock.Mock(metrics.CounterMetric) |
17 with helpers.ScopedIncrementCounter(counter): | 21 with helpers.ScopedIncrementCounter(counter): |
18 pass | 22 pass |
19 counter.increment.assert_called_once_with({'status': 'success'}) | 23 counter.increment.assert_called_once_with({'status': 'success'}) |
20 | 24 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 with helpers.ScopedIncrementCounter(counter, 'a', 'b', 'c'): | 61 with helpers.ScopedIncrementCounter(counter, 'a', 'b', 'c'): |
58 pass | 62 pass |
59 counter.increment.assert_called_once_with({'a': 'b'}) | 63 counter.increment.assert_called_once_with({'a': 'b'}) |
60 | 64 |
61 def test_custom_label_exception(self): | 65 def test_custom_label_exception(self): |
62 counter = mock.Mock(metrics.CounterMetric) | 66 counter = mock.Mock(metrics.CounterMetric) |
63 with self.assertRaises(Exception): | 67 with self.assertRaises(Exception): |
64 with helpers.ScopedIncrementCounter(counter, 'a', 'b', 'c'): | 68 with helpers.ScopedIncrementCounter(counter, 'a', 'b', 'c'): |
65 raise Exception() | 69 raise Exception() |
66 counter.increment.assert_called_once_with({'a': 'c'}) | 70 counter.increment.assert_called_once_with({'a': 'c'}) |
OLD | NEW |