<commit_before>import sys
from invoke.vendor.six import StringIO

from spec import Spec, trap, eq_, skip

from invoke import Local, Context

from _utils import mock_subprocess, mock_pty


class Local_(Spec):
    class run:
        def _run(self, *args, **kwargs):
            return Local(Context()).run(*args, **kwargs)

        @trap
        @mock_subprocess(out="sup")
        def out_stream_defaults_to_sys_stdout(self):
            "out_stream defaults to sys.stdout"
            self._run("nope")
            eq_(sys.stdout.getvalue(), "sup")

        @trap
        @mock_subprocess(err="sup")
        def err_stream_defaults_to_sys_stderr(self):
            "err_stream defaults to sys.stderr"
            self._run("nope")
            eq_(sys.stderr.getvalue(), "sup")

        @trap
        @mock_subprocess(out="sup")
        def out_stream_can_be_overridden(self):
            "out_stream can be overridden"
            out = StringIO()
            self._run("nope", out_stream=out)
            eq_(out.getvalue(), "sup")
            eq_(sys.stdout.getvalue(), "")

        @trap
        @mock_subprocess(err="sup")
        def err_stream_can_be_overridden(self):
            "err_stream can be overridden"
            err = StringIO()
            self._run("nope", err_stream=err)
            eq_(err.getvalue(), "sup")
            eq_(sys.stderr.getvalue(), "")

        @trap
        @mock_pty(out="sup")
        def pty_output_stream_defaults_to_sys(self):
            self._run("nope", pty=True)
            eq_(sys.stdout.getvalue(), "sup")

        @trap
        @mock_pty(out="yo")
        def pty_output_stream_overrides_work(self):
            out = StringIO()
            self._run("nope", pty=True, out_stream=out)
            eq_(out.getvalue(), "yo")
            eq_(sys.stdout.getvalue(), "")

        def pty_fallback_warnings_only_fire_once(self):
            # I.e. if implementation checks pty-ness >1 time, only one warning
            # is emitted. This is kinda implementation-specific, but...
            skip()

        def encoding_defaults_to_local_encoding(self):
            skip()

        def encoding_can_be_overridden(self):
            skip()

        @mock_pty(isatty=False)
        def fallback_can_be_overridden(self):
            # Do the stuff
            self._run("true", pty=True, fallback=False)
            # @mock_pty's asserts will be mad if pty-related os/pty calls
            # didn't fire, so we're done.<commit_msg>Meh @ nesting<commit_after>import sys
from invoke.vendor.six import StringIO

from spec import Spec, trap, eq_, skip

from invoke import Local, Context

from _utils import mock_subprocess, mock_pty


class Local_(Spec):
    def _run(self, *args, **kwargs):
        return Local(Context()).run(*args, **kwargs)

    @trap
    @mock_subprocess(out="sup")
    def out_stream_defaults_to_sys_stdout(self):
        "out_stream defaults to sys.stdout"
        self._run("nope")
        eq_(sys.stdout.getvalue(), "sup")

    @trap
    @mock_subprocess(err="sup")
    def err_stream_defaults_to_sys_stderr(self):
        "err_stream defaults to sys.stderr"
        self._run("nope")
        eq_(sys.stderr.getvalue(), "sup")

    @trap
    @mock_subprocess(out="sup")
    def out_stream_can_be_overridden(self):
        "out_stream can be overridden"
        out = StringIO()
        self._run("nope", out_stream=out)
        eq_(out.getvalue(), "sup")
        eq_(sys.stdout.getvalue(), "")

    @trap
    @mock_subprocess(err="sup")
    def err_stream_can_be_overridden(self):
        "err_stream can be overridden"
        err = StringIO()
        self._run("nope", err_stream=err)
        eq_(err.getvalue(), "sup")
        eq_(sys.stderr.getvalue(), "")

    @trap
    @mock_pty(out="sup")
    def pty_output_stream_defaults_to_sys(self):
        self._run("nope", pty=True)
        eq_(sys.stdout.getvalue(), "sup")

    @trap
    @mock_pty(out="yo")
    def pty_output_stream_overrides_work(self):
        out = StringIO()
        self._run("nope", pty=True, out_stream=out)
        eq_(out.getvalue(), "yo")
        eq_(sys.stdout.getvalue(), "")

    def pty_fallback_warnings_only_fire_once(self):
        # I.e. if implementation checks pty-ness >1 time, only one warning
        # is emitted. This is kinda implementation-specific, but...
        skip()

    def encoding_defaults_to_local_encoding(self):
        skip()

    def encoding_can_be_overridden(self):
        skip()

    @mock_pty(isatty=False)
    def fallback_can_be_overridden(self):
        # Do the stuff
        self._run("true", pty=True, fallback=False)
        # @mock_pty's asserts will be mad if pty-related os/pty calls
        # didn't fire, so we're done.
{'fraction_non_alphanumeric': 0.12094207511139402, 'fraction_numerical': 0.000424358158285593, 'mean_word_length': 2.443389335281227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4393116', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1499, 'n_words': 308}