<commit_before>import os

from expyfun.utils import _TempDir, tdt_test
from expyfun import ExperimentController

tempdir = _TempDir()
std_args = ['test']
std_kwargs = dict(participant='foo', session='01', full_screen=False,
                  window_size=(1, 1))


def test_logging(ac='psychopy'):
    """Test logging to file (PsychoPy)
    """
    os.chdir(tempdir)
    ec = ExperimentController(*std_args, audio_controller=ac, **std_kwargs)
    test_name = ec._log_file
    stamp = ec.current_time
    ec.wait_until(stamp)  # should log a warning
    ec.close()
    with open(test_name) as fid:
        data = '\n'.join(fid.readlines())

    # check for various expected log messages (TODO: add more)
    should_have = ['Subject: foo', 'Session: 01', 'wait_until was called']
    if ac == 'psychopy':
        should_have.append('PsychoPy')
    else:
        should_have.append('TDT')

    for s in should_have:
        if not s in data:
            raise ValueError('Missing data: "{0}" in:\n{1}'.format(s, data))


@tdt_test<commit_msg>added test for RMS checking to test_logging<commit_after>import os

from expyfun.utils import _TempDir, tdt_test
from expyfun import ExperimentController

tempdir = _TempDir()
std_args = ['test']
std_kwargs = dict(participant='foo', session='01', full_screen=False,
                  window_size=(1, 1))


def test_logging(ac='psychopy'):
    """Test logging to file (PsychoPy)
    """
    os.chdir(tempdir)
    ec = ExperimentController(*std_args, audio_controller=ac, **std_kwargs)
    test_name = ec._log_file
    stamp = ec.current_time
    ec.wait_until(stamp)  # wait_until called with already passed timestamp
    ec.load_buffer([1., -1., 1., -1., 1., -1.])  # RMS warning
    ec.close()
    with open(test_name) as fid:
        data = '\n'.join(fid.readlines())

    # check for various expected log messages (TODO: add more)
    should_have = ['Subject: foo', 'Session: 01', 'wait_until was called',
                   'Stimulus max RMS exceeds']
    if ac == 'psychopy':
        should_have.append('PsychoPy')
    else:
        should_have.append('TDT')

    for s in should_have:
        if not s in data:
            raise ValueError('Missing data: "{0}" in:\n{1}'.format(s, data))


@tdt_test
{'fraction_non_alphanumeric': 0.12884529647793133, 'fraction_numerical': 0.00980829246544806, 'mean_word_length': 3.202247191011236, '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': '4599661', 'n_tokens_mistral': 762, 'n_tokens_neox': 728, 'n_words': 195}