/usr/lib/python2.7/dist-packages/ginga/tests/test_colors.py is in python-ginga 2.6.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | #
# Unit Tests for the colors.py functions
#
# Rajul Srivastava (rajul09@gmail.com)
#
import unittest
import logging
import numpy as np
import ginga.colors
class TestError(Exception):
pass
class TestColors(unittest.TestCase):
def setUp(self):
self.logger = logging.getLogger("TestColors")
self.color_list_length = len(ginga.colors.color_dict)
# Tests for the lookup_color() funtion
def test_lookup_color_white_tuple(self):
expected = (1.0, 1.0, 1.0)
actual = ginga.colors.lookup_color("white", "tuple")
assert np.allclose(expected, actual)
def test_lookup_color_black_tuple(self):
expected = (0.0, 0.0, 0.0)
actual = ginga.colors.lookup_color("black", "tuple")
assert np.allclose(expected, actual)
def test_lookup_color_white_hash(self):
expected = "#ffffff"
actual = ginga.colors.lookup_color("white", "hash")
assert expected == actual
def test_lookup_color_black_black(self):
expected = "#000000"
actual = ginga.colors.lookup_color("black", "hash")
assert expected == actual
def test_lookup_color_yellow_tuple(self):
expected = (1.0, 1.0, 0.0)
actual = ginga.colors.lookup_color("yellow")
assert np.allclose(expected, actual)
def test_lookup_color_unknown(self):
self.assertRaises(KeyError, ginga.colors.lookup_color, "unknown_color")
def test_lookup_color_raise_exception_unknown_key(self):
self.assertRaises(KeyError, ginga.colors.lookup_color, "unknown_key")
def test_lookup_color_raise_exception_unknown_format(self):
self.assertRaises(ValueError, ginga.colors.lookup_color, "white", "unknown_format")
# Tests for the get_colors() function
def test_get_colors_len(self):
expected = self.color_list_length
actual = len(ginga.colors.get_colors())
assert expected == actual
def test_add_and_get_colors_len(self):
ginga.colors.add_color("test_color_white", (0.0, 0.0, 0.0))
expected = self.color_list_length + 1
actual = len(ginga.colors.get_colors())
assert expected == actual
ginga.colors.remove_color("test_color_white")
# Tests for the add_color() and remove_color() function
def test_add_and_remove_color_len(self):
ginga.colors.add_color("test_color_white", (0.0, 0.0, 0.0))
expected = self.color_list_length + 1
actual = len(ginga.colors.color_dict)
assert expected == actual
expected = len(ginga.colors.color_dict)
actual = len(ginga.colors.color_list)
assert expected == actual
ginga.colors.remove_color("test_color_white")
expected = self.color_list_length
actual = len(ginga.colors.color_dict)
assert expected == actual
expected = len(ginga.colors.color_dict)
actual = len(ginga.colors.color_list)
assert expected == actual
def test_add_and_remove_color_rbg(self):
ginga.colors.add_color("test_color_white", (0.0, 0.0, 0.0))
expected = (0.0, 0.0, 0.0)
actual = ginga.colors.lookup_color("test_color_white")
assert np.allclose(expected, actual)
ginga.colors.remove_color("test_color_white")
self.assertRaises(KeyError, ginga.colors.remove_color, "test_color_white")
def test_add_color_wrong_rbg_type(self):
self.assertRaises(TypeError, ginga.colors.add_color, "white", "string_wrong_format")
def test_add_color_wrong_rbg_values(self):
self.assertRaises(ValueError, ginga.colors.add_color, "test_color", (-1.0, 0.0, 0.0))
def test_add_color_wrong_tuple_length(self):
self.assertRaises(ValueError, ginga.colors.add_color, "test_color", (0.0, 0.0))
def test_remove_color_unknown(self):
self.assertRaises(KeyError, ginga.colors.remove_color, "unknown_color")
# Tests for recalc_color_list() function
def test_recalc_color_list(self):
ginga.colors.color_dict["test_color_white"] = (0.0, 0.0, 0.0)
expected = len(ginga.colors.color_dict) - 1
actual = len(ginga.colors.color_list)
assert expected == actual
ginga.colors.recalc_color_list()
expected = len(ginga.colors.color_dict)
actual = len(ginga.colors.color_list)
assert expected == actual
del ginga.colors.color_dict["test_color_white"]
expected = len(ginga.colors.color_dict) + 1
actual = len(ginga.colors.color_list)
assert expected == actual
ginga.colors.recalc_color_list()
expected = len(ginga.colors.color_dict)
actual = len(ginga.colors.color_list)
assert expected == actual
# Tests for scan_rgbtxt_buf() function
def test_scan_rgbtxt_buf(self):
test_rgb_lines = '''
255 255 255 white
0 0 0 black
255 0 0 red
0 255 0 green
0 0 255 blue
'''
result = ginga.colors.scan_rgbtxt_buf(test_rgb_lines)
assert isinstance(result, dict)
expected = 5
actual = len(result)
assert expected == actual
expected = (1.0, 1.0, 1.0)
actual = result["white"]
assert np.allclose(expected, actual)
def tearDown(self):
pass
if __name__ == '__main__':
unittest.main()
#END
|