<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Interpreter version: python 2.7
#
# Imports =====================================================================
import shutil
import os.path
import tempfile
import subprocess

import sh  # TODO: remove

from string import Template
from multiprocessing import Process


# Variables ===================================================================
SERV = None
TMP_DIR = None


# Functions & classes =========================================================
def data_context_name(fn):
    return os.path.join(os.path.dirname(__file__), "data", fn)


def data_context(fn, mode="r"):
    with open(data_context_name(fn), mode) as f:
        return f.read()


def tmp_context_name(fn):
    return os.path.join(TMP_DIR, fn)


def tmp_context(fn, mode="r"):
    with open(tmp_context_name(fn), mode) as f:
        return f.read()


# Environment generators ======================================================
def generate_environment():
    global TMP_DIR
    TMP_DIR = tempfile.mkdtemp()

    # write ZEO server config to  temp directory
    zeo_conf_path = os.path.join(TMP_DIR, "zeo.conf")
    with open(zeo_conf_path, "w") as f:
        f.write(
            Template(data_context("zeo.conf")).substitute(path=TMP_DIR)
        )

    # write client config to temp directory
    client_config_path = os.path.join(TMP_DIR, "zeo_client.conf")
    with open(client_config_path, "w") as f:
        f.write(data_context("zeo_client.conf"))

    # run the ZEO server
    def run_zeo():
        # subprocess.check_call("runzeo -C " + zeo_conf_path, shell=True)
        sh.runzeo(C=zeo_conf_path)<commit_msg>#5: Small improvements in tests.<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Interpreter version: python 2.7
#
# Imports =====================================================================
import shutil
import os.path
import tempfile

import sh

from string import Template
from multiprocessing import Process


# Variables ===================================================================
SERV = None
TMP_DIR = None


# Functions & classes =========================================================
def data_context_name(fn):
    return os.path.join(os.path.dirname(__file__), "data", fn)


def data_context(fn, mode="r"):
    with open(data_context_name(fn), mode) as f:
        return f.read()


def tmp_context_name(fn):
    return os.path.join(TMP_DIR, fn)


def tmp_context(fn, mode="r"):
    with open(tmp_context_name(fn), mode) as f:
        return f.read()


# Environment generators ======================================================
def generate_environment():
    global TMP_DIR
    TMP_DIR = tempfile.mkdtemp()

    # write ZEO server config to  temp directory
    zeo_conf_path = os.path.join(TMP_DIR, "zeo.conf")
    with open(zeo_conf_path, "w") as f:
        f.write(
            Template(data_context("zeo.conf")).substitute(path=TMP_DIR)
        )

    # write client config to temp directory
    client_config_path = os.path.join(TMP_DIR, "zeo_client.conf")
    shutil.copy(data_context_name("zeo_client.conf"), client_config_path)

    # run the ZEO server
    def run_zeo():
        # sh terminates when .terminate() is called, suprocess and os.system()
        # doesn't
        sh.runzeo(C=zeo_conf_path)
{'fraction_non_alphanumeric': 0.24729241877256317, 'fraction_numerical': 0.00210589651022864, 'mean_word_length': 4.155038759689923, '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': '5084872', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1002, 'n_words': 239}