<commit_before>import os
import shutil
import uuid
import subprocess

import gnupg

import config
import db
import crypto_util

def clean_root():
    shutil.rmtree(config.SECUREDROP_DATA_ROOT)


def create_directories():
    # Create directories for the file store and the GPG keyring
    for d in (config.SECUREDROP_DATA_ROOT, config.STORE_DIR, config.GPG_KEY_DIR):
        if not os.path.isdir(d):
            os.mkdir(d)


def init_gpg():
    # Initialize the GPG keyring
    gpg = gnupg.GPG(homedir=config.GPG_KEY_DIR)
    # Import the journalist key for testing (faster to import a pre-generated
    # key than to gen a new one every time)
    for keyfile in ("test_journalist_key.pub", "test_journalist_key.sec"):
        gpg.import_keys(open(keyfile).read())
    return gpg


def init_db():
    db.init_db()


def setup_test_docs(sid, files):
    filenames = [os.path.join(config.STORE_DIR, sid, file) for file in files]
    for filename in filenames:
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        with open(filename, 'w') as fp:<commit_msg>Create SecureDrop TEMP_DIR for tests<commit_after>import os
import shutil
import uuid
import subprocess

import gnupg

import config
import db
import crypto_util

def clean_root():
    shutil.rmtree(config.SECUREDROP_DATA_ROOT)


def create_directories():
    # Create directories for the file store and the GPG keyring
    for d in (config.SECUREDROP_DATA_ROOT, config.STORE_DIR,
              config.GPG_KEY_DIR, config.TEMP_DIR):
        if not os.path.isdir(d):
            os.mkdir(d)


def init_gpg():
    # Initialize the GPG keyring
    gpg = gnupg.GPG(homedir=config.GPG_KEY_DIR)
    # Import the journalist key for testing (faster to import a pre-generated
    # key than to gen a new one every time)
    for keyfile in ("test_journalist_key.pub", "test_journalist_key.sec"):
        gpg.import_keys(open(keyfile).read())
    return gpg


def init_db():
    db.init_db()


def setup_test_docs(sid, files):
    filenames = [os.path.join(config.STORE_DIR, sid, file) for file in files]
    for filename in filenames:
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        with open(filename, 'w') as fp:
{'fraction_non_alphanumeric': 0.09012131715771231, 'fraction_numerical': 0.0, 'mean_word_length': 3.2838589981447126, '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': '1496478', 'n_tokens_mistral': 786, 'n_tokens_neox': 773, 'n_words': 216}