diff options
author | Martin Matusiak <numerodix@gmail.com> | 2014-03-08 19:50:14 +0100 |
---|---|---|
committer | Martin Matusiak <numerodix@gmail.com> | 2014-03-08 19:50:14 +0100 |
commit | 7e335dfd75db8a5eeac9cdbc9da539486c07d3f3 (patch) | |
tree | 4c0b60c489c700757d85298932dfb94e4288e4a3 /tests | |
parent | 5ab5f0ccdb6a09ed96391c73473ee233f6d56985 (diff) | |
parent | c97681ddf26ed52f02800140d81dc69ff54dcee8 (diff) | |
download | ansicolor-0.0.4.tar.gz |
Merge branch 'release/0.0.4'0.0.4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/test_colors.py | 91 | ||||
-rw-r--r-- | tests/test_imports.py | 33 |
3 files changed, 124 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/test_colors.py b/tests/test_colors.py new file mode 100644 index 0000000..0e1bb1a --- /dev/null +++ b/tests/test_colors.py @@ -0,0 +1,91 @@ +from ansicolor import Colors +from ansicolor import blue +from ansicolor import colordiff +from ansicolor import colorize +from ansicolor import get_code +from ansicolor import get_highlighter +from ansicolor import justify_formatted +from ansicolor import red +from ansicolor import strip_escapes +from ansicolor import wrap_string + + +def test_codes(): + # reset code + assert '\033[0;0m' == get_code(None) + + # plain color codes + assert '\033[0;0;30m' == get_code(Colors.Black) + assert '\033[0;0;31m' == get_code(Colors.Red) + assert '\033[0;0;32m' == get_code(Colors.Green) + assert '\033[0;0;33m' == get_code(Colors.Yellow) + assert '\033[0;0;34m' == get_code(Colors.Blue) + assert '\033[0;0;35m' == get_code(Colors.Magenta) + assert '\033[0;0;36m' == get_code(Colors.Cyan) + assert '\033[0;0;37m' == get_code(Colors.White) + + # bold color + assert '\033[0;1;31m' == get_code(Colors.Red, bold=True) + + # reverse color + assert '\033[0;7;31m' == get_code(Colors.Red, reverse=True) + + # bold + reverse color + assert '\033[1;7;31m' == get_code(Colors.Red, bold=True, reverse=True) + + +def test_coloring(): + assert '\033[0;0;31m' + 'hi' + '\033[0;0m' == red('hi') + + +def test_highlights(): + # can I get a highlighter? + assert Colors.Green == get_highlighter(0) + assert Colors.Yellow == get_highlighter(1) + + +def test_colorize(): + assert ( + get_code(Colors.Red) + + "Hi there" + + get_code(None) + ) == colorize("Hi there", Colors.Red) + + +def test_wrap_string(): + assert ( + get_code(Colors.Red) + + "Hi " + + get_code(None) + + "there" + ) == wrap_string("Hi there", 3, Colors.Red) + + +def test_strip_escapes(): + assert "Hi there" == strip_escapes(wrap_string("Hi there", 3, Colors.Red)) + + assert strip_escapes( + colorize("Hi", None, bold=True) + + " there, " + + colorize("stranger", Colors.Green, bold=True) + ) == "Hi there, stranger" + + +def test_colordiff(): + x, y = colordiff("hi bob", "hi there", + color_x=Colors.Red, color_y=Colors.Blue) + + fx = lambda s: red(s, reverse=True) + fy = lambda s: blue(s, reverse=True) + + assert x == "hi " + fx("b") + fx("o") + fx("b") + assert y == "hi " + fy("t") + fy("h") + fy("e") + fy("r") + fy("e") + + +def test_justify_formatted(): + def rjust(s, width): + return s.rjust(width) + + assert justify_formatted( + red("hi"), rjust, 10 + ) == " " + red("hi") diff --git a/tests/test_imports.py b/tests/test_imports.py new file mode 100644 index 0000000..ed5f654 --- /dev/null +++ b/tests/test_imports.py @@ -0,0 +1,33 @@ +def test_importability(): + from ansicolor import black # noqa + from ansicolor import blue # noqa + from ansicolor import cyan # noqa + from ansicolor import green # noqa + from ansicolor import magenta # noqa + from ansicolor import red # noqa + from ansicolor import white # noqa + from ansicolor import yellow # noqa + + from ansicolor import Colors # noqa + Colors.Black + Colors.Blue + Colors.Cyan + Colors.Green + Colors.Magenta + Colors.Red + Colors.White + Colors.Yellow + + from ansicolor import get_highlighter # noqa + from ansicolor import get_code # noqa + + from ansicolor import colorize # noqa + from ansicolor import wrap_string # noqa + from ansicolor import highlight_string # noqa + from ansicolor import colordiff # noqa + from ansicolor import justify_formatted # noqa + from ansicolor import strip_escapes # noqa + from ansicolor import set_term_title # noqa + + from ansicolor import write_err # noqa + from ansicolor import write_out # noqa |