From eb82fb0a9d14ca317d366afb65e21d742bbe46a5 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Tue, 21 Oct 2014 15:31:24 +0700 Subject: Refactored color_style() and no_style() to improve testability. Refs #23663. This includes the following improvements: - The type of the style object is now called 'Style' rather than 'dummy'. - The new make_style() function allows generating a Style object directly from a config string. Before the only way to get a style object was through the environ and it also required that the terminal supported colors which isn't necessarily the case when testing. - The output of no_style() is now cached with @lru_cache. - The output of no_style() now has the same set of attributes as the other Style objects. Previously it allowed anything to pass through with __getattr__. --- tests/admin_scripts/tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/admin_scripts/tests.py') diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index c19fbb9019..5bc0fb3ee1 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -1392,6 +1392,22 @@ class CommandTypes(AdminScriptTestCase): self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the\ngiven model module name(s).") self.assertEqual(out.count('optional arguments'), 1) + def test_color_style(self): + style = color.no_style() + self.assertEqual(style.ERROR('Hello, world!'), 'Hello, world!') + + style = color.make_style('nocolor') + self.assertEqual(style.ERROR('Hello, world!'), 'Hello, world!') + + style = color.make_style('dark') + self.assertIn('Hello, world!', style.ERROR('Hello, world!')) + self.assertNotEqual(style.ERROR('Hello, world!'), 'Hello, world!') + + # Default palette has color. + style = color.make_style('') + self.assertIn('Hello, world!', style.ERROR('Hello, world!')) + self.assertNotEqual(style.ERROR('Hello, world!'), 'Hello, world!') + def test_command_color(self): class Command(BaseCommand): requires_system_checks = False -- cgit v1.3