Exemplo n.º 1
0
 def test_args(self):
     result = colored("hello", "red bold")
     self.assertEqual(result, "\033[31;1mhello\033[0m")
     result = colored("hello", "red, bold")
     self.assertEqual(result, "\033[31;1mhello\033[0m")
     result = colored("hello", ["red", "bold"])
     self.assertEqual(result, "\033[31;1mhello\033[0m")
Exemplo n.º 2
0
 def test_lines(self):
     result = colored("hello\nworld", "red", eachline=True)
     self.assertEqual(result, "\033[31mhello\033[0m\n\033[31mworld\033[0m")
     result = colored("hello\r\nworld", "red", eachline=True)
     self.assertEqual(result, "\033[31mhello\033[0m\r\n\033[31mworld\033[0m")
     result = colored("hello\nworld\n", "red", eachline=True)
     self.assertEqual(result, "\033[31mhello\033[0m\n\033[31mworld\033[0m\n")
     with self.assertRaisesRegex(TypeError, r".*positional arguments.*"):
         colored("hello\nworld", "red", True)
Exemplo n.º 3
0
#!/usr/bin/env python3
# Re-implementation of the output of 256colors2.pl by Todd Larason.
# This is not a port of the Perl script, but a mimic of the output.

from ansicol import colored

print('System colors:')
for i in range(2):
    for j in range(8):
        print(colored('  ', 'on_ansi{}'.format(i * 8 + j)), end='')
    print()
print()

print('Color cube, 6x6x6:')
for g in range(6):
    for r in range(6):
        for b in range(6):
            print(colored('  ', 'on_rgb{}{}{}'.format(r, g, b)), end='')
        print(' ', end='')
    print()

print('Grayscale ramp:')
for i in range(24):
    print(colored('  ', 'on_grey{}'.format(i)), end='')
print()
Exemplo n.º 4
0
 def test_arg(self):
     result = colored("hello", "red")
     self.assertEqual(result, "\033[31mhello\033[0m")
Exemplo n.º 5
0
 def test_empty(self):
     result = colored("", "red")
     self.assertEqual(result, "")
Exemplo n.º 6
0
 def test_bad(self):
     with self.assertRaisesRegex(ValueError, r"invalid attribute name.*"):
         colored("hello", "infrared")
Exemplo n.º 7
0
 def test_env(self):
     with patch.dict("os.environ", {"ANSI_COLORS_DISABLED": "1"}):
         result = colored("hello", "red")
     self.assertEqual(result, "hello")