summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2013-07-26 15:10:59 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2013-07-26 15:17:16 -0400
commit38db7e3eaa224110c0520c9e0c83a1bdbeefee5d (patch)
treebb276bee19ae714b85fc387300fa6e6e4ca1c98e
parent8b5f9a794dc2012b32dc10382798c783023f1f01 (diff)
downloadcliff-38db7e3eaa224110c0520c9e0c83a1bdbeefee5d.tar.gz
add tests for dict2columns
Change-Id: I42e9a9a74af9f5608e67e20f131f6a7155179037
-rw-r--r--docs/source/history.rst5
-rw-r--r--tests/test_show.py54
2 files changed, 59 insertions, 0 deletions
diff --git a/docs/source/history.rst b/docs/source/history.rst
index 5b090f9..700d87d 100644
--- a/docs/source/history.rst
+++ b/docs/source/history.rst
@@ -2,6 +2,11 @@
Release History
=================
+dev
+
+- Add ``dict2columns`` method to ``ShowOne``. (Contributed by Dean
+ Troyer)
+
1.4
- Store a reference to the InteractiveApp on the App while in
diff --git a/tests/test_show.py b/tests/test_show.py
new file mode 100644
index 0000000..41df5e1
--- /dev/null
+++ b/tests/test_show.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+from cliff.show import ShowOne
+
+import mock
+
+
+class FauxFormatter(object):
+
+ def __init__(self):
+ self.args = []
+
+ def emit_list(self, columns, data, stdout, args):
+ self.args.append((columns, data))
+
+
+class ExerciseShowOne(ShowOne):
+
+ def load_formatter_plugins(self):
+ self.formatters = {
+ 'test': FauxFormatter(),
+ }
+ return
+
+ def take_action(self, parsed_args):
+ return (
+ parsed_args.columns,
+ [('a', 'A'), ('b', 'B')],
+ )
+
+
+# def test_formatter_args():
+# app = mock.Mock()
+# test_lister = ExerciseLister(app, [])
+
+# parsed_args = mock.Mock()
+# parsed_args.columns = ('Col1', 'Col2')
+# parsed_args.formatter = 'test'
+
+# 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()
+ 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