PageRenderTime 123ms CodeModel.GetById 91ms app.highlight 19ms RepoModel.GetById 11ms app.codeStats 0ms

/tests/regressiontests/utils/termcolors.py

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