3
3
4
4
from __future__ import unicode_literals
5
5
6
+ from decimal import Decimal
7
+
6
8
from cli_helpers .tabular_output import json_output_adapter
7
9
8
10
@@ -29,6 +31,28 @@ def test_unicode_with_jsonl():
29
31
)
30
32
31
33
34
+ def test_decimal_with_jsonl ():
35
+ """Test that the jsonl wrapper can pass through Decimal values."""
36
+ data = [["ab\r \n c" , 1 ], ["d" , Decimal (4.56 )]]
37
+ headers = ["letters" , "number" ]
38
+ output = json_output_adapter .adapter (iter (data ), headers , table_format = "jsonl" )
39
+ assert (
40
+ "\n " .join (output )
41
+ == """{"letters":"ab\\ r\\ nc","number":1}\n {"letters":"d","number":4.56}"""
42
+ )
43
+
44
+
45
+ def test_null_with_jsonl ():
46
+ """Test that the jsonl wrapper can pass through null values."""
47
+ data = [["ab\r \n c" , None ], ["d" , None ]]
48
+ headers = ["letters" , "value" ]
49
+ output = json_output_adapter .adapter (iter (data ), headers , table_format = "jsonl" )
50
+ assert (
51
+ "\n " .join (output )
52
+ == """{"letters":"ab\\ r\\ nc","value":null}\n {"letters":"d","value":null}"""
53
+ )
54
+
55
+
32
56
def test_unicode_with_jsonl_esc ():
33
57
"""Test that the jsonl_escaped wrapper JSON-escapes non-ascii characters."""
34
58
data = [["观音" , 1 ], ["Ποσειδῶν" , 456 ]]
0 commit comments