parts/django/tests/regressiontests/utils/termcolors.py
changeset 69 c6bca38c1cbf
equal deleted inserted replaced
68:5ff1fc726848 69:c6bca38c1cbf
       
     1 import unittest
       
     2 
       
     3 from django.utils.termcolors import parse_color_setting, PALETTES, DEFAULT_PALETTE, LIGHT_PALETTE, DARK_PALETTE, NOCOLOR_PALETTE
       
     4 
       
     5 class TermColorTests(unittest.TestCase):
       
     6 
       
     7     def test_empty_string(self):
       
     8         self.assertEquals(parse_color_setting(''), PALETTES[DEFAULT_PALETTE])
       
     9 
       
    10     def test_simple_palette(self):
       
    11         self.assertEquals(parse_color_setting('light'), PALETTES[LIGHT_PALETTE])
       
    12         self.assertEquals(parse_color_setting('dark'), PALETTES[DARK_PALETTE])
       
    13         self.assertEquals(parse_color_setting('nocolor'), None)
       
    14 
       
    15     def test_fg(self):
       
    16         self.assertEquals(parse_color_setting('error=green'),
       
    17                           dict(PALETTES[NOCOLOR_PALETTE],
       
    18                             ERROR={'fg':'green'}))
       
    19 
       
    20     def test_fg_bg(self):
       
    21         self.assertEquals(parse_color_setting('error=green/blue'),
       
    22                           dict(PALETTES[NOCOLOR_PALETTE],
       
    23                             ERROR={'fg':'green', 'bg':'blue'}))
       
    24 
       
    25     def test_fg_opts(self):
       
    26         self.assertEquals(parse_color_setting('error=green,blink'),
       
    27                           dict(PALETTES[NOCOLOR_PALETTE],
       
    28                             ERROR={'fg':'green', 'opts': ('blink',)}))
       
    29         self.assertEquals(parse_color_setting('error=green,bold,blink'),
       
    30                           dict(PALETTES[NOCOLOR_PALETTE],
       
    31                             ERROR={'fg':'green', 'opts': ('blink','bold')}))
       
    32 
       
    33     def test_fg_bg_opts(self):
       
    34         self.assertEquals(parse_color_setting('error=green/blue,blink'),
       
    35                           dict(PALETTES[NOCOLOR_PALETTE],
       
    36                             ERROR={'fg':'green', 'bg':'blue', 'opts': ('blink',)}))
       
    37         self.assertEquals(parse_color_setting('error=green/blue,bold,blink'),
       
    38                           dict(PALETTES[NOCOLOR_PALETTE],
       
    39                             ERROR={'fg':'green', 'bg':'blue', 'opts': ('blink','bold')}))
       
    40 
       
    41     def test_override_palette(self):
       
    42         self.assertEquals(parse_color_setting('light;error=green'),
       
    43                           dict(PALETTES[LIGHT_PALETTE],
       
    44                             ERROR={'fg':'green'}))
       
    45 
       
    46     def test_override_nocolor(self):
       
    47         self.assertEquals(parse_color_setting('nocolor;error=green'),
       
    48                           dict(PALETTES[NOCOLOR_PALETTE],
       
    49                             ERROR={'fg': 'green'}))
       
    50 
       
    51     def test_reverse_override(self):
       
    52         self.assertEquals(parse_color_setting('error=green;light'), PALETTES[LIGHT_PALETTE])
       
    53 
       
    54     def test_multiple_roles(self):
       
    55         self.assertEquals(parse_color_setting('error=green;sql_field=blue'),
       
    56                           dict(PALETTES[NOCOLOR_PALETTE],
       
    57                             ERROR={'fg':'green'},
       
    58                             SQL_FIELD={'fg':'blue'}))
       
    59 
       
    60     def test_override_with_multiple_roles(self):
       
    61         self.assertEquals(parse_color_setting('light;error=green;sql_field=blue'),
       
    62                           dict(PALETTES[LIGHT_PALETTE],
       
    63                             ERROR={'fg':'green'},
       
    64                             SQL_FIELD={'fg':'blue'}))
       
    65 
       
    66     def test_empty_definition(self):
       
    67         self.assertEquals(parse_color_setting(';'), None)
       
    68         self.assertEquals(parse_color_setting('light;'), PALETTES[LIGHT_PALETTE])
       
    69         self.assertEquals(parse_color_setting(';;;'), None)
       
    70 
       
    71     def test_empty_options(self):
       
    72         self.assertEquals(parse_color_setting('error=green,'),
       
    73                           dict(PALETTES[NOCOLOR_PALETTE],
       
    74                             ERROR={'fg':'green'}))
       
    75         self.assertEquals(parse_color_setting('error=green,,,'),
       
    76                           dict(PALETTES[NOCOLOR_PALETTE],
       
    77                             ERROR={'fg':'green'}))
       
    78         self.assertEquals(parse_color_setting('error=green,,blink,,'),
       
    79                           dict(PALETTES[NOCOLOR_PALETTE],
       
    80                             ERROR={'fg':'green', 'opts': ('blink',)}))
       
    81 
       
    82     def test_bad_palette(self):
       
    83         self.assertEquals(parse_color_setting('unknown'), None)
       
    84 
       
    85     def test_bad_role(self):
       
    86         self.assertEquals(parse_color_setting('unknown='), None)
       
    87         self.assertEquals(parse_color_setting('unknown=green'), None)
       
    88         self.assertEquals(parse_color_setting('unknown=green;sql_field=blue'),
       
    89                           dict(PALETTES[NOCOLOR_PALETTE],
       
    90                             SQL_FIELD={'fg':'blue'}))
       
    91 
       
    92     def test_bad_color(self):
       
    93         self.assertEquals(parse_color_setting('error='), None)
       
    94         self.assertEquals(parse_color_setting('error=;sql_field=blue'),
       
    95                           dict(PALETTES[NOCOLOR_PALETTE],
       
    96                             SQL_FIELD={'fg':'blue'}))
       
    97         self.assertEquals(parse_color_setting('error=unknown'), None)
       
    98         self.assertEquals(parse_color_setting('error=unknown;sql_field=blue'),
       
    99                           dict(PALETTES[NOCOLOR_PALETTE],
       
   100                             SQL_FIELD={'fg':'blue'}))
       
   101         self.assertEquals(parse_color_setting('error=green/unknown'),
       
   102                           dict(PALETTES[NOCOLOR_PALETTE],
       
   103                             ERROR={'fg':'green'}))
       
   104         self.assertEquals(parse_color_setting('error=green/blue/something'),
       
   105                           dict(PALETTES[NOCOLOR_PALETTE],
       
   106                             ERROR={'fg':'green', 'bg': 'blue'}))
       
   107         self.assertEquals(parse_color_setting('error=green/blue/something,blink'),
       
   108                           dict(PALETTES[NOCOLOR_PALETTE],
       
   109                             ERROR={'fg':'green', 'bg': 'blue', 'opts': ('blink',)}))
       
   110 
       
   111     def test_bad_option(self):
       
   112         self.assertEquals(parse_color_setting('error=green,unknown'),
       
   113                           dict(PALETTES[NOCOLOR_PALETTE],
       
   114                             ERROR={'fg':'green'}))
       
   115         self.assertEquals(parse_color_setting('error=green,unknown,blink'),
       
   116                           dict(PALETTES[NOCOLOR_PALETTE],
       
   117                             ERROR={'fg':'green', 'opts': ('blink',)}))
       
   118 
       
   119     def test_role_case(self):
       
   120         self.assertEquals(parse_color_setting('ERROR=green'),
       
   121                           dict(PALETTES[NOCOLOR_PALETTE],
       
   122                             ERROR={'fg':'green'}))
       
   123         self.assertEquals(parse_color_setting('eRrOr=green'),
       
   124                           dict(PALETTES[NOCOLOR_PALETTE],
       
   125                             ERROR={'fg':'green'}))
       
   126 
       
   127     def test_color_case(self):
       
   128         self.assertEquals(parse_color_setting('error=GREEN'),
       
   129                           dict(PALETTES[NOCOLOR_PALETTE],
       
   130                             ERROR={'fg':'green'}))
       
   131         self.assertEquals(parse_color_setting('error=GREEN/BLUE'),
       
   132                           dict(PALETTES[NOCOLOR_PALETTE],
       
   133                             ERROR={'fg':'green', 'bg':'blue'}))
       
   134 
       
   135         self.assertEquals(parse_color_setting('error=gReEn'),
       
   136                           dict(PALETTES[NOCOLOR_PALETTE],
       
   137                             ERROR={'fg':'green'}))
       
   138         self.assertEquals(parse_color_setting('error=gReEn/bLuE'),
       
   139                           dict(PALETTES[NOCOLOR_PALETTE],
       
   140                             ERROR={'fg':'green', 'bg':'blue'}))
       
   141 
       
   142     def test_opts_case(self):
       
   143         self.assertEquals(parse_color_setting('error=green,BLINK'),
       
   144                           dict(PALETTES[NOCOLOR_PALETTE],
       
   145                             ERROR={'fg':'green', 'opts': ('blink',)}))
       
   146 
       
   147         self.assertEquals(parse_color_setting('error=green,bLiNk'),
       
   148                           dict(PALETTES[NOCOLOR_PALETTE],
       
   149                             ERROR={'fg':'green', 'opts': ('blink',)}))