diff options
author | 2017-03-29 13:35:45 +0300 | |
---|---|---|
committer | 2017-03-29 13:35:45 +0300 | |
commit | e2cc2530fc6d54ebc975c01a4ff887ce12f0a736 (patch) | |
tree | 38385867295c8a09fb0d7f8eaf5fa78179e5b13a /jython-tosca-parser/src/main/resources/Lib/site-packages/cliff-2.4.0-py2.7.egg/cliff/tests/test_show.py | |
parent | bccebaa9888906f8ff78172f62ec592956066d82 (diff) |
[SDC-6] sdc-distribution-client 1707 rebasing
Change-Id: I322a05fd79beb6ba4fee4d32afffecf531b86e98
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'jython-tosca-parser/src/main/resources/Lib/site-packages/cliff-2.4.0-py2.7.egg/cliff/tests/test_show.py')
-rw-r--r-- | jython-tosca-parser/src/main/resources/Lib/site-packages/cliff-2.4.0-py2.7.egg/cliff/tests/test_show.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/cliff-2.4.0-py2.7.egg/cliff/tests/test_show.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/cliff-2.4.0-py2.7.egg/cliff/tests/test_show.py new file mode 100644 index 0000000..9e46c54 --- /dev/null +++ b/jython-tosca-parser/src/main/resources/Lib/site-packages/cliff-2.4.0-py2.7.egg/cliff/tests/test_show.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import weakref + +from cliff import show + +import mock + + +class FauxFormatter(object): + + def __init__(self): + self.args = [] + self.obj = weakref.proxy(self) + + def emit_one(self, columns, data, stdout, args): + self.args.append((columns, data)) + + +class ExerciseShowOne(show.ShowOne): + + def _load_formatter_plugins(self): + return { + 'test': FauxFormatter(), + } + + def take_action(self, parsed_args): + return ( + parsed_args.columns, + [('a', 'A'), ('b', 'B')], + ) + + +def test_formatter_args(): + app = mock.Mock() + test_show = ExerciseShowOne(app, []) + + parsed_args = mock.Mock() + parsed_args.columns = ('Col1', 'Col2') + parsed_args.formatter = 'test' + + test_show.run(parsed_args) + f = test_show._formatter_plugins['test'] + assert len(f.args) == 1 + args = f.args[0] + assert args[0] == list(parsed_args.columns) + data = list(args[1]) + assert data == [('a', 'A'), ('b', 'B')] + + +def test_dict2columns(): + app = mock.Mock() + test_show = ExerciseShowOne(app, []) + d = {'a': 'A', 'b': 'B', 'c': 'C'} + expected = [('a', 'b', 'c'), ('A', 'B', 'C')] + actual = list(test_show.dict2columns(d)) + assert expected == actual + + +def test_no_exist_column(): + test_show = ExerciseShowOne(mock.Mock(), []) + parsed_args = mock.Mock() + parsed_args.columns = ('no_exist_column',) + parsed_args.formatter = 'test' + with mock.patch.object(test_show, 'take_action') as mock_take_action: + mock_take_action.return_value = (('Col1', 'Col2', 'Col3'), []) + try: + test_show.run(parsed_args) + except ValueError: + pass + else: + assert False, 'Should have had an exception' |