<commit_before>import os
import sys
import ctypes
import platform

from time import sleep

import pytest
import PyQt5
from PyQt5.QtWidgets import QApplication

############
# SHITCODE #
########################################################################################################################
_platform = platform.system().lower()

ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir)
LIB_DIR = os.path.join(ROOT_DIR,
                       'externals', 'build',
                       "%s%s" % (_platform if _platform != 'darwin' else 'osx', platform.architecture()[0][0:2]),
                       'release', 'lib')

if _platform == 'windows':
    QApplication.addLibraryPath(os.path.join(os.path.dirname(PyQt5.__file__), "plugins"))
    ctypes.windll.LoadLibrary(
        os.path.join(ROOT_DIR, 'externals', 'build', 'windows64', 'Release', 'lib', 'nanomsg.dll'))
    # ctypes.windll.LoadLibrary('nanomsg.dll')
    sys.path.insert(0, 'C:\Python34\lib\site-packages')

else:
    _original_load = ctypes.cdll.LoadLibrary
    ctypes.cdll.LoadLibrary = lambda x: _original_load(os.path.join(LIB_DIR, x))

sys.path.insert(0, os.path.join(ROOT_DIR, "playground", "src"))

instance_counter = 0

from cetech.engine import EngineInstance, ReadyLock


@pytest.fixture(scope='session')
def _build_dir(tmpdir_factory):
    instance = EngineInstance("compile test", os.path.join(ROOT_DIR, "bin"), os.path.join(ROOT_DIR, "externals/build"))

    global instance_counter

    build_dir = tmpdir_factory.mktemp("data")

    port = 4444 + (instance_counter * 2)
    instance_counter += 1

    instance.run_develop(
        build_dir,
        os.path.join(ROOT_DIR, "data", "src"),
        core_dir=os.path.join(ROOT_DIR, "core"),
        compile_=True,
        check=True,
        port=port,
        lock=False
    )

    return build_dir


@pytest.fixture(scope="function")
def engine_instance(request, _build_dir):
    instance = EngineInstance("test", os.path.join(ROOT_DIR, "bin"), os.path.join(ROOT_DIR, "externals/build"))
    global instance_counter

    port = 4444 + (instance_counter * 2)
    instance_counter += 1

    sleep(0.5)

    instance.run_develop(
        _build_dir,
        os.path.join(ROOT_DIR, "data", "src"),
        core_dir=os.path.join(ROOT_DIR, "core"),
        port=port, protocol="tcp",
    )

    while not instance.ready:
        pass

    api = instance.create_console_api()
    api.connect()

    yield api

    api.quit()

    api.disconnect()

    instance.kill()
<commit_msg>one instance per test session<commit_after>import ctypes
import os
import platform
import sys

import PyQt5
import pytest
from PyQt5.QtWidgets import QApplication

############
# SHITCODE #
########################################################################################################################
_platform = platform.system().lower()

ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir)
LIB_DIR = os.path.join(ROOT_DIR,
                       'externals', 'build',
                       "%s%s" % (_platform if _platform != 'darwin' else 'osx', platform.architecture()[0][0:2]),
                       'release', 'lib')

if _platform == 'windows':
    QApplication.addLibraryPath(os.path.join(os.path.dirname(PyQt5.__file__), "plugins"))
    ctypes.windll.LoadLibrary(
        os.path.join(ROOT_DIR, 'externals', 'build', 'windows64', 'Release', 'lib', 'nanomsg.dll'))
    # ctypes.windll.LoadLibrary('nanomsg.dll')
    sys.path.insert(0, 'C:\Python34\lib\site-packages')

else:
    _original_load = ctypes.cdll.LoadLibrary
    ctypes.cdll.LoadLibrary = lambda x: _original_load(os.path.join(LIB_DIR, x))

sys.path.insert(0, os.path.join(ROOT_DIR, "playground", "src"))

instance_counter = 0

from cetech.engine import EngineInstance


@pytest.fixture(scope='session')
def _build_dir(tmpdir_factory):
    instance = EngineInstance("compile test", os.path.join(ROOT_DIR, "bin"), os.path.join(ROOT_DIR, "externals/build"))

    global instance_counter

    build_dir = tmpdir_factory.mktemp("data")

    port = 4444 + (instance_counter * 2)
    instance_counter += 1

    instance.run_develop(
        build_dir,
        os.path.join(ROOT_DIR, "data", "src"),
        core_dir=os.path.join(ROOT_DIR, "core"),
        compile_=True,
        check=True,
        port=port,
        lock=False
    )

    return build_dir


@pytest.fixture(scope="session")
def engine_instance(request, _build_dir):
    instance = EngineInstance("test", os.path.join(ROOT_DIR, "bin"), os.path.join(ROOT_DIR, "externals/build"))
    global instance_counter

    port = 4444 + (instance_counter * 2)
    instance_counter += 1

    instance.run_develop(
        _build_dir,
        os.path.join(ROOT_DIR, "data", "src"),
        core_dir=os.path.join(ROOT_DIR, "core"),
        port=port, protocol="tcp",
    )

    while not instance.ready:
        pass

    api = instance.create_console_api()
    api.connect()

    yield api

    api.quit()

    api.disconnect()

    instance.kill()

{'fraction_non_alphanumeric': 0.18436636399526254, 'fraction_numerical': 0.010264508487958943, 'mean_word_length': 3.524107142857143, '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': '5864895', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1621, 'n_words': 296}