summaryrefslogtreecommitdiff
path: root/tests/regressiontests/utils
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-12-28 06:48:47 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-12-28 06:48:47 +0000
commitc38d66a216a45e2352ee666eff9e1270082f906b (patch)
treebb9c33e1b7cbcfa46c5bb98c189888623321d4b9 /tests/regressiontests/utils
parent9319f895478c60717a7cf2cf132ad7fa4440b4f8 (diff)
Fixed #12112 -- Made the colors used by syntax highlighting customizable.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12009 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/utils')
-rw-r--r--tests/regressiontests/utils/termcolors.py149
-rw-r--r--tests/regressiontests/utils/tests.py3
2 files changed, 151 insertions, 1 deletions
diff --git a/tests/regressiontests/utils/termcolors.py b/tests/regressiontests/utils/termcolors.py
new file mode 100644
index 0000000000..7c8fe0d63b
--- /dev/null
+++ b/tests/regressiontests/utils/termcolors.py
@@ -0,0 +1,149 @@
+from unittest import TestCase
+
+from django.utils.termcolors import parse_color_setting, PALETTES, DEFAULT_PALETTE, LIGHT_PALETTE, DARK_PALETTE, NOCOLOR_PALETTE
+
+class TermColorTests(TestCase):
+
+ def test_empty_string(self):
+ self.assertEquals(parse_color_setting(''), PALETTES[DEFAULT_PALETTE])
+
+ def test_simple_palette(self):
+ self.assertEquals(parse_color_setting('light'), PALETTES[LIGHT_PALETTE])
+ self.assertEquals(parse_color_setting('dark'), PALETTES[DARK_PALETTE])
+ self.assertEquals(parse_color_setting('nocolor'), None)
+
+ def test_fg(self):
+ self.assertEquals(parse_color_setting('error=green'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+
+ def test_fg_bg(self):
+ self.assertEquals(parse_color_setting('error=green/blue'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'bg':'blue'}))
+
+ def test_fg_opts(self):
+ self.assertEquals(parse_color_setting('error=green,blink'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'opts': ('blink',)}))
+ self.assertEquals(parse_color_setting('error=green,bold,blink'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'opts': ('blink','bold')}))
+
+ def test_fg_bg_opts(self):
+ self.assertEquals(parse_color_setting('error=green/blue,blink'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'bg':'blue', 'opts': ('blink',)}))
+ self.assertEquals(parse_color_setting('error=green/blue,bold,blink'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'bg':'blue', 'opts': ('blink','bold')}))
+
+ def test_override_palette(self):
+ self.assertEquals(parse_color_setting('light;error=green'),
+ dict(PALETTES[LIGHT_PALETTE],
+ ERROR={'fg':'green'}))
+
+ def test_override_nocolor(self):
+ self.assertEquals(parse_color_setting('nocolor;error=green'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg': 'green'}))
+
+ def test_reverse_override(self):
+ self.assertEquals(parse_color_setting('error=green;light'), PALETTES[LIGHT_PALETTE])
+
+ def test_multiple_roles(self):
+ self.assertEquals(parse_color_setting('error=green;sql_field=blue'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'},
+ SQL_FIELD={'fg':'blue'}))
+
+ def test_override_with_multiple_roles(self):
+ self.assertEquals(parse_color_setting('light;error=green;sql_field=blue'),
+ dict(PALETTES[LIGHT_PALETTE],
+ ERROR={'fg':'green'},
+ SQL_FIELD={'fg':'blue'}))
+
+ def test_empty_definition(self):
+ self.assertEquals(parse_color_setting(';'), None)
+ self.assertEquals(parse_color_setting('light;'), PALETTES[LIGHT_PALETTE])
+ self.assertEquals(parse_color_setting(';;;'), None)
+
+ def test_empty_options(self):
+ self.assertEquals(parse_color_setting('error=green,'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+ self.assertEquals(parse_color_setting('error=green,,,'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+ self.assertEquals(parse_color_setting('error=green,,blink,,'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'opts': ('blink',)}))
+
+ def test_bad_palette(self):
+ self.assertEquals(parse_color_setting('unknown'), None)
+
+ def test_bad_role(self):
+ self.assertEquals(parse_color_setting('unknown='), None)
+ self.assertEquals(parse_color_setting('unknown=green'), None)
+ self.assertEquals(parse_color_setting('unknown=green;sql_field=blue'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ SQL_FIELD={'fg':'blue'}))
+
+ def test_bad_color(self):
+ self.assertEquals(parse_color_setting('error='), None)
+ self.assertEquals(parse_color_setting('error=;sql_field=blue'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ SQL_FIELD={'fg':'blue'}))
+ self.assertEquals(parse_color_setting('error=unknown'), None)
+ self.assertEquals(parse_color_setting('error=unknown;sql_field=blue'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ SQL_FIELD={'fg':'blue'}))
+ self.assertEquals(parse_color_setting('error=green/unknown'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+ self.assertEquals(parse_color_setting('error=green/blue/something'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'bg': 'blue'}))
+ self.assertEquals(parse_color_setting('error=green/blue/something,blink'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'bg': 'blue', 'opts': ('blink',)}))
+
+ def test_bad_option(self):
+ self.assertEquals(parse_color_setting('error=green,unknown'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+ self.assertEquals(parse_color_setting('error=green,unknown,blink'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'opts': ('blink',)}))
+
+ def test_role_case(self):
+ self.assertEquals(parse_color_setting('ERROR=green'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+ self.assertEquals(parse_color_setting('eRrOr=green'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+
+ def test_color_case(self):
+ self.assertEquals(parse_color_setting('error=GREEN'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+ self.assertEquals(parse_color_setting('error=GREEN/BLUE'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'bg':'blue'}))
+
+ self.assertEquals(parse_color_setting('error=gReEn'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green'}))
+ self.assertEquals(parse_color_setting('error=gReEn/bLuE'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'bg':'blue'}))
+
+ def test_opts_case(self):
+ self.assertEquals(parse_color_setting('error=green,BLINK'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'opts': ('blink',)}))
+
+ self.assertEquals(parse_color_setting('error=green,bLiNk'),
+ dict(PALETTES[NOCOLOR_PALETTE],
+ ERROR={'fg':'green', 'opts': ('blink',)}))
diff --git a/tests/regressiontests/utils/tests.py b/tests/regressiontests/utils/tests.py
index 6258b81200..fe5f463110 100644
--- a/tests/regressiontests/utils/tests.py
+++ b/tests/regressiontests/utils/tests.py
@@ -9,8 +9,8 @@ from django.utils.functional import SimpleLazyObject
import timesince
import datastructures
-import dateformat
import itercompat
+
from decorators import DecoratorFromMiddlewareTests
# We need this because "datastructures" uses sorted() and the tests are run in
@@ -28,6 +28,7 @@ __test__ = {
}
from dateformat import *
+from termcolors import *
class TestUtilsHtml(TestCase):