Chromium Code Reviews| Index: infra_libs/ts_mon/common/test/pb_to_popo_test.py |
| diff --git a/infra_libs/ts_mon/common/test/pb_to_popo_test.py b/infra_libs/ts_mon/common/test/pb_to_popo_test.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9e975c525f976e6a12e409ecbdfc568a468dba9 |
| --- /dev/null |
| +++ b/infra_libs/ts_mon/common/test/pb_to_popo_test.py |
| @@ -0,0 +1,45 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import unittest |
| + |
| +from infra_libs.ts_mon.common import monitors |
| +from infra_libs.ts_mon.common import pb_to_popo |
| +from infra_libs.ts_mon.protos import acquisition_network_device_pb2 |
| +from infra_libs.ts_mon.protos import acquisition_task_pb2 |
| +from infra_libs.ts_mon.protos import metrics_pb2 |
| + |
| +class PbToPopoTest(unittest.TestCase): |
| + |
| + def test_convert(self): |
| + task = acquisition_task_pb2.Task(service_name='service') |
| + network_device = acquisition_network_device_pb2.NetworkDevice( |
| + hostname='host', alertable=True) |
| + metric1 = metrics_pb2.MetricsData( |
| + name='m1', counter=200, task=task, |
|
Sergey Berezin
2016/07/06 22:35:49
nit: 4 spaces from the start of the previous line:
tnn
2016/07/06 22:44:36
Done.
|
| + units=metrics_pb2.MetricsData.Units.Value('SECONDS')) |
| + metric2 = metrics_pb2.MetricsData(name='m2', network_device=network_device, |
| + cumulative_double_value=123.456) |
| + collection = metrics_pb2.MetricsCollection(data=[metric1, metric2], |
| + start_timestamp_us=12345) |
| + |
| + popo = pb_to_popo.convert(collection) |
| + expected = { |
| + 'data': [ |
| + { |
| + 'name': 'm1', |
| + 'counter': 200L, |
| + 'task': { 'service_name': 'service' }, |
| + 'units': 1 |
| + }, |
| + { |
| + 'name': 'm2', |
| + 'cumulative_double_value': 123.456, |
| + 'network_device': { 'hostname': 'host', 'alertable': True } |
| + } |
| + ], |
| + 'start_timestamp_us': 12345L |
| + } |
| + self.assertDictEqual(expected, popo) |
| + |