test_telemetry.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import json
  2. from reflex.utils import telemetry
  3. def versiontuple(v):
  4. return tuple(map(int, (v.split("."))))
  5. def test_telemetry():
  6. """Test that telemetry is sent correctly."""
  7. tel = telemetry.Telemetry()
  8. # Check that the user OS is one of the supported operating systems.
  9. assert tel.user_os is not None
  10. assert tel.user_os in ["Linux", "Darwin", "Java", "Windows"]
  11. # Check that the CPU count and memory are greater than 0.
  12. assert tel.cpu_count > 0
  13. # Check that the available memory is greater than 0
  14. assert tel.memory > 0
  15. # Check that the Reflex version is not None.
  16. assert tel.reflex_version is not None
  17. # Check that the Python version is greater than 3.7.
  18. assert tel.python_version is not None
  19. assert versiontuple(tel.python_version) >= versiontuple("3.7")
  20. # Check the json method.
  21. tel_json = json.loads(tel.json())
  22. assert tel_json["user_os"] == tel.user_os
  23. assert tel_json["cpu_count"] == tel.cpu_count
  24. assert tel_json["memory"] == tel.memory
  25. assert tel_json["reflex_version"] == tel.reflex_version
  26. assert tel_json["python_version"] == tel.python_version
  27. def test_disable():
  28. """Test that disabling telemetry works."""
  29. assert not telemetry.send("test", telemetry_enabled=False)