def test_creation_and_hydration(self): key = random_str() value = 10000 ts = int(time.time()) metric = Metric(key, value, ts) self._check(metric, key, value, ts) as_dict = {"key": key, "value": value, "timestamp": ts} self.assertEqual(dict(metric), as_dict) proto = metric.to_proto() metric2 = metric.from_proto(proto) self._check(metric2, key, value, ts) metric3 = Metric.from_dictionary(as_dict) self._check(metric3, key, value, ts)
def test_creation_and_hydration(): key = random_str() value = 10000 ts = int(1000 * time.time()) step = random_int() metric = Metric(key, value, ts, step) _check(metric, key, value, ts, step) as_dict = {"key": key, "value": value, "timestamp": ts, "step": step} assert dict(metric) == as_dict proto = metric.to_proto() metric2 = metric.from_proto(proto) _check(metric2, key, value, ts, step) metric3 = Metric.from_dictionary(as_dict) _check(metric3, key, value, ts, step)