File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,9 @@ def to_xml_str(tree):
8282
8383class JSONEncoder (json .JSONEncoder ):
8484 def default (self , o ):
85+ if isinstance (o , bytes ):
86+ return o .decode ()
87+
8588 try :
8689 to_json = getattr (o , "to_json" )
8790 if callable (to_json ):
Original file line number Diff line number Diff line change @@ -99,3 +99,43 @@ def test_cont_int_1(self):
9999 ]
100100 for node , exp in zip (nodes , expected_cls ):
101101 self .assertIsInstance (node , exp )
102+
103+ def test_to_pretty_json (self ):
104+ src = textwrap .dedent (
105+ """\
106+ local a = "foo"\
107+ """
108+ )
109+ exp = textwrap .dedent (
110+ """\
111+ {
112+ "comments": [],
113+ "body": {
114+ "comments": [],
115+ "body": [
116+ {
117+ "comments": [],
118+ "wrapped": false,
119+ "targets": [
120+ {
121+ "comments": [],
122+ "wrapped": false,
123+ "id": "a",
124+ "attribute": null
125+ }
126+ ],
127+ "values": [
128+ {
129+ "comments": [],
130+ "wrapped": false,
131+ "s": "foo",
132+ "raw": "foo",
133+ "delimiter": {}
134+ }
135+ ]
136+ }
137+ ]
138+ }
139+ }"""
140+ )
141+ self .assertEqual (ast .to_pretty_json (ast .parse (src )), exp )
You can’t perform that action at this time.
0 commit comments