<commit_before># -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:


import pytest

import re
import importlib
import os.path  as op


def test_version():
    version_py = op.abspath(op.join(op.dirname(__file__), op.pardir, 'version.py'))

    mod = importlib.machinery.SourceFileLoader('version', 'hansel/version.py').load_module()

    assert isinstance(mod.__version__, str)
    assert re.match(r'[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}', mod.__version__)
    assert all(isinstance(val, int) for val in mod.VERSION)<commit_msg>fix test_version for py2.7<commit_after># -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:


import pytest

import re
import os.path  as op
import sys


def import_pyfile(pathname, mod_name=''):
    """Import the contents of filepath as a Python module.
    Parameters
    ----------
    pathname: str
        Path to the .py file to be imported as a module
    mod_name: str
        Name of the module when imported
    Returns
    -------
    mod
        The imported module
    Raises
    ------
    IOError
        If file is not found
    """
    if not op.isfile(pathname):
        raise IOError('File {0} not found.'.format(pathname))

    if sys.version_info[0] == 3 and sys.version_info[1] > 2: # Python >= 3.3
        import importlib.machinery
        loader = importlib.machinery.SourceFileLoader('', pathname)
        mod = loader.load_module(mod_name)
    else: #  2.6 >= Python <= 3.2
        import imp
        mod = imp.load_source(mod_name, pathname)
    return mod


def test_version():
    version_py = op.abspath(op.join(op.dirname(__file__), op.pardir, 'version.py'))

    mod = import_pyfile('hansel/version.py')

    assert isinstance(mod.__version__, str)
    assert re.match(r'[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}', mod.__version__)
    assert all(isinstance(val, int) for val in mod.VERSION)
{'fraction_non_alphanumeric': 0.15243296921549157, 'fraction_numerical': 0.02333664349553128, 'mean_word_length': 2.882466281310212, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '897656', 'n_tokens_mistral': 709, 'n_tokens_neox': 692, 'n_words': 179}