~ubuntu-branches/ubuntu/utopic/python-ceilometerclient/utopic

« back to all changes in this revision

Viewing changes to ceilometerclient/tests/test_utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2014-01-21 09:53:01 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140121095301-cwxsrtdgddkzprjx
Tags: 1.0.8-0ubuntu1
[ James Page ]
* d/control: Add missing BD on python-babel. 

[ Chuck Short ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    under the License.
15
15
 
16
16
 
17
 
import cStringIO
 
17
import six
18
18
import sys
19
19
 
20
20
from ceilometerclient.common import utils
31
31
        # test that the prettytable output is wellformatted (left-aligned)
32
32
        saved_stdout = sys.stdout
33
33
        try:
34
 
            sys.stdout = output_dict = cStringIO.StringIO()
 
34
            sys.stdout = output_dict = six.StringIO()
35
35
            utils.print_dict({'K': 'k', 'Key': 'Value'})
36
36
 
37
37
        finally:
46
46
+----------+-------+
47
47
''')
48
48
 
 
49
    def test_print_list(self):
 
50
        class Foo:
 
51
            def __init__(self, one, two, three):
 
52
                self.one = one
 
53
                self.two = two
 
54
                self.three = three
 
55
 
 
56
        foo_list = [
 
57
            Foo(10, 'a', 'B'),
 
58
            Foo(8, 'c', 'c'),
 
59
            Foo(12, '0', 'Z')]
 
60
 
 
61
        def do_print_list(sortby):
 
62
            saved_stdout = sys.stdout
 
63
            try:
 
64
                sys.stdout = output = six.StringIO()
 
65
                utils.print_list(foo_list,
 
66
                                 ['one', 'two', 'three'],
 
67
                                 ['1st', '2nd', '3rd'],
 
68
                                 {'one': lambda o: o.one * 10},
 
69
                                 sortby)
 
70
            finally:
 
71
                sys.stdout = saved_stdout
 
72
            return output.getvalue()
 
73
 
 
74
        printed = do_print_list(None)
 
75
        self.assertEqual(printed, '''\
 
76
+-----+-----+-----+
 
77
| 1st | 2nd | 3rd |
 
78
+-----+-----+-----+
 
79
| 100 | a   | B   |
 
80
| 80  | c   | c   |
 
81
| 120 | 0   | Z   |
 
82
+-----+-----+-----+
 
83
''')
 
84
 
 
85
        printed = do_print_list(0)
 
86
        self.assertEqual(printed, '''\
 
87
+-----+-----+-----+
 
88
| 1st | 2nd | 3rd |
 
89
+-----+-----+-----+
 
90
| 80  | c   | c   |
 
91
| 100 | a   | B   |
 
92
| 120 | 0   | Z   |
 
93
+-----+-----+-----+
 
94
''')
 
95
 
 
96
        printed = do_print_list(1)
 
97
        self.assertEqual(printed, '''\
 
98
+-----+-----+-----+
 
99
| 1st | 2nd | 3rd |
 
100
+-----+-----+-----+
 
101
| 120 | 0   | Z   |
 
102
| 100 | a   | B   |
 
103
| 80  | c   | c   |
 
104
+-----+-----+-----+
 
105
''')
 
106
 
49
107
    def test_args_array_to_dict(self):
50
108
        my_args = {
51
109
            'matching_metadata': ['metadata.key=metadata_value'],