<commit_before>import glob
import os
import yaml
import numpy as np
import pytest
from astropy import units as u

from tardis import __githash__ as tardis_githash
from tardis.tests.tests_slow.report import DokuReport
from tardis.tests.tests_slow.plot_helpers import PlotUploader


def pytest_addoption(parser):
    parser.addoption("--integration-tests", dest="integration-tests",
                     help="path to configuration file for integration tests")
    parser.addoption("--generate-reference", action="store_true",
                     help="execute integration test run to generate reference data")


def pytest_configure(config):
    integration_tests_configpath = config.getvalue("integration-tests")
    if integration_tests_configpath is not None:
        integration_tests_configpath = os.path.expandvars(
            os.path.expanduser(integration_tests_configpath)
        )
        config.option.integration_tests_config = yaml.load(
            open(integration_tests_configpath))

        # Used by DokuReport class to show build environment details in report.
        config._environment = []
        # prevent opening dokupath on slave nodes (xdist)
        if not hasattr(config, 'slaveinput'):
            config.dokureport = DokuReport(
                config.option.integration_tests_config['dokuwiki'])
            config.pluginmanager.register(config.dokureport)


def pytest_unconfigure(config):
    integration_tests_configpath = config.getvalue("integration-tests")
    if integration_tests_configpath is not None:
        config.pluginmanager.unregister(config.dokureport)


@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    # execute all other hooks to obtain the report object
    outcome = yield
    report = outcome.get_result()
    if report.when == "call":
        if "plot_object" in item.fixturenames:
            plot_obj = item.funcargs["plot_object"]
            plot_obj.upload(report)
            report.extra = plot_obj.get_extras()


@pytest.fixture(scope="function")
def plot_object(request):
    return PlotUploader(request)


@pytest.fixture(scope="class", params=[
    path for path in glob.glob(os.path.join(
        os.path.dirname(os.path.realpath(__file__)), "*")) if os.path.isdir(path)
])
def data_path(request):
    integration_tests_config = request.config.option.integration_tests_config
    setup_name = os.path.basename(request.param)
    return {
        'config_dirpath': request.param,
        'reference_dirpath': os.path.join(os.path.expandvars(
            os.path.expanduser(integration_tests_config["reference"])), setup_name<commit_msg>Prevent dokureport plugin activation during generating ref data.<commit_after>import glob
import os
import yaml
import numpy as np
import pytest
from astropy import units as u

from tardis import __githash__ as tardis_githash
from tardis.tests.tests_slow.report import DokuReport
from tardis.tests.tests_slow.plot_helpers import PlotUploader


def pytest_addoption(parser):
    parser.addoption("--integration-tests", dest="integration-tests",
                     help="path to configuration file for integration tests")
    parser.addoption("--generate-reference", action="store_true",
                     help="execute integration test run to generate reference data")


def pytest_configure(config):
    integration_tests_configpath = config.getvalue("integration-tests")
    if integration_tests_configpath is not None:
        integration_tests_configpath = os.path.expandvars(
            os.path.expanduser(integration_tests_configpath)
        )
        config.option.integration_tests_config = yaml.load(
            open(integration_tests_configpath))

        if not config.getoption("--generate-reference"):
            config.option.generate_reference['generate_reference'] = None
            # Used by DokuReport class to show build environment details in report.
            config._environment = []
            # prevent opening dokupath on slave nodes (xdist)
            if not hasattr(config, 'slaveinput'):
                config.dokureport = DokuReport(
                    config.option.integration_tests_config['dokuwiki'])
                config.pluginmanager.register(config.dokureport)


def pytest_unconfigure(config):
    # Unregister only if it was registered in pytest_configure
    integration_tests_configpath = config.getvalue("integration-tests")
    if integration_tests_configpath and not config.getoption("--generate-reference"):
        config.pluginmanager.unregister(config.dokureport)


@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    # execute all other hooks to obtain the report object
    outcome = yield
    report = outcome.get_result()
    if report.when == "call":
        if "plot_object" in item.fixturenames:
            plot_obj = item.funcargs["plot_object"]
            plot_obj.upload(report)
            report.extra = plot_obj.get_extras()


@pytest.fixture(scope="function")
def plot_object(request):
    return PlotUploader(request)


@pytest.fixture(scope="class", params=[
    path for path in glob.glob(os.path.join(
        os.path.dirname(os.path.realpath(__file__)), "*")) if os.path.isdir(path)
])
def data_path(request):
    integration_tests_config = request.config.option.integration_tests_config
    setup_name = os.path.basename(request.param)
    return {
        'config_dirpath': request.param,
        'reference_dirpath': os.path.join(os.path.expandvars(
            os.path.expanduser(integration_tests_config["reference"])), setup_name
{'fraction_non_alphanumeric': 0.09084380610412926, 'fraction_numerical': 0.0, 'mean_word_length': 3.5, 'pattern_counts': {'":': 2, '<': 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': '3500999', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1549, 'n_words': 343}