test_label.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # freesurfer-surface - Read and Write Surface Files in Freesurfer’s TriangularSurface Format
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import pytest
  18. from freesurfer_surface import Label
  19. def test_init_missing_argument():
  20. with pytest.raises(
  21. TypeError, match=r"missing 1 required positional argument: .transparency.$"
  22. ):
  23. # pylint: disable=no-value-for-parameter
  24. Label(index=0, name="test", red=1, green=2, blue=3)
  25. def test_eq():
  26. kwargs = dict(name="test", red=1, green=2, blue=3, transparency=0)
  27. assert Label(index=21, **kwargs) == Label(index=21, **kwargs)
  28. assert Label(index=21, **kwargs) != Label(index=42, **kwargs)
  29. @pytest.mark.parametrize(
  30. ("red", "green", "blue", "transparency", "color_code"),
  31. [
  32. (220, 20, 20, 0, 1316060),
  33. (60, 20, 220, 0, 14423100),
  34. (75, 50, 125, 0, 8204875),
  35. (20, 220, 160, 0, 10542100),
  36. ],
  37. )
  38. def test_color_code(red, green, blue, transparency, color_code):
  39. label = Label(
  40. index=21,
  41. name="name",
  42. red=red,
  43. green=green,
  44. blue=blue,
  45. transparency=transparency,
  46. )
  47. assert color_code == label.color_code
  48. def test_color_code_unknown():
  49. label = Label(index=0, name="unknown", red=21, green=21, blue=21, transparency=0)
  50. assert label.color_code == 0
  51. @pytest.mark.parametrize(
  52. ("red", "green", "blue", "hex_color_code"),
  53. [
  54. (0, 0, 0, "#000000"),
  55. (255, 255, 255, "#ffffff"),
  56. (255, 0, 0, "#ff0000"),
  57. (0, 255, 0, "#00ff00"),
  58. (0, 0, 255, "#0000ff"),
  59. (1, 2, 3, "#010203"),
  60. (17, 18, 19, "#111213"),
  61. (128, 192, 255, "#80c0ff"),
  62. (20, 220, 160, "#14dca0"),
  63. ],
  64. )
  65. def test_hex_color_code(red, green, blue, hex_color_code):
  66. label = Label(
  67. index=21, name="name", red=red, green=green, blue=blue, transparency=0
  68. )
  69. assert hex_color_code == label.hex_color_code.lower()
  70. def test_str():
  71. label = Label(
  72. index=24, name="precentral", red=60, green=20, blue=220, transparency=0
  73. )
  74. assert str(label) == "Label(name=precentral, index=24, color=#3c14dc)"
  75. def test_repr():
  76. label = Label(
  77. index=24, name="precentral", red=60, green=20, blue=220, transparency=0
  78. )
  79. assert repr(label) == "Label(name=precentral, index=24, color=#3c14dc)"