<commit_before>from __future__ import with_statement

import os
from os.path import abspath, dirname, join
from subprocess import call, STDOUT
import tempfile

from robot.errors import DataError
from robot.utils.asserts import assert_equals
from robot.tidy import TidyCommandLine
import robot.tidy

ROBOT_SRC = join(dirname(abspath(__file__)), '..', '..', '..', 'src')


class TidyLib(object):

    def __init__(self, interpreter):
        self._cmd = [interpreter, '-m', 'robot.tidy']
        self._interpreter = interpreter
        path_var = 'PYTHONPATH' if 'python' in interpreter else 'JYTHONPATH'
        self._env = os.environ.copy()
        self._env.update({path_var: ROBOT_SRC})

    def run_tidy_and_return_output(self, options, input, command=None):
        """Runs tidy in the operating system and returns output."""
        options = options.split(' ') if options else []
        with tempfile.TemporaryFile() as output:
            rc = call(self._cmd + options + [self._path(input)],
                      stdout=output, stderr=STDOUT, env=self._env, shell=True)
            output.seek(0)
            content = output.read()
            if rc:
                raise RuntimeError(content)
            return content

    def run_tidy_and_check_result(self, options, input, expected):
        """Runs tidy and checks that output matches content of file `expected`."""
        result = self.run_tidy_and_return_output(options, input)<commit_msg>TidyLib: use shell=True only in Windows<commit_after>from __future__ import with_statement

import os
from os.path import abspath, dirname, join
from subprocess import call, STDOUT
import tempfile

from robot.errors import DataError
from robot.utils.asserts import assert_equals
from robot.tidy import TidyCommandLine
import robot.tidy

ROBOT_SRC = join(dirname(abspath(__file__)), '..', '..', '..', 'src')


class TidyLib(object):

    def __init__(self, interpreter):
        self._cmd = [interpreter, '-m', 'robot.tidy']
        self._interpreter = interpreter
        path_var = 'PYTHONPATH' if 'python' in interpreter else 'JYTHONPATH'
        self._env = os.environ.copy()
        self._env.update({path_var: ROBOT_SRC})

    def run_tidy_and_return_output(self, options, input, command=None):
        """Runs tidy in the operating system and returns output."""
        options = options.split(' ') if options else []
        with tempfile.TemporaryFile() as output:
            rc = call(self._cmd + options + [self._path(input)],
                      stdout=output, stderr=STDOUT, env=self._env, shell=os.sep=='\\')
            output.seek(0)
            content = output.read()
            if rc:
                raise RuntimeError(content)
            return content

    def run_tidy_and_check_result(self, options, input, expected):
        """Runs tidy and checks that output matches content of file `expected`."""
        result = self.run_tidy_and_return_output(options, input)
{'fraction_non_alphanumeric': 0.10738482384823848, 'fraction_numerical': 0.0006775067750677507, 'mean_word_length': 3.028649386084584, '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': '3279213', 'n_tokens_mistral': 882, 'n_tokens_neox': 855, 'n_words': 240}