<s> import unittest <EOL> import logging <EOL> import numpy as np <EOL> import ginga . colors <EOL> class TestError ( Exception ) : <EOL> pass <EOL> class TestColors ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . logger = logging . getLogger ( "<STR_LIT>" ) <EOL> self . color_list_length = len ( ginga . colors . color_dict ) <EOL> def test_lookup_color_white_tuple ( self ) : <EOL> expected = ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) <EOL> actual = ginga . colors . lookup_color ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> assert np . allclose ( expected , actual ) <EOL> def test_lookup_color_black_tuple ( self ) : <EOL> expected = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) <EOL> actual = ginga . colors . lookup_color ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> assert np . allclose ( expected , actual ) <EOL> def test_lookup_color_white_hash ( self ) : <EOL> expected = "<STR_LIT>" <EOL> actual = ginga . colors . lookup_color ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> assert expected == actual <EOL> def test_lookup_color_black_black ( self ) : <EOL> expected = "<STR_LIT>" <EOL> actual = ginga . colors . lookup_color ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> assert expected == actual <EOL> def test_lookup_color_yellow_tuple ( self ) : <EOL> expected = ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) <EOL> actual = ginga . colors . lookup_color ( "<STR_LIT>" ) <EOL> assert np . allclose ( expected , actual ) <EOL> def test_lookup_color_unknown ( self ) : <EOL> self . assertRaises ( KeyError , ginga . colors . lookup_color , "<STR_LIT>" ) <EOL> def test_lookup_color_raise_exception_unknown_key ( self ) : <EOL> self . assertRaises ( KeyError , ginga . colors . lookup_color , "<STR_LIT>" ) <EOL> def test_lookup_color_raise_exception_unknown_format ( self ) : <EOL> self . assertRaises ( ValueError , ginga . colors . lookup_color , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_get_colors_len ( self ) : <EOL> expected = self . color_list_length <EOL> actual = len ( ginga . colors . get_colors ( ) ) <EOL> assert expected == actual <EOL> def test_add_and_get_colors_len ( self ) : <EOL> ginga . colors . add_color ( "<STR_LIT>" , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) <EOL> expected = self . color_list_length + <NUM_LIT:1> <EOL> actual = len ( ginga . colors . get_colors ( ) ) <EOL> assert expected == actual <EOL> ginga . colors . remove_color ( "<STR_LIT>" ) <EOL> def test_add_and_remove_color_len ( self ) : <EOL> ginga . colors . add_color ( "<STR_LIT>" , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) <EOL> expected = self . color_list_length + <NUM_LIT:1> <EOL> actual = len ( ginga . colors . color_dict ) <EOL> assert expected == actual <EOL> expected = len ( ginga . colors . color_dict ) <EOL> actual = len ( ginga . colors . color_list ) <EOL> assert expected == actual <EOL> ginga . colors . remove_color ( "<STR_LIT>" ) <EOL> expected = self . color_list_length <EOL> actual = len ( ginga . colors . color_dict ) <EOL> assert expected == actual <EOL> expected = len ( ginga . colors . color_dict ) <EOL> actual = len ( ginga . colors . color_list ) <EOL> assert expected == actual <EOL> def test_add_and_remove_color_rbg ( self ) : <EOL> ginga . colors . add_color ( "<STR_LIT>" , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) <EOL> expected = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) <EOL> actual = ginga . colors . lookup_color ( "<STR_LIT>" ) <EOL> assert np . allclose ( expected , actual ) <EOL> ginga . colors . remove_color ( "<STR_LIT>" ) <EOL> self . assertRaises ( KeyError , ginga . colors . remove_color , "<STR_LIT>" ) <EOL> def test_add_color_wrong_rbg_type ( self ) : <EOL> self . assertRaises ( TypeError , ginga . colors . add_color , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_add_color_wrong_rbg_values ( self ) : <EOL> self . assertRaises ( ValueError , ginga . colors . add_color , "<STR_LIT>" , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) <EOL> def test_add_color_wrong_tuple_length ( self ) : <EOL> self . assertRaises ( ValueError , ginga . colors . add_color , "<STR_LIT>" , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) <EOL> def test_remove_color_unknown ( self ) : <EOL> self . assertRaises ( KeyError , ginga . colors . remove_color , "<STR_LIT>" ) <EOL> def test_recalc_color_list ( self ) : <EOL> ginga . colors . color_dict [ "<STR_LIT>" ] = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) <EOL> expected = len ( ginga . colors . color_dict ) - <NUM_LIT:1> <EOL> actual = len ( ginga . colors . color_list ) <EOL> assert expected == actual <EOL> ginga . colors . recalc_color_list ( ) <EOL> expected = len ( ginga . colors . color_dict ) <EOL> actual = len ( ginga . colors . color_list ) <EOL> assert expected == actual <EOL> del ginga . colors . color_dict [ "<STR_LIT>" ] <EOL> expected = len ( ginga . colors . color_dict ) + <NUM_LIT:1> <EOL> actual = len ( ginga . colors . color_list ) <EOL> assert expected == actual <EOL> ginga . colors . recalc_color_list ( ) <EOL> expected = len ( ginga . colors . color_dict ) <EOL> actual = len ( ginga . colors . color_list ) <EOL> assert expected == actual <EOL> def test_scan_rgbtxt_buf ( self ) : <EOL> test_rgb_lines = '''<STR_LIT>''' <EOL> result = ginga . colors . scan_rgbtxt_buf ( test_rgb_lines ) <EOL> assert isinstance ( result , dict ) <EOL> expected = <NUM_LIT:5> <EOL> actual = len ( result ) <EOL> assert expected == actual <EOL> expected = ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) <EOL> actual = result [ "<STR_LIT>" ] <EOL> assert np . allclose ( expected , actual ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
