<commit_before>import os
import importlib
from elifetools.utils import unicode_value

BASE_DIR = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))


def json_expected_folder(filename):
    return os.path.join(BASE_DIR, "tests", "JSON", filename.split(".")[0])


def json_expected_file(filename, function_name):
    if json_expected_folder(filename):
        return os.path.join(json_expected_folder(filename), function_name + ".json")


def sample_xml(filename):
    return os.path.join(BASE_DIR, "sample-xml", filename)

def fixture_folder(folder_name):
    return os.path.join(BASE_DIR, "tests", "fixtures", folder_name)

def fixture_module_name(folder_name, filename):
    return '.'.join(["tests", "fixtures", folder_name, filename.rstrip('.py')])

def fixture_file(folder_name, filename):
    return os.path.join(fixture_folder(folder_name), filename)

def read_fixture(folder_name, filename):
    full_filename = fixture_file(folder_name, filename)
    if full_filename.endswith('.py'):
        # import the fixture and return the value of expected
        module_name = fixture_module_name(folder_name, filename)
        mod = importlib.import_module(module_name)
        return mod.expected
    else:
        with open(full_filename, 'rb') as file_fp:
            return file_fp.read()

__all__ = [json_expected_file, json_expected_folder, sample_xml,
           fixture_folder, read_fixture]
<commit_msg>Assert a python fixture has the property "expected".<commit_after>import os
import importlib
from elifetools.utils import unicode_value

BASE_DIR = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))


def json_expected_folder(filename):
    return os.path.join(BASE_DIR, "tests", "JSON", filename.split(".")[0])


def json_expected_file(filename, function_name):
    if json_expected_folder(filename):
        return os.path.join(json_expected_folder(filename), function_name + ".json")


def sample_xml(filename):
    return os.path.join(BASE_DIR, "sample-xml", filename)

def fixture_folder(folder_name):
    return os.path.join(BASE_DIR, "tests", "fixtures", folder_name)

def fixture_module_name(folder_name, filename):
    return '.'.join(["tests", "fixtures", folder_name, filename.rstrip('.py')])

def fixture_file(folder_name, filename):
    return os.path.join(fixture_folder(folder_name), filename)

def read_fixture(folder_name, filename):
    full_filename = fixture_file(folder_name, filename)
    if full_filename.endswith('.py'):
        # import the fixture and return the value of expected
        module_name = fixture_module_name(folder_name, filename)
        mod = importlib.import_module(module_name)
        # assert expected exists before continuing
        assert hasattr(mod, 'expected'), (
            'expected property not found in module {module_name}'.format(module_name=module_name))
        return mod.expected
    else:
        with open(full_filename, 'rb') as file_fp:
            return file_fp.read()

__all__ = [json_expected_file, json_expected_folder, sample_xml,
           fixture_folder, read_fixture]

{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.000649772579597141, 'mean_word_length': 4.608378870673953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '1862570', 'n_tokens_mistral': 943, 'n_tokens_neox': 934, 'n_words': 204}