summaryrefslogtreecommitdiffstats
path: root/tests/test_main.py
diff options
context:
space:
mode:
authorJoakim Koljonen <koljonen@outlook.com>2017-08-06 19:13:46 +0200
committerJoakim Koljonen <koljonen@outlook.com>2017-08-06 19:30:34 +0200
commitc616a8b42272c2900a7306817d20b13fef3dc052 (patch)
tree60b71e001abd7a8a85b6b6110824d6ca894cc0b7 /tests/test_main.py
parent9d59fa5a8ac85f0699daeb51f8602b7d01d31882 (diff)
Improve formatting of array output
Before this change, e.g. `SELECT '{1}'::numeric` would output `[Decimal(1)]`. Now it instead outputs `{1}`.
Diffstat (limited to 'tests/test_main.py')
-rw-r--r--tests/test_main.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_main.py b/tests/test_main.py
index 0380c6fa..249a4c69 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1,6 +1,8 @@
+# coding=utf-8
import os
import platform
import mock
+from decimal import Decimal
import pytest
try:
@@ -56,6 +58,52 @@ def test_format_output():
assert results == expected
+def test_format_array_output(executor):
+ statement = u"""
+ SELECT
+ array[1, 2, 3]::bigint[] as bigint_array,
+ '{{1,2},{3,4}}'::numeric[] as nested_numeric_array,
+ '{å,魚,текст}'::text[] as 配列
+ UNION ALL
+ SELECT '{}', NULL, array[NULL]
+ """
+ results = run(executor, statement)
+ expected = [
+ u'+----------------+------------------------+--------------+\n'
+ u'| bigint_array | nested_numeric_array | 配列 |\n'
+ u'|----------------+------------------------+--------------|\n'
+ u'| {1,2,3} | {{1,2},{3,4}} | {å,魚,текст} |\n'
+ u'| {} | <null> | {<null>} |\n'
+ u'+----------------+------------------------+--------------+',
+ u'SELECT 2'
+ ]
+ assert results == expected
+
+
+def test_format_array_output_expanded(executor):
+ statement = u"""
+ SELECT
+ array[1, 2, 3]::bigint[] as bigint_array,
+ '{{1,2},{3,4}}'::numeric[] as nested_numeric_array,
+ '{å,魚,текст}'::text[] as 配列
+ UNION ALL
+ SELECT '{}', NULL, array[NULL]
+ """
+ results = run(executor, statement, expanded=True)
+ expected = [
+ u'-[ RECORD 1 ]-------------------------\n'
+ u'bigint_array | {1,2,3}\n'
+ u'nested_numeric_array | {{1,2},{3,4}}\n'
+ u'配列 | {å,魚,текст}\n'
+ u'-[ RECORD 2 ]-------------------------\n'
+ u'bigint_array | {}\n'
+ u'nested_numeric_array | <null>\n'
+ u'配列 | {<null>}\n',
+ u'SELECT 2'
+ ]
+ assert results == expected
+
+
def test_format_output_auto_expand():
settings = OutputSettings(
table_format='psql', dcmlfmt='d', floatfmt='g', max_width=100)