test_mri.py 1.1 KB

123456789101112131415161718192021222324
  1. from typing import cast
  2. import pytest
  3. from sentry.snuba.metrics.naming_layer.mri import format_mri_field, format_mri_field_value
  4. from sentry.testutils.cases import TestCase
  5. pytestmark = pytest.mark.sentry_metrics
  6. class TestMRIUtils(TestCase):
  7. def test_format_mri_field(self):
  8. assert format_mri_field("avg(c:custom/foo@none)") == "avg(foo)"
  9. assert format_mri_field("max(s:spans/user@none)") == "max(user)"
  10. assert format_mri_field("sum(d:spans/exclusive_time@millisecond)") == "sum(exclusive_time)"
  11. assert format_mri_field("invalid_mri_field") == "invalid_mri_field"
  12. assert format_mri_field(cast(str, None)) is None
  13. def test_format_mri_field_value(self):
  14. assert format_mri_field_value("avg(c:custom/foo@none)", "100.0") == "100.0"
  15. assert format_mri_field_value("count(s:spans/user@none)", "100") == "100"
  16. assert format_mri_field_value("sum(d:spans/exclusive_time@millisecond)", "1000") == "1 s"
  17. assert format_mri_field_value("invalid_mri_field", "100") == "100"
  18. assert format_mri_field_value(cast(str, None), "100") == "100"