Beispiel #1
0
  def test_process_snapshot(self):
    """Test the conversion of a snapshot into HTML."""
    tail = TestLinkedList(name='tail')
    head = TestLinkedList(name='head', next_elem=tail)
    snapshot = JsonSnapshot()
    snapshot.make_entity_for_data(head)
    json_snapshot = snapshot.to_json_object()

    entity_manager = ProcessedEntityManager()
    processor = ProcessToRenderInfo(
        HtmlDocumentManager('test_json'), entity_manager)
    processor.max_uncollapsable_json_lines = 20
    processor.max_uncollapsable_metadata_rows = 20
    processor.max_uncollapsable_entity_rows = 20
    processor.default_force_top_level_collapse = False

    entity_manager.push_entity_map(json_snapshot['_entities'])
    html_info = processor.process_entity_id(json_snapshot['_subject_id'],
                                            json_snapshot)
    entity_manager.pop_entity_map(json_snapshot['_entities'])

    expect = """<table>
  <tr>
    <th><i>metadata</i></th>
    <td>
      <table>
        <tr><th>_id</th><td>1</td></tr>
        <tr><th>class</th><td>type TestLinkedList</td></tr>
        <tr><th>name</th><td>head</td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <th>Next</th>
    <td>
      <table>
        <tr>
          <th><i>metadata</i></th>
          <td>
            <table>
              <tr><th>_id</th><td>2</td></tr>
              <tr><th>class</th><td>type TestLinkedList</td></tr>
              <tr><th>name</th><td>tail</td></tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
"""
    # Test without regard to whitespace formatting.
    self.assertEquals(''.join(expect.split()),
                      ''.join(html_info.detail_html.split()))
    def test_cycle(self):
        tail = TestLinkedList(name='tail')
        head = TestLinkedList(name='head', next_elem=tail)
        tail.next = head
        snapshot = JsonSnapshot()

        entity_manager = ProcessedEntityManager()
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_json'),
                                        entity_manager)

        snapshot.make_entity_for_object(head)
        json_snapshot = snapshot.to_json_object()
        self.assertEqual(1, json_snapshot.get('_subject_id'))
        entity_manager.push_entity_map(json_snapshot.get('_entities'))
        info = processor.process_entity_id(1, snapshot)
Beispiel #3
0
  def test_cycle(self):
    tail = TestLinkedList(name='tail')
    head = TestLinkedList(name='head', next_elem=tail)
    tail.next = head
    snapshot = JsonSnapshot()

    entity_manager = ProcessedEntityManager()
    processor = ProcessToRenderInfo(
        HtmlDocumentManager('test_json'), entity_manager)

    snapshot.make_entity_for_data(head)
    json_snapshot = snapshot.to_json_object()
    self.assertEqual(1, json_snapshot.get('_subject_id'))
    entity_manager.push_entity_map(json_snapshot.get('_entities'))
    info = processor.process_entity_id(1, snapshot)
Beispiel #4
0
    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_process_snapshot(self):
    """Test the conversion of a snapshot into HTML."""
    tail = TestLinkedList(name='tail')
    head = TestLinkedList(name='head', next_elem=tail)
    snapshot = JsonSnapshot()
    snapshot.make_entity_for_object(head)
    json_snapshot = snapshot.to_json_object()

    entity_manager = ProcessedEntityManager()
    processor = ProcessToRenderInfo(
        HtmlDocumentManager('test_json'), entity_manager)
    processor.max_uncollapsable_json_lines = 20
    processor.max_uncollapsable_metadata_rows = 20
    processor.max_uncollapsable_entity_rows = 20
    processor.default_force_top_level_collapse = False

    in_relation = None
    entity_manager.push_entity_map(json_snapshot['_entities'])
    html_info = processor.process_entity_id(json_snapshot['_subject_id'],
                                            json_snapshot, in_relation)
    entity_manager.pop_entity_map(json_snapshot['_entities'])

    expect = """<table>
  <tr>
    <th><i>metadata</i></th>
    <td>
      <table>
        <tr><th>_id</th><td>1</td></tr>
        <tr><th>class</th><td>type TestLinkedList</td></tr>
        <tr><th>name</th><td>head</td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <th>Next</th>
    <td>
      <table>
        <tr>
          <th><i>metadata</i></th>
          <td>
            <table>
              <tr><th>_id</th><td>2</td></tr>
              <tr><th>class</th><td>type TestLinkedList</td></tr>
              <tr><th>name</th><td>tail</td></tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
"""
    # Test without regard to whitespace formatting.
    self.assertEquals(''.join(expect.split()),
                      ''.join(str(html_info.detail_block).split()))