test_label.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import pytest
  2. from freesurfer_surface import Label
  3. @pytest.mark.parametrize(
  4. ("red", "green", "blue", "transparency", "color_code"),
  5. [
  6. (220, 20, 20, 0, 1316060),
  7. (60, 20, 220, 0, 14423100),
  8. (75, 50, 125, 0, 8204875),
  9. (20, 220, 160, 0, 10542100),
  10. ],
  11. )
  12. def test_color_code(red, green, blue, transparency, color_code):
  13. label = Label(
  14. index=21,
  15. name="name",
  16. red=red,
  17. green=green,
  18. blue=blue,
  19. transparency=transparency,
  20. )
  21. assert color_code == label.color_code
  22. def test_color_code_unknown():
  23. label = Label(index=0, name="unknown", red=21, green=21, blue=21, transparency=0)
  24. assert label.color_code == 0
  25. @pytest.mark.parametrize(
  26. ("red", "green", "blue", "hex_color_code"),
  27. [
  28. (0, 0, 0, "#000000"),
  29. (255, 255, 255, "#ffffff"),
  30. (255, 0, 0, "#ff0000"),
  31. (0, 255, 0, "#00ff00"),
  32. (0, 0, 255, "#0000ff"),
  33. (1, 2, 3, "#010203"),
  34. (17, 18, 19, "#111213"),
  35. (128, 192, 255, "#80c0ff"),
  36. (20, 220, 160, "#14dca0"),
  37. ],
  38. )
  39. def test_hex_color_code(red, green, blue, hex_color_code):
  40. label = Label(
  41. index=21, name="name", red=red, green=green, blue=blue, transparency=0
  42. )
  43. assert hex_color_code == label.hex_color_code.lower()
  44. def test_str():
  45. label = Label(
  46. index=24, name="precentral", red=60, green=20, blue=220, transparency=0
  47. )
  48. assert str(label) == "Label(name=precentral, index=24, color=#3c14dc)"
  49. def test_repr():
  50. label = Label(
  51. index=24, name="precentral", red=60, green=20, blue=220, transparency=0
  52. )
  53. assert repr(label) == "Label(name=precentral, index=24, color=#3c14dc)"