<commit_before>from ..table import Table

REFERENCE = """
<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-type"/>
  <style>
table,th,td,tr,tbody {border: 1px solid black; border-collapse: collapse;}  </style>
  <link href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.css" rel="stylesheet" type="text/css"/>
  <script src="http://code.jquery.com/jquery-1.11.3.min.js">
  </script>
  <script src="http://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js">
  </script>
 </head>
 <body>
  <script>
$(document).ready(function() {
    $('#test').dataTable({
     "iDisplayLength": 50,
     "aLengthMenu": [[10, 25, 50, 100, 500, 1000, -1], [10, 25, 50, 100, 500, 1000, 'All']],
     "pagingType": "full_numbers"
    });
} );  </script>
  <table class="cell-border compact strip hover order-column" id="test">
   <thead>
    <tr>
     <th>a</th>
     <th>b</th>
    </tr>
   </thead>
   <tr>
    <td>1</td>
    <td>a</td>
   </tr>
   <tr>
    <td>2</td>
    <td>b</td>
   </tr>
   <tr>
    <td>3</td>
    <td>c</td>
   </tr>
  </table>
 </body>
</html>
"""


def test_write_jsviewer(tmpdir):

    t = Table()
    t['a'] = [1,2,3]
    t['b'] = ['a','b','c']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath

    t.write(tmpfile, format='jsviewer', table_id='test')

    with open(tmpfile) as f:
        content = f.read()

    assert content.strip() == REFERENCE.strip()<commit_msg>Fix tests and add one for use_local_files<commit_after>from os.path import abspath, dirname, join

from ..table import Table
from ... import extern

EXTERN_DIR = abspath(dirname(extern.__file__))

REFERENCE = """
<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-type"/>
  <style>
  </style>
  <link href="%(datatables_url)s/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css"/>
  <script src="%(jquery_url)s/jquery-1.11.3.min.js">
  </script>
  <script src="%(datatables_url)s/js/jquery.dataTables.min.js">
  </script>
 </head>
 <body>
  <script>
$(document).ready(function() {
    $('#test').dataTable({
     "iDisplayLength": 50,
     "aLengthMenu": [[10, 25, 50, 100, 500, 1000, -1], [10, 25, 50, 100, 500, 1000, 'All']],
     "pagingType": "full_numbers"
    });
} );  </script>
  <table class="%(table_class)s" id="test">
   <thead>
    <tr>
     <th>a</th>
     <th>b</th>
    </tr>
   </thead>
   <tr>
    <td>1</td>
    <td>a</td>
   </tr>
   <tr>
    <td>2</td>
    <td>b</td>
   </tr>
   <tr>
    <td>3</td>
    <td>c</td>
   </tr>
  </table>
 </body>
</html>
"""


def test_write_jsviewer(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3]
    t['b'] = ['a', 'b', 'c']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath

    t.write(tmpfile, format='jsviewer', table_id='test')
    ref = REFERENCE % dict(
        table_class='display compact',
        datatables_url='https://cdn.datatables.net/1.10.9',
        jquery_url='https://code.jquery.com'
    )
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()

    t.write(tmpfile, format='jsviewer', table_id='test',
            table_class='display hover')
    ref = REFERENCE % dict(
        table_class='display hover',
        datatables_url='https://cdn.datatables.net/1.10.9',
        jquery_url='https://code.jquery.com'
    )
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()


def test_write_jsviewer_local(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3]
    t['b'] = ['a', 'b', 'c']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath

    t.write(tmpfile, format='jsviewer', table_id='test',
            jskwargs={'use_local_files': True})
    ref = REFERENCE % dict(
        table_class='display compact',
        datatables_url='file://' + EXTERN_DIR,
        jquery_url='file://' + join(EXTERN_DIR, 'js')
    )
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()
{'fraction_non_alphanumeric': 0.21805835010060362, 'fraction_numerical': 0.028672032193158954, 'mean_word_length': 2.906679764243615, 'pattern_counts': {'":': 6, '<': 93, '<?xml version=': 0, '>': 93, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7041371', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1564, 'n_words': 287}