(self, metrics_patch, datetime_patch)
| 262 | @patch("st2common.metrics.base.get_datetime_utc_now") |
| 263 | @patch("st2common.metrics.base.METRICS") |
| 264 | def test_time(self, metrics_patch, datetime_patch): |
| 265 | start_time = get_datetime_utc_now() |
| 266 | middle_time = start_time + timedelta(seconds=1) |
| 267 | end_time = middle_time + timedelta(seconds=1) |
| 268 | datetime_patch.side_effect = [ |
| 269 | start_time, |
| 270 | middle_time, |
| 271 | middle_time, |
| 272 | middle_time, |
| 273 | end_time, |
| 274 | ] |
| 275 | test_key = "test_key" |
| 276 | with base.Timer(test_key) as timer: |
| 277 | self.assertIsInstance(timer._start_time, datetime) |
| 278 | metrics_patch.time.assert_not_called() |
| 279 | timer.send_time() |
| 280 | metrics_patch.time.assert_called_with( |
| 281 | test_key, (end_time - middle_time).total_seconds() |
| 282 | ) |
| 283 | second_test_key = "lakshmi_has_toes" |
| 284 | timer.send_time(second_test_key) |
| 285 | metrics_patch.time.assert_called_with( |
| 286 | second_test_key, (end_time - middle_time).total_seconds() |
| 287 | ) |
| 288 | time_delta = timer.get_time_delta() |
| 289 | self.assertEqual( |
| 290 | time_delta.total_seconds(), (end_time - middle_time).total_seconds() |
| 291 | ) |
| 292 | metrics_patch.time.assert_called_with( |
| 293 | test_key, (end_time - start_time).total_seconds() |
| 294 | ) |
| 295 | |
| 296 | |
| 297 | class TestCounterWithTimerContextManager(unittest.TestCase): |
nothing calls this directly
no test coverage detected