diff options
Diffstat (limited to 'cliff/tests/test_show.py')
-rw-r--r-- | cliff/tests/test_show.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/cliff/tests/test_show.py b/cliff/tests/test_show.py index 41df5e1..5db07ec 100644 --- a/cliff/tests/test_show.py +++ b/cliff/tests/test_show.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +import weakref + from cliff.show import ShowOne import mock @@ -9,15 +11,16 @@ class FauxFormatter(object): def __init__(self): self.args = [] + self.obj = weakref.proxy(self) - def emit_list(self, columns, data, stdout, args): + def emit_one(self, columns, data, stdout, args): self.args.append((columns, data)) class ExerciseShowOne(ShowOne): - def load_formatter_plugins(self): - self.formatters = { + def _load_formatter_plugins(self): + return { 'test': FauxFormatter(), } return @@ -29,21 +32,22 @@ class ExerciseShowOne(ShowOne): ) -# def test_formatter_args(): -# app = mock.Mock() -# test_lister = ExerciseLister(app, []) +def test_formatter_args(): + app = mock.Mock() + test_show = ExerciseShowOne(app, []) + + parsed_args = mock.Mock() + parsed_args.columns = ('Col1', 'Col2') + parsed_args.formatter = 'test' -# 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')] -# test_lister.run(parsed_args) -# f = test_lister.formatters['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() |