test_label.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(index=21, name='name', red=red, green=green,
  12. blue=blue, transparency=transparency)
  13. assert color_code == label.color_code
  14. def test_color_code_unknown():
  15. label = Label(index=0, name='unknown', red=21,
  16. green=21, blue=21, transparency=0)
  17. assert label.color_code == 0
  18. @pytest.mark.parametrize(('red', 'green', 'blue', 'hex_color_code'), [
  19. # pylint: disable=bad-whitespace
  20. ( 0, 0, 0, '#000000'),
  21. (255, 255, 255, '#ffffff'),
  22. (255, 0, 0, '#ff0000'),
  23. ( 0, 255, 0, '#00ff00'),
  24. ( 0, 0, 255, '#0000ff'),
  25. ( 1, 2, 3, '#010203'),
  26. ( 17, 18, 19, '#111213'),
  27. (128, 192, 255, '#80c0ff'),
  28. ( 20, 220, 160, '#14dca0'),
  29. ])
  30. def test_hex_color_code(red, green, blue, hex_color_code):
  31. label = Label(index=21, name='name', red=red,
  32. green=green, blue=blue, transparency=0)
  33. assert hex_color_code == label.hex_color_code.lower()
  34. def test_str():
  35. label = Label(index=24, name='precentral', red=60,
  36. green=20, blue=220, transparency=0)
  37. assert str(label) == 'Label(name=precentral, index=24, color=#3c14dc)'
  38. def test_repr():
  39. label = Label(index=24, name='precentral', red=60,
  40. green=20, blue=220, transparency=0)
  41. assert repr(label) == 'Label(name=precentral, index=24, color=#3c14dc)'