Ejemplo n.º 1
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_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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def test_yaml(self):
        """Test rendering literal json values"""
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_yaml'),
                                        ProcessedEntityManager())
        processor.max_uncollapsable_json_lines = 20
        processor.max_uncollapsable_entity_rows = 20

        # Numeric literals wont be treated as yaml
        for n in [-1, 0, 1, 3.14]:
            info = processor.process_yaml_html_if_possible(n)
            self.assertEquals('{0}'.format(n), info.detail_block)
            self.assertEquals(None, info.summary_block)

        # None of these strings are well-defined YAML documents
        # so should just be strings.
        for s in ['test', 'a phrase']:
            info = processor.process_yaml_html_if_possible(s)
            self.assertEquals('<pre>%s\n</pre>' % s, info.detail_block)
            self.assertEquals(None, info.summary_block)
        info = processor.process_yaml_html_if_possible('True')
        self.assertEquals('<pre>true\n</pre>', info.detail_block)

        # Boolean values wont be considered YAML
        for b in [True, False]:
            info = processor.process_yaml_html_if_possible(b)
            self.assertEquals('{0}'.format(str(b)), info.detail_block)
            self.assertEquals(None, info.summary_block)

        # Dictionaries and YAML dictionary strings normalize to YAML
        import yaml
        for d in [{'A': 'a', 'B': True}, 'A: a\nB: true\n']:
            info = processor.process_yaml_html_if_possible(d)
            # The eolns here show that it is being yaml formatted.
            self.assertEquals('<pre>A:a\nB:true\n</pre>',
                              str(info.detail_block).replace(' ', ''))
            self.assertEquals(None, info.summary_block)
            self.assertEquals(None, info.summary_block)

        # Lists and YAML lists strings normalize to YAML.
        for l in [[123, 'abc', True, {
                'A': 'a',
                'B': 'b'
        }], '[123, "abc", true, {"A":"a", "B":"b"}]']:
            info = processor.process_yaml_html_if_possible(l)
            self.assertEquals(
                '<pre>-123\n-abc\n-true\n-A:a\nB:b\n</pre>',
                str(info.detail_block).replace(' ', '').replace('\n', '\n'))
            self.assertEquals(None, info.summary_block)
Ejemplo n.º 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)
Ejemplo n.º 5
0
  def test_yaml(self):
    """Test rendering literal json values"""
    processor = ProcessToRenderInfo(
        HtmlDocumentManager('test_yaml'),
        ProcessedEntityManager())
    processor.max_uncollapsable_json_lines = 20
    processor.max_uncollapsable_entity_rows = 20

    # Numeric literals wont be treated as yaml
    for n in [-1, 0, 1, 3.14]:
      info = processor.process_yaml_html_if_possible(n)
      self.assertEquals('{0}'.format(n), info.detail_block)
      self.assertEquals(None, info.summary_block)

    # None of these strings are well-defined YAML documents
    # so should just be strings.
    for s in ['test', 'a phrase']:
      info = processor.process_yaml_html_if_possible(s)
      self.assertEquals('<pre>%s\n</pre>' % s, info.detail_block)
      self.assertEquals(None, info.summary_block)
    info = processor.process_yaml_html_if_possible('True')
    self.assertEquals('<pre>true\n</pre>', info.detail_block)

    # Boolean values wont be considered YAML
    for b in [True, False]:
      info = processor.process_yaml_html_if_possible(b)
      self.assertEquals('{0}'.format(str(b)), info.detail_block)
      self.assertEquals(None, info.summary_block)

    # Dictionaries and YAML dictionary strings normalize to YAML
    import yaml
    for d in [{'A': 'a', 'B': True}, 'A: a\nB: true\n']:
      info = processor.process_yaml_html_if_possible(d)
      # The eolns here show that it is being yaml formatted.
      self.assertEquals('<pre>A:a\nB:true\n</pre>',
                        str(info.detail_block).replace(' ', ''))
      self.assertEquals(None, info.summary_block)
      self.assertEquals(None, info.summary_block)

    # Lists and YAML lists strings normalize to YAML.
    for l in [[123, 'abc', True, {'A': 'a', 'B': 'b'}],
              '[123, "abc", true, {"A":"a", "B":"b"}]']:
      info = processor.process_yaml_html_if_possible(l)
      self.assertEquals(
          '<pre>-123\n-abc\n-true\n-A:a\nB:b\n</pre>',
          str(info.detail_block).replace(' ', '').replace('\n', '\n'))
      self.assertEquals(None, info.summary_block)
Ejemplo n.º 6
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_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()))
Ejemplo n.º 7
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)
Ejemplo n.º 8
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_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()))