コード例 #1
0
ファイル: snapshot_test.py プロジェクト: tompscanlan/citest
  def test_snapshot_list(self):
    a = TestLinkedList('A')
    b = TestLinkedList('B')
    c = TestLinkedList('C')
    a.next = b
    b.next = c

    snapshot = JsonSnapshot()
    self.assertIsNone(snapshot.find_entity_for_data(b))
    self.assertIsNone(snapshot.find_entity_for_data(b)) # Still none
    snapshot.add_data(a)
    json_object = snapshot.to_json_object()

    have_b = snapshot.find_entity_for_data(b)
    self.assertEquals(2, have_b.id)
    entity_b = snapshot.make_entity_for_data(b)
    self.assertEquals(id(have_b), id(entity_b))

    have_c = snapshot.find_entity_for_data(c)
    entity_c = snapshot.make_entity_for_data(c)
    self.assertEquals(id(have_c), id(entity_c))
    self.assertEquals(3, entity_c.id)

    expect = {
        '_subject_id': 1,
        '_type': 'JsonSnapshot',
        '_entities': [
            {'_id': 1, 'name': 'A', '_edges': [{'_to': 2}]},
            {'_id': 2, 'name': 'B', '_edges': [{'_to': 3}]},
            {'_id': 3, 'name': 'C'}]}

    self.assertItemsEqual(expect, json_object)
コード例 #2
0
ファイル: html_renderer_test.py プロジェクト: jtk54/citest
  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()))
コード例 #3
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()))
コード例 #4
0
ファイル: html_renderer_test.py プロジェクト: jtk54/citest
  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)
コード例 #5
0
ファイル: snapshot_test.py プロジェクト: tompscanlan/citest
 def test_snapshot_make_transitive_entity(self):
   """Test snapshotting compound entities."""
   elem = TestLinkedList('First', next_elem=TestLinkedList('Second'))
   snapshot = JsonSnapshot()
   snapshot.make_entity_for_data(elem)
   entity = snapshot.make_entity_for_data(elem.next)
   found = snapshot.find_entity_for_data(elem.next)
   self.assertEquals(found, entity)
   self.assertEquals(id(found), id(entity))
   self.assertItemsEqual({'_subject_id': 1,
                          '_type': 'JsonSnapshot',
                          '_entities': [{'_id': 1, 'name': 'First',
                                         '_edges':[{'_to': 2}]},
                                        {'_id': 2, 'name': 'Second'}]},
                         snapshot.to_json_object())
コード例 #6
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)
コード例 #7
0
ファイル: snapshot_test.py プロジェクト: tompscanlan/citest
 def test_snapshot_make_entity(self):
   """Test snapshotting JsonSnapshotable objects into entities."""
   elem = TestLinkedList('Hello')
   snapshot = JsonSnapshot()
   entity = snapshot.make_entity_for_data(elem)
   found = snapshot.find_entity_for_data(elem)
   self.assertEquals(found, entity)
   self.assertEquals(id(found), id(entity))
   self.assertItemsEqual({'_subject_id': 1,
                          '_type': 'JsonSnapshot',
                          '_entities': [{'_id': 1, 'name': 'Hello'}]},
                         snapshot.to_json_object())