Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaille committed Feb 21, 2018
1 parent 31e79f4 commit 944b271
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 40 deletions.
2 changes: 1 addition & 1 deletion buzio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

init()

__version__ = "1.1.0"
__version__ = "1.1.1"

console = Console()
formatStr = Console(format_only=True)
92 changes: 54 additions & 38 deletions buzio/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from collections import OrderedDict
from colorama import Fore

try:
from unittest.mock import patch
except ImportError:
from mock import patch


class BaseTest(unittest.TestCase):
"""Base Unit Tests Class."""
Expand Down Expand Up @@ -111,11 +116,11 @@ def test_print_with_prefix(self):
def test_print_with_transform(self):
"""test_print_with_transform."""
self.instance.text = "Hello World"
self.instance.transform = "upper"
self.instance.transform = "small"
ret = self.instance._print()
self.assertEqual(
ret,
"HELLO WORLD"
"hello world"
)

def test_print_with_theme(self):
Expand Down Expand Up @@ -151,6 +156,24 @@ def test_list_with_breaklines(self):
"\x1b[36mFirst Line\x1b[0m\x1b[36mSecond Line\x1b[0m"
)

def test_load_new_theme(self):
"""test_load_new_theme."""
new_theme = {
'test': Fore.RED
}
self.instance.load_theme(new_theme)
self.instance.theme = 'test'
self.assertEqual(
self.instance._get_style(),
Fore.RED
)

def test_load_wrong_theme(self):
"""test_load_wrong_theme."""
new_theme = "ORANGE"
with self.assertRaises(ValueError):
self.instance.load_theme(new_theme)


class StyleTestCase(BaseTest):
"""Unit Tests for Styles."""
Expand Down Expand Up @@ -243,64 +266,57 @@ def test_progress(self):
"-------------------| 50.00% Complete "
)

def test_load_new_theme(self):
"""test_load_new_theme."""
new_theme = {
'test': Fore.RED
}
self.instance.load_theme(new_theme)
self.instance.theme = 'test'
self.assertEqual(
self.instance._get_style(),
Fore.RED
)

def test_confirm(self):
"""test_confirm."""
self.instance.format_only = True
ret = self.instance.confirm()
self.assertEqual(
ret[0],
'\x1b[95mPlease confirm (y/n) \x1b[0m'
)
user_input = "y"
with patch('__builtin__.input', side_effect=user_input):
ret = self.instance.confirm()
self.assertTrue(ret)

def test_choose(self):
"""test_choose."""
self.instance.format_only = True
options = ["Apple", "Orange", "Banana"]
ret = self.instance.choose(options)
user_input = "2"
with patch('__builtin__.input', side_effect=user_input):
ret = self.instance.choose(options)
self.assertEqual(
ret[1],
'\x1b[93m2. Orange\x1b[0m'
ret,
'Orange'
)

def test_choose_with_default(self):
"""test_choose_with_default."""
self.instance.format_only = True
options = ["Apple", "Orange", "Banana"]
ret = self.instance.choose(options, default="Apple")
with patch('__builtin__.input'):
ret = self.instance.choose(options, default="Apple")

self.assertEqual(
ret[-1],
'\x1b[93m\x1b[0m'
ret,
'Apple'
)

def test_ask(self):
"""test_ask."""
self.instance.format_only = True
ret = self.instance.ask('How many tests')
self.assertEqual(
ret[0],
'\x1b[33mHow many tests \x1b[0m'
)
def validate_answer(obj):
"""Test validator for ask."""
return int(obj) == 3

user_input = "3"
with patch('__builtin__.input', side_effect=user_input):
ret = self.instance.ask(
'How many tests', validator=validate_answer)

self.assertEqual(ret, "3")

def test_select(self):
"""test_select."""
self.instance.format_only = True
options = ['orange', 'apples']
ret = self.instance.select(options)
user_input = "A"
with patch('__builtin__.input', side_effect=user_input):
ret = self.instance.select(options)
self.assertEqual(
ret[0],
'\x1b[93mSelect: (O)range, (A)pples\x1b[0m'
options[ret],
'apples'
)

def test_run(self):
Expand Down
34 changes: 33 additions & 1 deletion docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,39 @@ The *Show Prefix* column tells if the text to be printed will be the section nam

$ Success: Operation Complete

You can control this behavior with the ``use_prefix`` paramenter. For example: ``console.info("Starting download...", use_prefix=False)```
You can control this behavior with the ``use_prefix`` paramenter. For example: ``console.info("Starting download...", use_prefix=False)``` will print::

$ Starting download...

Transforming text
+++++++++++++++++

You can use the ``transform`` to format text:

.. code-block:: python
>>> console.warning("Hello World", transform="upper")
Warning: HELLO WORLD
>>> console.warning("Hello World", transform="breakline")
Warning:
Hello World
>>> console.warning("Hello World", transform="upper linebreak")
Warning:
HELLO WORLD
>>> console.warning(["Hello", "World"], transform="breakline")
Warning:
Hello
World
Current options for transform are:

* ``upper``: UPPERTEXT
* ``small``: lowertext
* ``title``: Titletext
* ``center``: horizontal centering text in terminal
* ``breakline``: Break lines in text
* ``bold``: Apply Style.BRIGHT effect in text
* ``show_counters``: Add counters to text: 1) Hello 2) World (only for dicts and lists)

The Input styles
----------------
Expand Down

0 comments on commit 944b271

Please sign in to comment.