test_label.py 1.6 KB

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