test_label.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import pytest
  2. from freesurfer_surface import Label
  3. @pytest.mark.parametrize(('red', 'green', 'blue', 'transparency', 'color_code'), [
  4. # pylint: disable=bad-whitespace
  5. (220, 20, 20, 0, 1316060),
  6. ( 60, 20, 220, 0, 14423100),
  7. ( 75, 50, 125, 0, 8204875),
  8. ( 20, 220, 160, 0, 10542100),
  9. ])
  10. def test_color_code(red, green, blue, transparency, color_code):
  11. label = Label()
  12. label.index = 21
  13. label.red = red
  14. label.green = green
  15. label.blue = blue
  16. label.transparency = transparency
  17. assert color_code == label.color_code
  18. def test_color_code_unknown():
  19. label = Label()
  20. label.index = 0
  21. label.name = 'unknown'
  22. label.red = 21
  23. label.green = 21
  24. label.blue = 21
  25. assert label.color_code == 0
  26. @pytest.mark.parametrize(('red', 'green', 'blue', 'hex_color_code'), [
  27. # pylint: disable=bad-whitespace
  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. def test_hex_color_code(red, green, blue, hex_color_code):
  39. label = Label()
  40. label.red = red
  41. label.green = green
  42. label.blue = blue
  43. assert hex_color_code == label.hex_color_code.lower()
  44. def test_str():
  45. label = Label()
  46. label.index = 24
  47. label.name = 'precentral'
  48. label.red = 60
  49. label.green = 20
  50. label.blue = 220
  51. label.transparency = 0
  52. assert str(label) == 'Label(name=precentral, index=24, color=#3c14dc)'
  53. def test_repr():
  54. label = Label()
  55. label.index = 24
  56. label.name = 'precentral'
  57. label.red = 60
  58. label.green = 20
  59. label.blue = 220
  60. label.transparency = 0
  61. assert repr(label) == 'Label(name=precentral, index=24, color=#3c14dc)'