test_units.py 1.8 KB

123456789101112131415161718192021222324252627282930313233
  1. import pytest
  2. from sentry.snuba.metrics.units import format_value_using_unit
  3. from sentry.testutils.cases import TestCase
  4. pytestmark = pytest.mark.sentry_metrics
  5. class TestUnitsUtils(TestCase):
  6. def test_format_value_using_unit(self):
  7. assert format_value_using_unit(543200, "nanosecond") == "0.54 ms"
  8. assert format_value_using_unit(54320, "microsecond") == "54.32 ms"
  9. assert format_value_using_unit(123456, "millisecond") == "2.06 m"
  10. assert format_value_using_unit(1, "second") == "1 s"
  11. assert format_value_using_unit(0.55823414213, "second") == "558.23 ms"
  12. assert format_value_using_unit(45, "minute") == "45 m"
  13. assert format_value_using_unit(24, "hour") == "1 d"
  14. assert format_value_using_unit(3, "day") == "3 d"
  15. assert format_value_using_unit(1, "week") == "1 wk"
  16. assert format_value_using_unit(600, "byte") == "600 B"
  17. assert format_value_using_unit(2048, "kibibyte") == "1.95 MB"
  18. assert format_value_using_unit(3072, "mebibyte") == "2.86 GB"
  19. assert format_value_using_unit(3072, "gibibyte") == "2.79 TB"
  20. assert format_value_using_unit(4096, "tebibyte") == "3.64 PB"
  21. assert format_value_using_unit(51, "pebibyte") == "45.30 PB"
  22. assert format_value_using_unit(1, "exbibyte") == "888.18 PB"
  23. assert format_value_using_unit(4096, "kilobyte") == "4.00 MB"
  24. assert format_value_using_unit(3145728, "megabyte") == "3.00 TB"
  25. assert format_value_using_unit(3072, "megabyte") == "3.00 GB"
  26. assert format_value_using_unit(4096, "gigabyte") == "4.00 TB"
  27. assert format_value_using_unit(5120, "terabyte") == "5.00 PB"
  28. assert format_value_using_unit(6144, "petabyte") == "6.00 EB"
  29. assert format_value_using_unit(7168, "exabyte") == "7.00 ZB"