<commit_before>"""Assertion based test cases for monotable.MonoTable.  Run with pytest."""

from collections import namedtuple
from os import path
import re

import pytest

import monotable
import monotable.plugin


def read_file(*path_components):
    """Read a text file from the source tree into a string.

    The path is relative to the directory containing this file.
    """
    here = path.abspath(path.dirname(__file__))
    with open(path.join(here, *path_components)) as f:
        return f.read()


def test_consistent_version_strings():
    """Verify all same release version string.

    Obtain the version string from various places in the source tree
    and check that they are all the same.
    This test does not prove the version is correct.

    Whitespace around the equals sign in the version statement IS significant.
    """
    version = monotable.__version__    # authoritative

    # -------------------------------------------------------
    # index.rst
    # example:
    # monotable version 1.0.1.
    # Note the final period is required.
    index_text = read_file('..', 'doc', 'index.rst')
    versionref = re.compile(r"monotable version (\d+\.\d+\.\d+)\.$", re.M)
    match = versionref.search(index_text)
    assert match.group(1) == version

    # make sure we properly match possible future versions.
    v1 = 'monotable version 10.0.1.'
    m1 = versionref.search(v1)
    assert m1.group(1) == '10.0.1'

    v2 = 'monotable version 1.11.1.'
    m2 = versionref.search(v2)
    assert m2.group(1) == '1.11.1'

    v3 = 'monotable version 1.0.11.'
    m3 = versionref.search(v3)
    assert m3.group(1) == '1.0.11'

    v4 = 'monotable version 12.34.56.'
    m4 = versionref.search(v4)
    assert m4.group(1) == '12.34.56'

    # make sure we don't match bogus version strings.
    v5 = 'monotable version 12.34.56'  # no period
    m5 = versionref.search(v5)
    assert m5 == None

    v6 = 'monotable version .34.56'  # missing major version
    m6 = versionref.search(v6)
    assert m6 == None

    v7 = 'monotable version 1.Z.56'  # non numeric
    m7 = versionref.search(v7)
    assert m7 == None


    # -------------------------------------------------------
    # setup.py
    # example: version='0.1.0',
    setup_text = read_file('..', 'setup.py')
    match = re.search(r" *version=['\"]([^'\"]*)['\"]", setup_text, re.M)
    assert match.group(1) == version

    # -------------------------------------------------------
    # conf.py
    # example:
    # # The short X.Y version.
    # version = u'0.1.0'
    conf_text = read_file('..', 'doc', 'conf.py')
    match = re.search(r"^version = u['\"]([^'\"]*)['\"]", conf_text, re.M)
    assert match.group(1) == version

    # conf.py
    # example:
    # # The full version, including alpha/beta/rc tags.
    # release = u'0.1.0'
    match = re.search(r"^release = u['\"]([^'\"]*)['\"]", conf_text, re.M)
    assert match.group(1) == version

#
# Test handling of empty lists and default constructor arguments.
#


def test_noheadings_noformats_notitle_emptycells():
    """No headings, formats, title, and no cells in the cellgrid.

    Test with both default argument values and empty lists."""

    tbl = monotable.MonoTable()    # default args for headings, formats
    text = tbl.table()
    assert text == ''

    text = tbl.table(cellgrid=[[]])
    assert text == ''

    text = tbl.bordered_table()<commit_msg>Bug fix index.rst version checking re. Remove $ at the end of the re. It was still failing on Travis on Python 2.7.9 and Python 2.7.8[pypy-2.5.0-final] Builds 20.1 and 20.6. Verified original failure and this fix on Raspberry Pi Python 2.7.3 Renamed version to auth_version. Moved setup.py and conf.py tests up a few lines.<commit_after>"""Assertion based test cases for monotable.MonoTable.  Run with pytest."""

from collections import namedtuple
from os import path
import re

import pytest

import monotable
import monotable.plugin


def read_file(*path_components):
    """Read a text file from the source tree into a string.

    The path is relative to the directory containing this file.
    """
    here = path.abspath(path.dirname(__file__))
    with open(path.join(here, *path_components)) as f:
        return f.read()


def test_consistent_version_strings():
    """Verify all same release version string.

    Obtain the version string from various places in the source tree
    and check that they are all the same.
    This test does not prove the version is correct.

    Whitespace around the equals sign in the version statement IS significant.
    """
    auth_version = monotable.__version__    # authoritative

    # -------------------------------------------------------
    # index.rst
    # example:
    # monotable version 1.0.1.
    # Note the final period is required.
    index_text = read_file('..', 'doc', 'index.rst')
    versionref = re.compile(r"monotable version (\d+\.\d+\.\d+)\.", re.M)
    match = versionref.search(index_text)
    assert match.group(1) == auth_version

    # -------------------------------------------------------
    # setup.py
    # example: version='0.1.0',
    setup_text = read_file('..', 'setup.py')
    match = re.search(r" *version=['\"]([^'\"]*)['\"]", setup_text, re.M)
    assert match.group(1) == auth_version

    # -------------------------------------------------------
    # conf.py
    # example:
    # # The short X.Y version.
    # version = u'0.1.0'
    conf_text = read_file('..', 'doc', 'conf.py')
    match = re.search(r"^version = u['\"]([^'\"]*)['\"]", conf_text, re.M)
    assert match.group(1) == auth_version

    # conf.py
    # example:
    # # The full version, including alpha/beta/rc tags.
    # release = u'0.1.0'
    match = re.search(r"^release = u['\"]([^'\"]*)['\"]", conf_text, re.M)
    assert match.group(1) == auth_version


    # make sure we properly match possible future versions.
    v1 = 'monotable version 10.0.1.'
    m1 = versionref.search(v1)
    assert m1.group(1) == '10.0.1'

    v2 = 'monotable version 1.11.1.'
    m2 = versionref.search(v2)
    assert m2.group(1) == '1.11.1'

    v3 = 'monotable version 1.0.11.'
    m3 = versionref.search(v3)
    assert m3.group(1) == '1.0.11'

    v4 = 'monotable version 12.34.56.'
    m4 = versionref.search(v4)
    assert m4.group(1) == '12.34.56'

    # make sure we don't match bogus version strings.
    v5 = 'monotable version 12.34.56'  # no period
    m5 = versionref.search(v5)
    assert m5 == None

    v6 = 'monotable version .34.56'  # missing major version
    m6 = versionref.search(v6)
    assert m6 == None

    v7 = 'monotable version 1.Z.56'  # non numeric
    m7 = versionref.search(v7)
    assert m7 == None

#
# Test handling of empty lists and default constructor arguments.
#


def test_noheadings_noformats_notitle_emptycells():
    """No headings, formats, title, and no cells in the cellgrid.

    Test with both default argument values and empty lists."""

    tbl = monotable.MonoTable()    # default args for headings, formats
    text = tbl.table()
    assert text == ''

    text = tbl.table(cellgrid=[[]])
    assert text == ''

    text = tbl.bordered_table()
{'fraction_non_alphanumeric': 0.17597765363128492, 'fraction_numerical': 0.029608938547486034, 'mean_word_length': 2.3970588235294117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '477540', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2276, 'n_words': 685}