diff --git a/tests/test_utils.py b/tests/test_utils.py index 3f275b8e6..279f5d62a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -15,6 +15,8 @@ import errno import testtools +import sys +import StringIO from glanceclient.common import utils @@ -69,6 +71,47 @@ def test_ensure_unicode(self): self.assertEqual(u'ni\xf1o', ensure_unicode('ni\xc3\xb1o', incoming='ascii')) + def test_prettytable(self): + class Struct: + def __init__(self, **entries): + self.__dict__.update(entries) + + # test that the prettytable output is wellformatted (left-aligned) + columns = ['ID', 'Name'] + val = ['Name1', 'another', 'veeeery long'] + images = [Struct(**{'id': i ** 16, 'name': val[i]}) + for i in range(len(val))] + + saved_stdout = sys.stdout + try: + sys.stdout = output_list = StringIO.StringIO() + utils.print_list(images, columns) + + sys.stdout = output_dict = StringIO.StringIO() + utils.print_dict({'K': 'k', 'Key': 'Value'}) + + finally: + sys.stdout = saved_stdout + + self.assertEqual(output_list.getvalue(), '''\ ++-------+--------------+ +| ID | Name | ++-------+--------------+ +| | Name1 | +| 1 | another | +| 65536 | veeeery long | ++-------+--------------+ +''') + + self.assertEqual(output_dict.getvalue(), '''\ ++----------+-------+ +| Property | Value | ++----------+-------+ +| K | k | +| Key | Value | ++----------+-------+ +''') + def test_ensure_str(self): ensure_str = utils.ensure_str self.assertEqual("True", ensure_str(True)) diff --git a/tools/pip-requires b/tools/pip-requires index e5a994121..7aaf5daa6 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -1,5 +1,5 @@ argparse -prettytable>=0.6,<0.7 +prettytable>=0.6,<0.8 python-keystoneclient>=0.1.2,<1 pyOpenSSL warlock>=0.7.0,<2