def test_json(self): """Test rendering literal json values""" processor = ProcessToRenderInfo(HtmlDocumentManager('test_json'), ProcessedEntityManager()) processor.max_uncollapsable_json_lines = 20 processor.max_uncollapsable_entity_rows = 20 # Numeric literals wont be treated as json. for n in [-1, 0, 1, 3.14]: info = processor.process_json_html_if_possible(n) self.assertEquals('{0}'.format(n), info.detail_html) self.assertEquals(None, info.summary_html) # None of these strings are well-defined JSON documents # so should just be strings. for s in ['test', 'a phrase', 'True']: info = processor.process_json_html_if_possible(s) self.assertEquals('"{0}"'.format(s), info.detail_html) self.assertEquals(None, info.summary_html) # Boolean values wont be considered JSON. for b in [True, False]: info = processor.process_json_html_if_possible(b) self.assertEquals('{0}'.format(str(b)), info.detail_html) self.assertEquals(None, info.summary_html) # Dictionaries and JSON dictionary strings normalize to JSON. for d in [{'A': 'a', 'B': True}, '{"A":"a", "B":true}']: info = processor.process_json_html_if_possible(d) self.assertEquals( '<pre>{{\n "A": "a",\n' ' "B": true\n' '}}</pre>'.format(), info.detail_html) self.assertEquals(None, info.summary_html) self.assertEquals(None, info.summary_html) # Lists and JSON lists strings normalize to JSON. for l in [[123, 'abc', True, { 'A': 'a', 'B': 'b' }], '[123, "abc", true, {"A":"a", "B":"b"}]']: info = processor.process_json_html_if_possible(l) self.assertEquals( '<pre>[\n 123,\n "abc",\n true,\n' ' {{\n' ' "A": "a",\n' ' "B": "b"\n' ' }}\n' ']</pre>'.format(), info.detail_html) self.assertEquals(None, info.summary_html)
def test_json(self): """Test rendering literal json values""" processor = ProcessToRenderInfo( HtmlDocumentManager('test_json'), ProcessedEntityManager()) processor.max_uncollapsable_json_lines = 20 processor.max_uncollapsable_entity_rows = 20 # Numeric literals wont be treated as json. for n in [-1, 0, 1, 3.14]: info = processor.process_json_html_if_possible(n) self.assertEquals('{0}'.format(n), info.detail_html) self.assertEquals(None, info.summary_html) # None of these strings are well-defined JSON documents # so should just be strings. for s in ['test', 'a phrase', 'True']: info = processor.process_json_html_if_possible(s) self.assertEquals('"{0}"'.format(s), info.detail_html) self.assertEquals(None, info.summary_html) # Boolean values wont be considered JSON. for b in [True, False]: info = processor.process_json_html_if_possible(b) self.assertEquals('{0}'.format(str(b)), info.detail_html) self.assertEquals(None, info.summary_html) # Dictionaries and JSON dictionary strings normalize to JSON. for d in [{'A': 'a', 'B': True}, '{"A":"a", "B":true}']: info = processor.process_json_html_if_possible(d) self.assertEquals('<pre>{{\n "A": "a",\n' ' "B": true\n' '}}</pre>'.format(), info.detail_html) self.assertEquals(None, info.summary_html) self.assertEquals(None, info.summary_html) # Lists and JSON lists strings normalize to JSON. for l in [[123, 'abc', True, {'A': 'a', 'B': 'b'}], '[123, "abc", true, {"A":"a", "B":"b"}]']: info = processor.process_json_html_if_possible(l) self.assertEquals('<pre>[\n 123,\n "abc",\n true,\n' ' {{\n' ' "A": "a",\n' ' "B": "b"\n' ' }}\n' ']</pre>'.format(), info.detail_html) self.assertEquals(None, info.summary_html)