summaryrefslogtreecommitdiffstats
path: root/tests/tabular_output/test_tsv_output_adapter.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:37:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:37:29 +0000
commitde734e6e5777abb6f8f16f94166ecd3dbe179421 (patch)
treefff61580a08934083aab3043d228c2f484f6f844 /tests/tabular_output/test_tsv_output_adapter.py
parentInitial commit. (diff)
downloadcli-helpers-upstream/2.3.0.tar.xz
cli-helpers-upstream/2.3.0.zip
Adding upstream version 2.3.0.upstream/2.3.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/tabular_output/test_tsv_output_adapter.py')
-rw-r--r--tests/tabular_output/test_tsv_output_adapter.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/tabular_output/test_tsv_output_adapter.py b/tests/tabular_output/test_tsv_output_adapter.py
new file mode 100644
index 0000000..9249d87
--- /dev/null
+++ b/tests/tabular_output/test_tsv_output_adapter.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+"""Test the tsv delimited output adapter."""
+
+from __future__ import unicode_literals
+from textwrap import dedent
+
+import pytest
+
+from cli_helpers.tabular_output import tsv_output_adapter
+
+
+def test_tsv_wrapper():
+ """Test the tsv output adapter."""
+ # Test tab-delimited output.
+ data = [["ab\r\nc", "1"], ["d", "456"]]
+ headers = ["letters", "number"]
+ output = tsv_output_adapter.adapter(iter(data), headers, table_format="tsv")
+ assert "\n".join(output) == dedent(
+ """\
+ letters\tnumber\n\
+ ab\r\\nc\t1\n\
+ d\t456"""
+ )
+
+
+def test_unicode_with_tsv():
+ """Test that the tsv wrapper can handle non-ascii characters."""
+ data = [["观音", "1"], ["Ποσειδῶν", "456"]]
+ headers = ["letters", "number"]
+ output = tsv_output_adapter.adapter(data, headers)
+ assert "\n".join(output) == dedent(
+ """\
+ letters\tnumber\n\
+ 观音\t1\n\
+ Ποσειδῶν\t456"""
+ )