|
1 | 1 | import os
|
2 | 2 | import unittest
|
3 |
| - |
4 | 3 | try:
|
5 | 4 | from unittest.mock import patch, call
|
6 | 5 | except ImportError:
|
7 | 6 | from mock import patch, call
|
8 | 7 |
|
9 |
| -from datadog_lambda.metric import lambda_metric, _format_dd_lambda_layer_tag |
| 8 | +from datadog_lambda.metric import ( |
| 9 | + lambda_metric, |
| 10 | + _format_dd_lambda_layer_tag, |
| 11 | +) |
10 | 12 |
|
11 | 13 |
|
12 | 14 | class TestLambdaMetric(unittest.TestCase):
|
| 15 | + |
13 | 16 | def setUp(self):
|
14 |
| - patcher = patch("datadog_lambda.metric.lambda_stats") |
| 17 | + patcher = patch('datadog_lambda.metric.lambda_stats') |
15 | 18 | self.mock_metric_lambda_stats = patcher.start<
8000
/span>()
|
16 | 19 | self.addCleanup(patcher.stop)
|
17 | 20 |
|
18 | 21 | def test_lambda_metric_tagged_with_dd_lambda_layer(self):
|
19 |
| - lambda_metric("test", 1) |
20 |
| - lambda_metric("test", 1, 123, []) |
21 |
| - lambda_metric("test", 1, tags=["tag1:test"]) |
| 22 | + lambda_metric('test', 1) |
| 23 | + lambda_metric('test', 1, 123, []) |
| 24 | + lambda_metric('test', 1, tags=['tag1:test']) |
22 | 25 | expected_tag = _format_dd_lambda_layer_tag()
|
23 |
| - self.mock_metric_lambda_stats.distribution.assert_has_calls( |
24 |
| - [ |
25 |
| - call("test", 1, timestamp=None, tags=[expected_tag]), |
26 |
| - call("test", 1, timestamp=123, tags=[expected_tag]), |
27 |
| - call("test", 1, timestamp=None, tags=["tag1:test", expected_tag]), |
28 |
| - ] |
29 |
| - ) |
| 26 | + self.mock_metric_lambda_stats.distribution.assert_has_calls([ |
| 27 | + call('test', 1, timestamp=None, tags=[expected_tag]), |
| 28 | + call('test', 1, timestamp=123, tags=[expected_tag]), |
| 29 | + call('test', 1, timestamp=None, tags=['tag1:test', expected_tag]), |
| 30 | + ]) |
30 | 31 |
|
31 | 32 | def test_lambda_metric_flush_to_log(self):
|
32 |
| - os.environ["DD_FLUSH_TO_LOG"] = "True" |
| 33 | + os.environ["DD_FLUSH_TO_LOG"] = 'True' |
33 | 34 |
|
34 |
| - lambda_metric("test", 1) |
| 35 | + lambda_metric('test', 1) |
35 | 36 | self.mock_metric_lambda_stats.distribution.assert_not_called()
|
36 | 37 |
|
37 | 38 | del os.environ["DD_FLUSH_TO_LOG"]
|
0 commit comments