<commit_before>import re
import shlex
import subprocess
from config import SALT_KEY_CMD


def assert_minion_key_state(env, expected_state):
    STATES_MAPPING = dict(
        unaccepted=re.compile("Unaccepted Keys:\n{HOSTNAME}".format(**env)),
        accepted=re.compile("Accepted Keys:\n{HOSTNAME}".format(**env))
    )
    assert expected_state in STATES_MAPPING
    cmd = shlex.split(SALT_KEY_CMD.format(**env))
    cmd.append("-L")
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env)
    output, unused_err = process.communicate()
    assert STATES_MAPPING[expected_state].search(output)


def assert_proxyminion_key_state(env, expected_state):
    STATES_MAPPING = dict(
        unaccepted=re.compile("Unaccepted Keys:\n{PROXY_ID}".format(**env)),
        accepted=re.compile("Accepted Keys:\n{PROXY_ID}".format(**env))
    )
    assert expected_state in STATES_MAPPING
    cmd = shlex.split(SALT_KEY_CMD.format(**env))
    cmd.append("-L")
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env)
    output, unused_err = process.communicate()
    assert STATES_MAPPING[expected_state].search(output)<commit_msg>Fix minion state assertions - multiple keys possible<commit_after>import re
import shlex
import subprocess
from config import SALT_KEY_CMD


def has_expected_state(expected_state, mapping, env):
    assert expected_state in mapping
    cmd = shlex.split(SALT_KEY_CMD.format(**env))
    cmd.append("-L")
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env)
    output, unused_err = process.communicate()
    return mapping[expected_state].search(output) is not None


def assert_minion_key_state(env, expected_state):
    STATES_MAPPING = dict(
        unaccepted=re.compile("Unaccepted Keys:(\n.+)*\n{HOSTNAME}".format(**env)),
        accepted=re.compile("Accepted Keys:(\n.+)*\n{HOSTNAME}".format(**env))
    )
    assert has_expected_state(expected_state, STATES_MAPPING, env)


def assert_proxyminion_key_state(env, expected_state):
    STATES_MAPPING = dict(
        unaccepted=re.compile("Unaccepted Keys:(\n.+)*\n{PROXY_ID}".format(**env)),
        accepted=re.compile("Accepted Keys:(\n.+)*\n{PROXY_ID}".format(**env))
    )
    assert has_expected_state(expected_state, STATES_MAPPING, env)
{'fraction_non_alphanumeric': 0.1316836058329651, 'fraction_numerical': 0.0, 'mean_word_length': 4.880519480519481, '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': '1298334', 'n_tokens_mistral': 794, 'n_tokens_neox': 751, 'n_words': 124}