diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:59:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:59:59 +0000 |
commit | c9ef4ed560a5de28fce031882257b6741565284e (patch) | |
tree | 07afa40629447df997726efd4de84d5987ff5e50 /tests/tabular_output/test_delimited_output_adapter.py | |
parent | Initial commit. (diff) | |
download | cli-helpers-c9ef4ed560a5de28fce031882257b6741565284e.tar.xz cli-helpers-c9ef4ed560a5de28fce031882257b6741565284e.zip |
Adding upstream version 2.3.1.upstream/2.3.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/tabular_output/test_delimited_output_adapter.py')
-rw-r--r-- | tests/tabular_output/test_delimited_output_adapter.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/tabular_output/test_delimited_output_adapter.py b/tests/tabular_output/test_delimited_output_adapter.py new file mode 100644 index 0000000..86a622e --- /dev/null +++ b/tests/tabular_output/test_delimited_output_adapter.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +"""Test the delimited output adapter.""" + +from __future__ import unicode_literals +from textwrap import dedent + +import pytest + +from cli_helpers.tabular_output import delimited_output_adapter + + +def test_csv_wrapper(): + """Test the delimited output adapter.""" + # Test comma-delimited output. + data = [["abc", "1"], ["d", "456"]] + headers = ["letters", "number"] + output = delimited_output_adapter.adapter(iter(data), headers, dialect="unix") + assert "\n".join(output) == dedent( + '''\ + "letters","number"\n\ + "abc","1"\n\ + "d","456"''' + ) + + # Test tab-delimited output. + data = [["abc", "1"], ["d", "456"]] + headers = ["letters", "number"] + output = delimited_output_adapter.adapter( + iter(data), headers, table_format="csv-tab", dialect="unix" + ) + assert "\n".join(output) == dedent( + '''\ + "letters"\t"number"\n\ + "abc"\t"1"\n\ + "d"\t"456"''' + ) + + with pytest.raises(ValueError): + output = delimited_output_adapter.adapter( + iter(data), headers, table_format="foobar" + ) + list(output) + + +def test_unicode_with_csv(): + """Test that the csv wrapper can handle non-ascii characters.""" + data = [["观音", "1"], ["Ποσειδῶν", "456"]] + headers = ["letters", "number"] + output = delimited_output_adapter.adapter(data, headers) + assert "\n".join(output) == dedent( + """\ + letters,number\n\ + 观音,1\n\ + Ποσειδῶν,456""" + ) |