Esempio n. 1
0
    def test_pretty_print_html(self):
        self.maxDiff = None
        html = pretty_print_html(_TEST_TOKS["span"].values, True)
        suffix = html[-809:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\
</tr>
    <tr>
      <th>7</th>
      <td>20</td>
      <td>26</td>
      <td>change</td>
    </tr>
  </tbody>
</table>
            </div>
            <div id="text"
             style="float:right; background-color:#F5F5F5; border: 1px solid #E0E0E0; width: 60%;">
                <div style="float:center; padding:10px">
                    <p style="font-family:monospace">
                        <span style="background-color:yellow">Item&#39;s</span> <span style="background-color:yellow">for</span> <span style="background-color:yellow">&lt;</span> <span style="background-color:yellow"><span>&#36;</span>100</span> <span style="background-color:yellow">&amp;</span> <span style="background-color:yellow">change
                    </p>
                </div>
            </div>
        </div>
        """)

        html = pretty_print_html(_TEST_TOKS["span"].values, False)
        suffix = html[-809:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\

        <div id="text"
         style="float:right; background-color:#F5F5F5; border: 1px solid #E0E0E0; width: 100%;">
            <div style="float:center; padding:10px">
                <p style="font-family:monospace">
                    <span style="background-color:yellow">Item&#39;s</span> <span style="background-color:yellow">for</span> <span style="background-color:yellow">&lt;</span> <span style="background-color:yellow"><span>&#36;</span>100</span> <span style="background-color:yellow">&amp;</span> <span style="background-color:yellow">change
                </p>
            </div>
        </div>
        """)
Esempio n. 2
0
    def test_pretty_print_html(self):
        self.maxDiff = None
        html = pretty_print_html(_TEST_TOKS["span"].values, True)
        suffix = html[-800:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\
</tbody>
</table>
    </div>
    <div id="text"
     style="float:right; border: 1px solid var(--jp-border-color0); width: 60%;">

                <div style="float:center; padding:10px">
                    <p style="font-family:var(--jp-code-font-family); font-size:var(--jp-code-font-size)">
                        <span style="background-color:rgba(255, 215, 0, 0.5)">Item&#39;s</span> <span style="background-color:rgba(255, 215, 0, 0.5)">for</span> <span style="background-color:rgba(255, 215, 0, 0.5)">&lt;</span> <span style="background-color:rgba(255, 215, 0, 0.5)"><span>&#36;</span>100</span> <span style="background-color:rgba(255, 215, 0, 0.5)">&amp;</span> <span style="background-color:rgba(255, 215, 0, 0.5)">change
                    </p>
                </div>

    </div>
</div>
""")

        html = pretty_print_html(_TEST_TOKS["span"].values, False)
        suffix = html[-809:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\

<div id="text"
 style="float:right; color: var(--jp-layout-color2); border: 1px solid var(--jp-border-color0); width: 100%;">

                <div style="float:center; padding:10px">
                    <p style="font-family:var(--jp-code-font-family); font-size:var(--jp-code-font-size)">
                        <span style="background-color:rgba(255, 215, 0, 0.5)">Item&#39;s</span> <span style="background-color:rgba(255, 215, 0, 0.5)">for</span> <span style="background-color:rgba(255, 215, 0, 0.5)">&lt;</span> <span style="background-color:rgba(255, 215, 0, 0.5)"><span>&#36;</span>100</span> <span style="background-color:rgba(255, 215, 0, 0.5)">&amp;</span> <span style="background-color:rgba(255, 215, 0, 0.5)">change
                    </p>
                </div>

</div>
""")
 def _repr_html_(self) -> str:
     """
     HTML pretty-printing of a series of spans for Jupyter notebooks.
     """
     return jupyter.pretty_print_html(self, self._repr_html_show_offsets)
Esempio n. 4
0
    def test_pretty_print_html(self):
        self.maxDiff = None
        html = pretty_print_html(_TEST_TOKS["span"].values, True)
        suffix = html[-500:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\
>
</div>
<script>
    {
        const Span = window.SpanArray.Span
        const script_context = document.currentScript
        const documents = []

    {

    const doc_spans = [[0,4],[4,6],[7,10],[11,12],[13,14],[14,17],[18,19],[20,26]]
    const doc_text = 'Item\\'s for < $100 & change'

        documents.push({doc_text: doc_text, doc_spans: doc_spans})

    }

        const instance = new window.SpanArray.SpanArray(documents, true, script_context)
        instance.render()
    }
</script>

""")

        html = pretty_print_html(_TEST_TOKS["span"].values, False)
        suffix = html[-500:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\

</div>
<script>
    {
        const Span = window.SpanArray.Span
        const script_context = document.currentScript
        const documents = []

    {

    const doc_spans = [[0,4],[4,6],[7,10],[11,12],[13,14],[14,17],[18,19],[20,26]]
    const doc_text = 'Item\\'s for < $100 & change'

        documents.push({doc_text: doc_text, doc_spans: doc_spans})

    }

        const instance = new window.SpanArray.SpanArray(documents, false, script_context)
        instance.render()
    }
</script>

""")

        # Multi-document regression test
        toks_union = pd.concat([_TEST_TOKS, _ALT_TEST_TOKS])
        html = pretty_print_html(toks_union["span"].values, False)
        suffix = html[-700:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\
/span>
</div>
<script>
    {
        const Span = window.SpanArray.Span
        const script_context = document.currentScript
        const documents = []

    {

    const doc_spans = [[0,4],[4,6],[7,10],[11,12],[13,14],[14,17],[18,19],[20,26]]
    const doc_text = 'Item\\'s for < $100 & change'

        documents.push({doc_text: doc_text, doc_spans: doc_spans})

    }

    {

    const doc_spans = [[0,4],[5,9],[10,11],[12,18],[19,27]]
    const doc_text = 'Once upon a second document'

        documents.push({doc_text: doc_text, doc_spans: doc_spans})

    }

        const instance = new window.SpanArray.SpanArray(documents, false, script_context)
        instance.render()
    }
</script>

""")

        # Multi-line document text regression test
        html = pretty_print_html(_NEWLINE_TEST_TOKS["span"].values, False)
        suffix = html[-500:]
        # print(f"[[[{suffix}]]]")
        self.assertEqual(
            suffix, """\
ocuments = []

    {

    const doc_spans = [[0,3],[4,9],[10,12],[13,17],[17,18],[18,19],[19,20],[21,24],[25,29],[30,38],[39,42],[43,47],[47,48],[48,49],[49,51],[52,59],[60,63],[64,70],[70,71]]
    const doc_text = 'The first of many.\\nA new line segments the text.\\nIt remains one string.'

        documents.push({doc_text: doc_text, doc_spans: doc_spans})

    }

        const instance = new window.SpanArray.SpanArray(documents, false, script_context)
        instance.render()
    }
</script>

""")