root / kamaki / cli / utils / test.py @ 46d130c9
History | View | Annotate | Download (13.4 kB)
1 | b3cb58c2 | Stavros Sachtouris | # Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | b3cb58c2 | Stavros Sachtouris | #
|
3 | b3cb58c2 | Stavros Sachtouris | # Redistribution and use in source and binary forms, with or
|
4 | b3cb58c2 | Stavros Sachtouris | # without modification, are permitted provided that the following
|
5 | b3cb58c2 | Stavros Sachtouris | # conditions are met:
|
6 | b3cb58c2 | Stavros Sachtouris | #
|
7 | b3cb58c2 | Stavros Sachtouris | # 1. Redistributions of source code must retain the above
|
8 | b3cb58c2 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
9 | b3cb58c2 | Stavros Sachtouris | # disclaimer.
|
10 | b3cb58c2 | Stavros Sachtouris | #
|
11 | b3cb58c2 | Stavros Sachtouris | # 2. Redistributions in binary form must reproduce the above
|
12 | b3cb58c2 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
13 | b3cb58c2 | Stavros Sachtouris | # disclaimer in the documentation and/or other materials
|
14 | b3cb58c2 | Stavros Sachtouris | # provided with the distribution.
|
15 | b3cb58c2 | Stavros Sachtouris | #
|
16 | b3cb58c2 | Stavros Sachtouris | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | b3cb58c2 | Stavros Sachtouris | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | b3cb58c2 | Stavros Sachtouris | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | b3cb58c2 | Stavros Sachtouris | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | b3cb58c2 | Stavros Sachtouris | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | b3cb58c2 | Stavros Sachtouris | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | b3cb58c2 | Stavros Sachtouris | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | b3cb58c2 | Stavros Sachtouris | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | b3cb58c2 | Stavros Sachtouris | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | b3cb58c2 | Stavros Sachtouris | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | b3cb58c2 | Stavros Sachtouris | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | b3cb58c2 | Stavros Sachtouris | # POSSIBILITY OF SUCH DAMAGE.
|
28 | b3cb58c2 | Stavros Sachtouris | #
|
29 | b3cb58c2 | Stavros Sachtouris | # The views and conclusions contained in the software and
|
30 | b3cb58c2 | Stavros Sachtouris | # documentation are those of the authors and should not be
|
31 | b3cb58c2 | Stavros Sachtouris | # interpreted as representing official policies, either expressed
|
32 | b3cb58c2 | Stavros Sachtouris | # or implied, of GRNET S.A.
|
33 | b3cb58c2 | Stavros Sachtouris | |
34 | b3cb58c2 | Stavros Sachtouris | from unittest import TestCase |
35 | b3cb58c2 | Stavros Sachtouris | #from tempfile import NamedTemporaryFile
|
36 | 0f383dcc | Stavros Sachtouris | from mock import patch, call |
37 | b3cb58c2 | Stavros Sachtouris | from itertools import product |
38 | b3cb58c2 | Stavros Sachtouris | |
39 | b3cb58c2 | Stavros Sachtouris | |
40 | b3cb58c2 | Stavros Sachtouris | class UtilsMethods(TestCase): |
41 | b3cb58c2 | Stavros Sachtouris | |
42 | b3cb58c2 | Stavros Sachtouris | def assert_dicts_are_equal(self, d1, d2): |
43 | b3cb58c2 | Stavros Sachtouris | for k, v in d1.items(): |
44 | b3cb58c2 | Stavros Sachtouris | self.assertTrue(k in d2) |
45 | b3cb58c2 | Stavros Sachtouris | if isinstance(v, dict): |
46 | b3cb58c2 | Stavros Sachtouris | self.assert_dicts_are_equal(v, d2[k])
|
47 | b3cb58c2 | Stavros Sachtouris | else:
|
48 | b3cb58c2 | Stavros Sachtouris | self.assertEqual(unicode(v), unicode(d2[k])) |
49 | b3cb58c2 | Stavros Sachtouris | |
50 | b3cb58c2 | Stavros Sachtouris | def test_guess_mime_type(self): |
51 | b3cb58c2 | Stavros Sachtouris | from kamaki.cli.utils import guess_mime_type |
52 | b3cb58c2 | Stavros Sachtouris | from mimetypes import guess_type |
53 | b3cb58c2 | Stavros Sachtouris | for args in product( |
54 | b3cb58c2 | Stavros Sachtouris | ('file.txt', 'file.png', 'file.zip', 'file.gz', None, 'X'), |
55 | b3cb58c2 | Stavros Sachtouris | ('a type', None), |
56 | b3cb58c2 | Stavros Sachtouris | ('an/encoding', None)): |
57 | b3cb58c2 | Stavros Sachtouris | filename, ctype, cencoding = args |
58 | b3cb58c2 | Stavros Sachtouris | if filename:
|
59 | b3cb58c2 | Stavros Sachtouris | exp_type, exp_enc = guess_type(filename) |
60 | b3cb58c2 | Stavros Sachtouris | self.assertEqual(
|
61 | b3cb58c2 | Stavros Sachtouris | guess_mime_type(*args), |
62 | b3cb58c2 | Stavros Sachtouris | (exp_type or ctype, exp_enc or cencoding)) |
63 | b3cb58c2 | Stavros Sachtouris | else:
|
64 | b3cb58c2 | Stavros Sachtouris | self.assertRaises(AssertionError, guess_mime_type, *args) |
65 | b3cb58c2 | Stavros Sachtouris | |
66 | 0f383dcc | Stavros Sachtouris | @patch('kamaki.cli.utils.dumps', return_value='(dumps output)') |
67 | 0f383dcc | Stavros Sachtouris | @patch('kamaki.cli.utils._print') |
68 | 0f383dcc | Stavros Sachtouris | def test_print_json(self, PR, JD): |
69 | 0f383dcc | Stavros Sachtouris | from kamaki.cli.utils import print_json, INDENT_TAB |
70 | 0f383dcc | Stavros Sachtouris | print_json('some data')
|
71 | 0f383dcc | Stavros Sachtouris | JD.assert_called_once_with('some data', indent=INDENT_TAB)
|
72 | 0f383dcc | Stavros Sachtouris | PR.assert_called_once_with('(dumps output)')
|
73 | 0f383dcc | Stavros Sachtouris | |
74 | 0f383dcc | Stavros Sachtouris | @patch('kamaki.cli.utils._print') |
75 | 0f383dcc | Stavros Sachtouris | def test_print_dict(self, PR): |
76 | 0f383dcc | Stavros Sachtouris | from kamaki.cli.utils import print_dict, INDENT_TAB |
77 | 0f383dcc | Stavros Sachtouris | call_counter = 0
|
78 | 0f383dcc | Stavros Sachtouris | self.assertRaises(AssertionError, print_dict, 'non-dict think') |
79 | 0f383dcc | Stavros Sachtouris | self.assertRaises(AssertionError, print_dict, {}, indent=-10) |
80 | 0f383dcc | Stavros Sachtouris | for args in product( |
81 | b3cb58c2 | Stavros Sachtouris | ( |
82 | 0f383dcc | Stavros Sachtouris | {'k1': 'v1'}, |
83 | 0f383dcc | Stavros Sachtouris | {'k1': 'v1', 'k2': 'v2'}, |
84 | 0f383dcc | Stavros Sachtouris | {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}, |
85 | 0f383dcc | Stavros Sachtouris | {'k1': 'v1', 'k2': {'k1': 'v1', 'k2': 'v2'}, 'k3': 'v3'}, |
86 | b3cb58c2 | Stavros Sachtouris | { |
87 | 0f383dcc | Stavros Sachtouris | 'k1': {'k1': 'v1', 'k2': 'v2'}, |
88 | 0f383dcc | Stavros Sachtouris | 'k2': [1, 2, 3], |
89 | 0f383dcc | Stavros Sachtouris | 'k3': 'v3'}, |
90 | 0f383dcc | Stavros Sachtouris | { |
91 | 0f383dcc | Stavros Sachtouris | 'k1': {'k1': 'v1', 'k2': 'v2'}, |
92 | 0f383dcc | Stavros Sachtouris | 'k2': 42, |
93 | 0f383dcc | Stavros Sachtouris | 'k3': {'k1': 1, 'k2': [1, 2, 3]}}, |
94 | b3cb58c2 | Stavros Sachtouris | { |
95 | 0f383dcc | Stavros Sachtouris | 'k1': {
|
96 | 0f383dcc | Stavros Sachtouris | 'k1': 'v1', |
97 | 0f383dcc | Stavros Sachtouris | 'k2': [1, 2, 3], |
98 | 0f383dcc | Stavros Sachtouris | 'k3': {'k1': [(1, 2)]}}, |
99 | 0f383dcc | Stavros Sachtouris | 'k2': (3, 4, 5), |
100 | 0f383dcc | Stavros Sachtouris | 'k3': {'k1': 1, 'k2': [1, 2, 3]}}), |
101 | 0f383dcc | Stavros Sachtouris | (tuple(), ('k1', ), ('k1', 'k2')), |
102 | 0f383dcc | Stavros Sachtouris | (0, 1, 2, 9), (False, True), (False, True)): |
103 | 0f383dcc | Stavros Sachtouris | d, exclude, indent, with_enumeration, recursive_enumeration = args |
104 | 0f383dcc | Stavros Sachtouris | with patch('kamaki.cli.utils.print_dict') as PD: |
105 | 0f383dcc | Stavros Sachtouris | with patch('kamaki.cli.utils.print_list') as PL: |
106 | 0f383dcc | Stavros Sachtouris | pd_calls, pl_calls = 0, 0 |
107 | 0f383dcc | Stavros Sachtouris | print_dict(*args) |
108 | 0f383dcc | Stavros Sachtouris | exp_calls = [] |
109 | 0f383dcc | Stavros Sachtouris | for i, (k, v) in enumerate(d.items()): |
110 | 0f383dcc | Stavros Sachtouris | if k in exclude: |
111 | 0f383dcc | Stavros Sachtouris | continue
|
112 | 0f383dcc | Stavros Sachtouris | str_k = ' ' * indent
|
113 | 0f383dcc | Stavros Sachtouris | str_k += '%s.' % (i + 1) if with_enumeration else '' |
114 | 0f383dcc | Stavros Sachtouris | str_k += '%s:' % k
|
115 | 0f383dcc | Stavros Sachtouris | if isinstance(v, dict): |
116 | 0f383dcc | Stavros Sachtouris | self.assertEqual(
|
117 | 0f383dcc | Stavros Sachtouris | PD.mock_calls[pd_calls], |
118 | 0f383dcc | Stavros Sachtouris | call( |
119 | 0f383dcc | Stavros Sachtouris | v, |
120 | 0f383dcc | Stavros Sachtouris | exclude, |
121 | 0f383dcc | Stavros Sachtouris | indent + INDENT_TAB, |
122 | 0f383dcc | Stavros Sachtouris | recursive_enumeration, |
123 | 0f383dcc | Stavros Sachtouris | recursive_enumeration)) |
124 | 0f383dcc | Stavros Sachtouris | pd_calls += 1
|
125 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call(str_k)) |
126 | 0f383dcc | Stavros Sachtouris | elif isinstance(v, list) or isinstance(v, tuple): |
127 | 0f383dcc | Stavros Sachtouris | self.assertEqual(
|
128 | 0f383dcc | Stavros Sachtouris | PL.mock_calls[pl_calls], |
129 | 0f383dcc | Stavros Sachtouris | call( |
130 | 0f383dcc | Stavros Sachtouris | v, |
131 | 0f383dcc | Stavros Sachtouris | exclude, |
132 | 0f383dcc | Stavros Sachtouris | indent + INDENT_TAB, |
133 | 0f383dcc | Stavros Sachtouris | recursive_enumeration, |
134 | 0f383dcc | Stavros Sachtouris | recursive_enumeration)) |
135 | 0f383dcc | Stavros Sachtouris | pl_calls += 1
|
136 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call(str_k)) |
137 | 0f383dcc | Stavros Sachtouris | else:
|
138 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call('%s %s' % (str_k, v)))
|
139 | 0f383dcc | Stavros Sachtouris | real_calls = PR.mock_calls[call_counter:] |
140 | 0f383dcc | Stavros Sachtouris | call_counter = len(PR.mock_calls)
|
141 | 0f383dcc | Stavros Sachtouris | self.assertEqual(sorted(real_calls), sorted(exp_calls)) |
142 | 0f383dcc | Stavros Sachtouris | |
143 | 0f383dcc | Stavros Sachtouris | @patch('kamaki.cli.utils._print') |
144 | 0f383dcc | Stavros Sachtouris | def test_print_list(self, PR): |
145 | 0f383dcc | Stavros Sachtouris | from kamaki.cli.utils import print_list, INDENT_TAB |
146 | 0f383dcc | Stavros Sachtouris | call_counter = 0
|
147 | 0f383dcc | Stavros Sachtouris | self.assertRaises(AssertionError, print_list, 'non-list non-tuple') |
148 | 0f383dcc | Stavros Sachtouris | self.assertRaises(AssertionError, print_list, {}, indent=-10) |
149 | 0f383dcc | Stavros Sachtouris | for args in product( |
150 | 0f383dcc | Stavros Sachtouris | ( |
151 | 0f383dcc | Stavros Sachtouris | ['v1', ],
|
152 | 0f383dcc | Stavros Sachtouris | ('v2', 'v3'), |
153 | 0f383dcc | Stavros Sachtouris | [1, '2', 'v3'], |
154 | 0f383dcc | Stavros Sachtouris | ({'k1': 'v1'}, 2, 'v3'), |
155 | 0f383dcc | Stavros Sachtouris | [(1, 2), 'v2', [(3, 4), {'k3': [5, 6], 'k4': 7}]]), |
156 | 0f383dcc | Stavros Sachtouris | (tuple(), ('v1', ), ('v1', 1), ('v1', 'k3')), |
157 | 0f383dcc | Stavros Sachtouris | (0, 1, 2, 9), (False, True), (False, True)): |
158 | 0f383dcc | Stavros Sachtouris | l, exclude, indent, with_enumeration, recursive_enumeration = args |
159 | 0f383dcc | Stavros Sachtouris | with patch('kamaki.cli.utils.print_dict') as PD: |
160 | 0f383dcc | Stavros Sachtouris | with patch('kamaki.cli.utils.print_list') as PL: |
161 | 0f383dcc | Stavros Sachtouris | pd_calls, pl_calls = 0, 0 |
162 | 0f383dcc | Stavros Sachtouris | print_list(*args) |
163 | 0f383dcc | Stavros Sachtouris | exp_calls = [] |
164 | 0f383dcc | Stavros Sachtouris | for i, v in enumerate(l): |
165 | 0f383dcc | Stavros Sachtouris | str_v = ' ' * indent
|
166 | 0f383dcc | Stavros Sachtouris | str_v += '%s.' % (i + 1) if with_enumeration else '' |
167 | 0f383dcc | Stavros Sachtouris | if isinstance(v, dict): |
168 | 0f383dcc | Stavros Sachtouris | if with_enumeration:
|
169 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call(str_v)) |
170 | 0f383dcc | Stavros Sachtouris | elif i and i < len(l): |
171 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call()) |
172 | 0f383dcc | Stavros Sachtouris | self.assertEqual(
|
173 | 0f383dcc | Stavros Sachtouris | PD.mock_calls[pd_calls], |
174 | 0f383dcc | Stavros Sachtouris | call( |
175 | 0f383dcc | Stavros Sachtouris | v, |
176 | 0f383dcc | Stavros Sachtouris | exclude, |
177 | 0f383dcc | Stavros Sachtouris | indent + ( |
178 | 0f383dcc | Stavros Sachtouris | INDENT_TAB if with_enumeration else 0), |
179 | 0f383dcc | Stavros Sachtouris | recursive_enumeration, |
180 | 0f383dcc | Stavros Sachtouris | recursive_enumeration)) |
181 | 0f383dcc | Stavros Sachtouris | pd_calls += 1
|
182 | 0f383dcc | Stavros Sachtouris | elif isinstance(v, list) or isinstance(v, tuple): |
183 | 0f383dcc | Stavros Sachtouris | if with_enumeration:
|
184 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call(str_v)) |
185 | 0f383dcc | Stavros Sachtouris | elif i and i < len(l): |
186 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call()) |
187 | 0f383dcc | Stavros Sachtouris | self.assertEqual(
|
188 | 0f383dcc | Stavros Sachtouris | PL.mock_calls[pl_calls], |
189 | 0f383dcc | Stavros Sachtouris | call( |
190 | 0f383dcc | Stavros Sachtouris | v, |
191 | 0f383dcc | Stavros Sachtouris | exclude, |
192 | 0f383dcc | Stavros Sachtouris | indent + INDENT_TAB, |
193 | 0f383dcc | Stavros Sachtouris | recursive_enumeration, |
194 | 0f383dcc | Stavros Sachtouris | recursive_enumeration)) |
195 | 0f383dcc | Stavros Sachtouris | pl_calls += 1
|
196 | 0f383dcc | Stavros Sachtouris | elif ('%s' % v) in exclude: |
197 | 0f383dcc | Stavros Sachtouris | continue
|
198 | 0f383dcc | Stavros Sachtouris | else:
|
199 | 0f383dcc | Stavros Sachtouris | exp_calls.append(call('%s%s' % (str_v, v)))
|
200 | 0f383dcc | Stavros Sachtouris | real_calls = PR.mock_calls[call_counter:] |
201 | 0f383dcc | Stavros Sachtouris | call_counter = len(PR.mock_calls)
|
202 | 0f383dcc | Stavros Sachtouris | self.assertEqual(sorted(real_calls), sorted(exp_calls)) |
203 | b3cb58c2 | Stavros Sachtouris | |
204 | 46d130c9 | Stavros Sachtouris | @patch('__builtin__.raw_input') |
205 | 46d130c9 | Stavros Sachtouris | def test_page_hold(self, RI): |
206 | 46d130c9 | Stavros Sachtouris | from kamaki.cli.utils import page_hold |
207 | 46d130c9 | Stavros Sachtouris | ri_counter = 0
|
208 | 46d130c9 | Stavros Sachtouris | for args, expected in ( |
209 | 46d130c9 | Stavros Sachtouris | ((0, 0, 0), False), |
210 | 46d130c9 | Stavros Sachtouris | ((1, 3, 10), True), |
211 | 46d130c9 | Stavros Sachtouris | ((3, 3, 10), True), |
212 | 46d130c9 | Stavros Sachtouris | ((5, 3, 10), True), |
213 | 46d130c9 | Stavros Sachtouris | ((6, 3, 10), True), |
214 | 46d130c9 | Stavros Sachtouris | ((10, 3, 10), False), |
215 | 46d130c9 | Stavros Sachtouris | ((11, 3, 10), False)): |
216 | 46d130c9 | Stavros Sachtouris | self.assertEqual(page_hold(*args), expected)
|
217 | 46d130c9 | Stavros Sachtouris | index, limit, maxlen = args |
218 | 46d130c9 | Stavros Sachtouris | if index and index < maxlen and index % limit == 0: |
219 | 46d130c9 | Stavros Sachtouris | self.assertEqual(ri_counter + 1, len(RI.mock_calls)) |
220 | 46d130c9 | Stavros Sachtouris | self.assertEqual(RI.mock_calls[-1], call( |
221 | 46d130c9 | Stavros Sachtouris | '(%s listed - %s more - "enter" to continue)' % (
|
222 | 46d130c9 | Stavros Sachtouris | index, maxlen - index))) |
223 | 46d130c9 | Stavros Sachtouris | else:
|
224 | 46d130c9 | Stavros Sachtouris | self.assertEqual(ri_counter, len(RI.mock_calls)) |
225 | 46d130c9 | Stavros Sachtouris | ri_counter = len(RI.mock_calls)
|
226 | 46d130c9 | Stavros Sachtouris | |
227 | 46d130c9 | Stavros Sachtouris | @patch('kamaki.cli.utils._print') |
228 | 46d130c9 | Stavros Sachtouris | @patch('kamaki.cli.utils._write') |
229 | 46d130c9 | Stavros Sachtouris | @patch('kamaki.cli.utils.print_dict') |
230 | 46d130c9 | Stavros Sachtouris | @patch('kamaki.cli.utils.print_list') |
231 | 46d130c9 | Stavros Sachtouris | @patch('kamaki.cli.utils.page_hold') |
232 | 46d130c9 | Stavros Sachtouris | @patch('kamaki.cli.utils.bold', return_value='bold') |
233 | 46d130c9 | Stavros Sachtouris | def test_print_items(self, bold, PH, PL, PD, WR, PR): |
234 | 46d130c9 | Stavros Sachtouris | from kamaki.cli.utils import print_items, INDENT_TAB |
235 | 46d130c9 | Stavros Sachtouris | for args in product( |
236 | 46d130c9 | Stavros Sachtouris | ( |
237 | 46d130c9 | Stavros Sachtouris | 42, None, 'simple outputs', |
238 | 46d130c9 | Stavros Sachtouris | [1, 2, 3], {1: 1, 2: 2}, (3, 4), |
239 | 46d130c9 | Stavros Sachtouris | ({'k': 1, 'id': 2}, [5, 6, 7], (8, 9), '10')), |
240 | 46d130c9 | Stavros Sachtouris | (('id', 'name'), ('something', 2), ('lala', )), |
241 | 46d130c9 | Stavros Sachtouris | (False, True), |
242 | 46d130c9 | Stavros Sachtouris | (False, True), |
243 | 46d130c9 | Stavros Sachtouris | (0, 1, 2, 10)): |
244 | 46d130c9 | Stavros Sachtouris | items, title, with_enumeration, with_redundancy, page_size = args |
245 | 46d130c9 | Stavros Sachtouris | wr_counter, pr_counter = len(WR.mock_calls), len(PR.mock_calls) |
246 | 46d130c9 | Stavros Sachtouris | pl_counter, pd_counter = len(PL.mock_calls), len(PD.mock_calls) |
247 | 46d130c9 | Stavros Sachtouris | bold_counter, ph_counter = len(bold.mock_calls), len(PH.mock_calls) |
248 | 46d130c9 | Stavros Sachtouris | print_items(*args) |
249 | 46d130c9 | Stavros Sachtouris | if not (isinstance(items, dict) or isinstance( |
250 | 46d130c9 | Stavros Sachtouris | items, list) or isinstance(items, tuple)): |
251 | 46d130c9 | Stavros Sachtouris | self.assertEqual(PR.mock_calls[-1], call( |
252 | 46d130c9 | Stavros Sachtouris | '%s' % items if items is not None else '')) |
253 | 46d130c9 | Stavros Sachtouris | else:
|
254 | 46d130c9 | Stavros Sachtouris | for i, item in enumerate(items): |
255 | 46d130c9 | Stavros Sachtouris | if with_enumeration:
|
256 | 46d130c9 | Stavros Sachtouris | self.assertEqual(
|
257 | 46d130c9 | Stavros Sachtouris | WR.mock_calls[wr_counter], |
258 | 46d130c9 | Stavros Sachtouris | call('%s. ' % (i + 1))) |
259 | 46d130c9 | Stavros Sachtouris | wr_counter += 1
|
260 | 46d130c9 | Stavros Sachtouris | if isinstance(item, dict): |
261 | 46d130c9 | Stavros Sachtouris | title = sorted(set(title).intersection(item)) |
262 | 46d130c9 | Stavros Sachtouris | pick = item.get if with_redundancy else item.pop |
263 | 46d130c9 | Stavros Sachtouris | header = ' '.join('%s' % pick(key) for key in title) |
264 | 46d130c9 | Stavros Sachtouris | self.assertEqual(
|
265 | 46d130c9 | Stavros Sachtouris | bold.mock_calls[bold_counter], call(header)) |
266 | 46d130c9 | Stavros Sachtouris | self.assertEqual(
|
267 | 46d130c9 | Stavros Sachtouris | PR.mock_calls[pr_counter], call('bold'))
|
268 | 46d130c9 | Stavros Sachtouris | self.assertEqual(
|
269 | 46d130c9 | Stavros Sachtouris | PD.mock_calls[pd_counter], |
270 | 46d130c9 | Stavros Sachtouris | call(item, indent=INDENT_TAB)) |
271 | 46d130c9 | Stavros Sachtouris | pr_counter += 1
|
272 | 46d130c9 | Stavros Sachtouris | pd_counter += 1
|
273 | 46d130c9 | Stavros Sachtouris | bold_counter += 1
|
274 | 46d130c9 | Stavros Sachtouris | elif isinstance(item, list) or isinstance(item, tuple): |
275 | 46d130c9 | Stavros Sachtouris | self.assertEqual(
|
276 | 46d130c9 | Stavros Sachtouris | PL.mock_calls[pl_counter], |
277 | 46d130c9 | Stavros Sachtouris | call(item, indent=INDENT_TAB)) |
278 | 46d130c9 | Stavros Sachtouris | pl_counter += 1
|
279 | 46d130c9 | Stavros Sachtouris | else:
|
280 | 46d130c9 | Stavros Sachtouris | self.assertEqual(
|
281 | 46d130c9 | Stavros Sachtouris | PR.mock_calls[pr_counter], call(' %s' % item))
|
282 | 46d130c9 | Stavros Sachtouris | pr_counter += 1
|
283 | 46d130c9 | Stavros Sachtouris | page_size = page_size if page_size > 0 else len(items) |
284 | 46d130c9 | Stavros Sachtouris | self.assertEqual(
|
285 | 46d130c9 | Stavros Sachtouris | PH.mock_calls[ph_counter], |
286 | 46d130c9 | Stavros Sachtouris | call(i + 1, page_size, len(items))) |
287 | 46d130c9 | Stavros Sachtouris | ph_counter += 1
|
288 | 46d130c9 | Stavros Sachtouris | |
289 | b3cb58c2 | Stavros Sachtouris | |
290 | b3cb58c2 | Stavros Sachtouris | if __name__ == '__main__': |
291 | b3cb58c2 | Stavros Sachtouris | from sys import argv |
292 | b3cb58c2 | Stavros Sachtouris | from kamaki.cli.test import runTestCase |
293 | b3cb58c2 | Stavros Sachtouris | runTestCase(UtilsMethods, 'UtilsMethods', argv[1:]) |