envs.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import pytest
  2. from gpustack.utils.envs import sanitize_env
  3. @pytest.mark.parametrize(
  4. "name, env, expected",
  5. [
  6. ("Empty", {}, {}),
  7. (
  8. "Insensitive",
  9. {
  10. "SOME_OTHER_ENV": "value",
  11. "ANOTHER_ENV": "another_value",
  12. },
  13. {
  14. "SOME_OTHER_ENV": "value",
  15. "ANOTHER_ENV": "another_value",
  16. },
  17. ),
  18. (
  19. "Prefixes",
  20. {
  21. "CUDA_VISIBLE_DEVICES": "0",
  22. "GPUSTACK_WORKER_ID": "worker-1",
  23. "GPUSTACK_WORKER_NAME": "worker-name",
  24. "GPUSTACK_WORKER_TYPE": "worker-type",
  25. },
  26. {
  27. "CUDA_VISIBLE_DEVICES": "0",
  28. },
  29. ),
  30. (
  31. "Suffixes",
  32. {
  33. "HF_HOME": "/path/to/hf_home",
  34. "HF_KEY": "",
  35. "hf_key": "",
  36. "HF_TOKEN": "",
  37. "hf_token": "",
  38. "ABC_SECRET": "",
  39. "abc_secret": "",
  40. "XYZ_PASSWORD": "",
  41. "xyz_password": "",
  42. "XYZ_PASS": "",
  43. "xyz_pass": "",
  44. },
  45. {
  46. "HF_HOME": "/path/to/hf_home",
  47. },
  48. ),
  49. ],
  50. )
  51. def test_sanitize_env(name, env, expected):
  52. actual = sanitize_env(env)
  53. assert actual == expected, f"Case {name} expected {expected}, but got {actual}"