<commit_before>"""
    :codeauthor: <NAME> <<EMAIL>>
"""

import pytest
import salt.utils.platform
from tests.support.case import ShellCase


@pytest.mark.windows_whitelisted
@pytest.mark.usefixtures("salt_sub_minion")
class BatchTest(ShellCase):
    """
    Integration tests for the salt.cli.batch module
    """

    if salt.utils.platform.is_windows():
        run_timeout = 180
    else:
        run_timeout = 30

    @pytest.mark.slow_test
    def test_batch_run(self):
        """
        Tests executing a simple batch command to help catch regressions
        """
        ret = "Executing run on [{}]".format(repr("sub_minion"))
        cmd = self.run_salt(
            '"*minion" test.echo "batch testing" -b 50%', timeout=self.run_timeout,
        )
        self.assertIn(ret, cmd)

    @pytest.mark.slow_test
    def test_batch_run_number(self):
        """
        Tests executing a simple batch command using a number division instead of
        a percentage with full batch CLI call.
        """
        ret = "Executing run on [{}, {}]".format(repr("minion"), repr("sub_minion"))
        cmd = self.run_salt(
            '"*minion" test.ping --batch-size 2', timeout=self.run_timeout,
        )
        self.assertIn(ret, cmd)

    @pytest.mark.slow_test
    def test_batch_run_grains_targeting(self):
        """
        Tests executing a batch command using a percentage divisor as well as grains
        targeting.
        """
        os_grain = ""
        sub_min_ret = "Executing run on [{}]".format(repr("sub_minion"))
        min_ret = "Executing run on [{}]".format(repr("minion"))

        for item in self.run_salt("minion grains.get os"):
            if item != "minion:":
                os_grain = item

        os_grain = os_grain.strip()
        cmd = self.run_salt(
            '-C "G@os:{} and not localhost" -b 25% test.ping'.format(os_grain),
            timeout=self.run_timeout,
        )
        self.assertIn(sub_min_ret, cmd)
        self.assertIn(min_ret, cmd)

    @pytest.mark.slow_test
    def test_batch_exit_code(self):
        """
        Test that a failed state returns a non-zero exit code in batch mode
        """
        cmd = self.run_salt(
            ' "*" state.single test.fail_without_changes name=test_me -b 25%',
            with_retcode=True,
            timeout=self.run_timeout,
        )
        self.assertEqual(cmd[-1], 2)<commit_msg>Use ? for matching spaces<commit_after>"""
    :codeauthor: <NAME> <<EMAIL>>
"""

import pytest
import salt.utils.platform
from tests.support.case import ShellCase


@pytest.mark.windows_whitelisted
@pytest.mark.usefixtures("salt_sub_minion")
class BatchTest(ShellCase):
    """
    Integration tests for the salt.cli.batch module
    """

    if salt.utils.platform.is_windows():
        run_timeout = 180
    else:
        run_timeout = 30

    @pytest.mark.slow_test
    def test_batch_run(self):
        """
        Tests executing a simple batch command to help catch regressions
        """
        ret = "Executing run on [{}]".format(repr("sub_minion"))
        cmd = self.run_salt(
            '"*minion" test.echo "batch testing" -b 50%', timeout=self.run_timeout,
        )
        self.assertIn(ret, cmd)

    @pytest.mark.slow_test
    def test_batch_run_number(self):
        """
        Tests executing a simple batch command using a number division instead of
        a percentage with full batch CLI call.
        """
        ret = "Executing run on [{}, {}]".format(repr("minion"), repr("sub_minion"))
        cmd = self.run_salt(
            '"*minion" test.ping --batch-size 2', timeout=self.run_timeout,
        )
        self.assertIn(ret, cmd)

    @pytest.mark.slow_test
    def test_batch_run_grains_targeting(self):
        """
        Tests executing a batch command using a percentage divisor as well as grains
        targeting.
        """
        os_grain = ""
        sub_min_ret = "Executing run on [{}]".format(repr("sub_minion"))
        min_ret = "Executing run on [{}]".format(repr("minion"))

        for item in self.run_salt("minion grains.get os"):
            if item != "minion:":
                os_grain = item

        os_grain = os_grain.strip()
        cmd = self.run_salt(
            '-C "G@os:{} and not localhost" -b 25% test.ping'.format(
                os_grain.replace(" ", "?")
            ),
            timeout=self.run_timeout,
        )
        self.assertIn(sub_min_ret, cmd)
        self.assertIn(min_ret, cmd)

    @pytest.mark.slow_test
    def test_batch_exit_code(self):
        """
        Test that a failed state returns a non-zero exit code in batch mode
        """
        cmd = self.run_salt(
            ' "*" state.single test.fail_without_changes name=test_me -b 25%',
            with_retcode=True,
            timeout=self.run_timeout,
        )
        self.assertEqual(cmd[-1], 2)
{'fraction_non_alphanumeric': 0.12052653229123818, 'fraction_numerical': 0.005758946935417524, 'mean_word_length': 2.229083665338645, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '956386', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1506, 'n_words': 359}