|
2 | 2 | import unittest |
3 | 3 | import json |
4 | 4 | import os |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
5 | 8 | from prometheus_api_client import MetricSnapshotDataFrame |
| 9 | +from prometheus_api_client.exceptions import MetricValueConversionError |
6 | 10 | from pandas.api.types import is_datetime64_any_dtype as is_dtype_datetime |
7 | 11 |
|
8 | 12 |
|
@@ -90,6 +94,29 @@ def test_init_single_metric(self): |
90 | 94 | "incorrect dataframe shape when initialized with single json list", |
91 | 95 | ) |
92 | 96 |
|
| 97 | + def test_init_multiple_metrics(self): |
| 98 | + """Ensures metric values provided as strings are properly cast to a numeric value (in this case, a float).""" |
| 99 | + raw_data = [ |
| 100 | + {"metric": {"fake": "data",}, "value": [1627485628.789, "26.82068965517243"],}, |
| 101 | + {"metric": {"fake": "data",}, "value": [1627485628.789, "26.82068965517243"],}, |
| 102 | + ] |
| 103 | + |
| 104 | + test_df = MetricSnapshotDataFrame(data=raw_data) |
| 105 | + |
| 106 | + self.assertTrue(isinstance(test_df["value"][0], float)) |
| 107 | + |
| 108 | + def test_init_invalid_float_error(self): |
| 109 | + """Ensures metric values provided as strings are properly cast to a numeric value (in this case, a float).""" |
| 110 | + raw_data = [ |
| 111 | + { |
| 112 | + "metric": {"fake": "data",}, |
| 113 | + "value": [1627485628.789, "26.8206896551724326.82068965517243"], |
| 114 | + }, |
| 115 | + ] |
| 116 | + |
| 117 | + with pytest.raises(MetricValueConversionError): |
| 118 | + MetricSnapshotDataFrame(data=raw_data) |
| 119 | + |
93 | 120 |
|
94 | 121 | if __name__ == "__main__": |
95 | 122 | unittest.main() |
0 commit comments