<commit_before>#!/usr/bin/env python

"""A script for running Robot Framework's acceptance tests.

Usage:  run_atests.py interpreter [options] datasource(s)

Data sources are paths to directories or files under `robot` folder.

Available options are the same that can be used with Robot Framework.
See its help (e.g. `pybot --help`) for more information.

The specified interpreter is used by acceptance tests under `robot` to
run test cases under `testdata`. It can be simply `python` or `jython`
(if they are in PATH) or to a path a selected interpreter (e.g.
`/usr/bin/python26`). Note that this script itself must always be
executed with Python.

Examples:
$ atest/run_atests.py python --test example atest/robot
$ atest/run_atests.py /usr/bin/jython25 atest/robot/tags/tag_doc.txt
"""

import os
import shutil
import signal
import subprocess
import sys
import tempfile
from os.path import abspath, basename, dirname, exists, join, normpath, splitext


CURDIR = dirname(abspath(__file__))
RUNNER = normpath(join(CURDIR, '..', 'src', 'robot', 'run.py'))
ARGUMENTS = ' '.join('''
--doc RobotSPFrameworkSPacceptanceSPtests
--reporttitle RobotSPFrameworkSPTestSPReport
--logtitle RobotSPFrameworkSPTestSPLog
--metadata Interpreter:%(INTERPRETER)s
--metadata Platform:%(PLATFORM)s
--variable INTERPRETER:%(INTERPRETER)s
--variable STANDALONE_JYTHON:NO
--pythonpath %(PYTHONPATH)s
--include %(INCLUDE)s
--outputdir %(OUTPUTDIR)s
--output output.xml
--report report.html
--log log.html
--splitlog
--escape space:SP
--escape star:STAR
--escape paren1:PAR1
--escape paren2:PAR2
--critical regression
--SuiteStatLevel 3
--TagStatCombine jybotNOTpybot
--TagStatCombine pybotNOTjybot
--TagStatExclude pybot
--TagStatExclude jybot
--TagStatExclude x-*
'''.strip().split())


def atests(interpreter, *params):
    resultdir, tempdir = _get_result_and_temp_dirs(interpreter)
    args = ARGUMENTS % {
        'PYTHONPATH' : join(CURDIR, 'resources'),
        'OUTPUTDIR' : resultdir,
        'INTERPRETER': interpreter,
        'PLATFORM': sys.platform,
        'INCLUDE': 'jybot' if 'jython' in basename(interpreter) else 'pybot'
    }
    if os.name == 'nt':
        args += ' --exclude x-exclude-on-windows'
    if sys.platform == 'darwin' and 'python' in basename(interpreter):
        args += ' --exclude x-exclude-on-osx-python'
    command = '%s %s %s %s' % (sys.executable, RUNNER, args, ' '.join(params))
    environ = dict(os.environ, TEMPDIR=tempdir)
    print 'Running command\n%s\n' % command
    sys.stdout.flush()
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    try:
        return subprocess.call(command.split(), env=environ)
    finally:
        shutil.rmtree(tempdir)


def _get_result_and_temp_dirs(interpreter):
    interpreter = splitext(basename(interpreter))[0]
    resultdir = join(CURDIR, 'results', interpreter)
    tempdir = join(tempfile.gettempdir(), 'robottests', interpreter)
    if os.path.exists(tempdir):
        print 'Temp directory for this interpreter already exists:', tempdir
        print 'Cannot run tests simultaneously with same interpreter.'
        print 'Remove the directory if it is left from an interrupted run.'
        sys.exit(255)
    if exists(resultdir):
        shutil.rmtree(resultdir)
    os.mkdir(tempdir)
    return resultdir, tempdir


if __name__ == '__main__':
    if len(sys.argv) == 1 or '--help' in sys.argv:
        print __doc__
        rc = 251
    else:
        rc = atests(*sys.argv[1:])
    sys.exit(rc)<commit_msg>run_atests.py: create also intermeditate dirs when creating tempdir<commit_after>#!/usr/bin/env python

"""A script for running Robot Framework's acceptance tests.

Usage:  run_atests.py interpreter [options] datasource(s)

Data sources are paths to directories or files under `robot` folder.

Available options are the same that can be used with Robot Framework.
See its help (e.g. `pybot --help`) for more information.

The specified interpreter is used by acceptance tests under `robot` to
run test cases under `testdata`. It can be simply `python` or `jython`
(if they are in PATH) or to a path a selected interpreter (e.g.
`/usr/bin/python26`). Note that this script itself must always be
executed with Python.

Examples:
$ atest/run_atests.py python --test example atest/robot
$ atest/run_atests.py /usr/bin/jython25 atest/robot/tags/tag_doc.txt
"""

import os
import shutil
import signal
import subprocess
import sys
import tempfile
from os.path import abspath, basename, dirname, exists, join, normpath, splitext


CURDIR = dirname(abspath(__file__))
RUNNER = normpath(join(CURDIR, '..', 'src', 'robot', 'run.py'))
ARGUMENTS = ' '.join('''
--doc RobotSPFrameworkSPacceptanceSPtests
--reporttitle RobotSPFrameworkSPTestSPReport
--logtitle RobotSPFrameworkSPTestSPLog
--metadata Interpreter:%(INTERPRETER)s
--metadata Platform:%(PLATFORM)s
--variable INTERPRETER:%(INTERPRETER)s
--variable STANDALONE_JYTHON:NO
--pythonpath %(PYTHONPATH)s
--include %(INCLUDE)s
--outputdir %(OUTPUTDIR)s
--output output.xml
--report report.html
--log log.html
--splitlog
--escape space:SP
--escape star:STAR
--escape paren1:PAR1
--escape paren2:PAR2
--critical regression
--SuiteStatLevel 3
--TagStatCombine jybotNOTpybot
--TagStatCombine pybotNOTjybot
--TagStatExclude pybot
--TagStatExclude jybot
--TagStatExclude x-*
'''.strip().split())


def atests(interpreter, *params):
    resultdir, tempdir = _get_result_and_temp_dirs(interpreter)
    args = ARGUMENTS % {
        'PYTHONPATH' : join(CURDIR, 'resources'),
        'OUTPUTDIR' : resultdir,
        'INTERPRETER': interpreter,
        'PLATFORM': sys.platform,
        'INCLUDE': 'jybot' if 'jython' in basename(interpreter) else 'pybot'
    }
    if os.name == 'nt':
        args += ' --exclude x-exclude-on-windows'
    if sys.platform == 'darwin' and 'python' in basename(interpreter):
        args += ' --exclude x-exclude-on-osx-python'
    command = '%s %s %s %s' % (sys.executable, RUNNER, args, ' '.join(params))
    environ = dict(os.environ, TEMPDIR=tempdir)
    print 'Running command\n%s\n' % command
    sys.stdout.flush()
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    try:
        return subprocess.call(command.split(), env=environ)
    finally:
        shutil.rmtree(tempdir)


def _get_result_and_temp_dirs(interpreter):
    interpreter = splitext(basename(interpreter))[0]
    resultdir = join(CURDIR, 'results', interpreter)
    tempdir = join(tempfile.gettempdir(), 'robottests', interpreter)
    if os.path.exists(tempdir):
        print 'Temp directory for this interpreter already exists:', tempdir
        print 'Cannot run tests simultaneously with same interpreter.'
        print 'Remove the directory if it is left from an interrupted run.'
        sys.exit(255)
    if exists(resultdir):
        shutil.rmtree(resultdir)
    os.makedirs(tempdir)
    return resultdir, tempdir


if __name__ == '__main__':
    if len(sys.argv) == 1 or '--help' in sys.argv:
        print __doc__
        rc = 251
    else:
        rc = atests(*sys.argv[1:])
    sys.exit(rc)
{'fraction_non_alphanumeric': 0.12106537530266344, 'fraction_numerical': 0.00512747471870104, 'mean_word_length': 3.7931740614334473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4780626', 'n_tokens_mistral': 2367, 'n_tokens_neox': 2308, 'n_words': 648}