<commit_before>import sys
import pytest
import ansible
import mock
from _pytest.main import EXIT_OK, EXIT_TESTSFAILED, EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED, EXIT_INTERRUPTED

if sys.version_info[0] == 2:
    import __builtin__ as builtins  # NOQA
else:
    import builtins  # NOQA


def test_plugin_help(testdir):
    """Verifies expected output from of py.test --help"""

    result = testdir.runpytest('--help')
    result.stdout.fnmatch_lines([
        # Check for the github args section header
        'pytest-ansible:',
        # Check for the specific args
        '  --ansible-inventory=ANSIBLE_INVENTORY, --inventory=ANSIBLE_INVENTORY',
        '  --ansible-host-pattern=ANSIBLE_HOST_PATTERN, --host-pattern=ANSIBLE_HOST_PATTERN',
        '  --ansible-connection=ANSIBLE_CONNECTION, --connection=ANSIBLE_CONNECTION',
        '  --ansible-user=ANSIBLE_USER, --user=ANSIBLE_USER',
        '  --ansible-check, --check',
        '  --ansible-module-path=ANSIBLE_MODULE_PATH, --module-path=ANSIBLE_MODULE_PATH',
        '  --ansible-become, --become',
        '  --ansible-become-method=ANSIBLE_BECOME_METHOD, --become-method=ANSIBLE_BECOME_METHOD',
        '  --ansible-become-user=ANSIBLE_BECOME_USER, --become-user=ANSIBLE_BECOME_USER',
        '  --ansible-ask-become-pass=ANSIBLE_ASK_BECOME_PASS, --ask-become-pass=ANSIBLE_ASK_BECOME_PASS',
        # Check for the marker in --help
        '  ansible (args) * Ansible integration',
    ])


def test_plugin_markers(testdir):
    """Verifies expected output from of py.test --markers"""

    result = testdir.runpytest('--markers')
    result.stdout.fnmatch_lines([
        '@pytest.mark.ansible(*args): Ansible integration',
    ])


def test_report_header(testdir, option):
    """Verify the expected ansible version in the pytest report header.
    """

    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_NOTESTSCOLLECTED
    result.stdout.fnmatch_lines([
        'ansible: %s' % ansible.__version__,
    ])


def test_params_not_required_when_not_using_fixture(testdir, option):
    """Verify the ansible parameters are not required if the fixture is not used.
    """

    src = """
        import pytest
        def test_func():
            assert True
    """
    testdir.makepyfile(src)
    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_OK


@pytest.mark.parametrize(
    "fixture_name",
    [
        'ansible_adhoc',
        'ansible_module',
        'ansible_facts',
    ],
)
def test_params_required_when_using_fixture(testdir, option, fixture_name):
    """Verify the ansible parameters are required if the fixture is used.
    """

    src = """
        import pytest
        def test_func({0}):
            {0}
    """.format(fixture_name)
    testdir.makepyfile(src)
    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_USAGEERROR
    result.stderr.fnmatch_lines([
        'ERROR: Missing required parameter --ansible-host-pattern/--host-pattern',
    ])


@pytest.mark.parametrize(
    "fixture_name",
    [
        'ansible_host',
        'ansible_group',
    ],
)
def test_params_required_when_using_generator(testdir, option, fixture_name):
    """Verify the ansible parameters are required when using a fixture generator.
    """

    src = """
        import pytest
        def test_func({0}):
            assert True
    """.format(fixture_name)
    testdir.makepyfile(src)
    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_TESTSFAILED
    result.stdout.fnmatch_lines([
        'collected 0 items / 1 errors',
        'E   UsageError: Missing required parameter --ansible-host-pattern/--host-pattern',
    ])


@pytest.mark.parametrize(
    "required_value_parameter",<commit_msg>Fix to work with newest py.test<commit_after>import sys
import pytest
import ansible
import mock
from _pytest.main import EXIT_OK, EXIT_TESTSFAILED, EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED, EXIT_INTERRUPTED

if sys.version_info[0] == 2:
    import __builtin__ as builtins  # NOQA
else:
    import builtins  # NOQA


def test_plugin_help(testdir):
    """Verifies expected output from of py.test --help"""

    result = testdir.runpytest('--help')
    result.stdout.fnmatch_lines([
        # Check for the github args section header
        'pytest-ansible:',
        # Check for the specific args
        '  --ansible-inventory=ANSIBLE_INVENTORY, --inventory=ANSIBLE_INVENTORY',
        '  --ansible-host-pattern=ANSIBLE_HOST_PATTERN, --host-pattern=ANSIBLE_HOST_PATTERN',
        '  --ansible-connection=ANSIBLE_CONNECTION, --connection=ANSIBLE_CONNECTION',
        '  --ansible-user=ANSIBLE_USER, --user=ANSIBLE_USER',
        '  --ansible-check, --check',
        '  --ansible-module-path=ANSIBLE_MODULE_PATH, --module-path=ANSIBLE_MODULE_PATH',
        '  --ansible-become, --become',
        '  --ansible-become-method=ANSIBLE_BECOME_METHOD, --become-method=ANSIBLE_BECOME_METHOD',
        '  --ansible-become-user=ANSIBLE_BECOME_USER, --become-user=ANSIBLE_BECOME_USER',
        '  --ansible-ask-become-pass=ANSIBLE_ASK_BECOME_PASS, --ask-become-pass=ANSIBLE_ASK_BECOME_PASS',
        # Check for the marker in --help
        '  ansible (args) * Ansible integration',
    ])


def test_plugin_markers(testdir):
    """Verifies expected output from of py.test --markers"""

    result = testdir.runpytest('--markers')
    result.stdout.fnmatch_lines([
        '@pytest.mark.ansible(*args): Ansible integration',
    ])


def test_report_header(testdir, option):
    """Verify the expected ansible version in the pytest report header.
    """

    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_NOTESTSCOLLECTED
    result.stdout.fnmatch_lines([
        'ansible: %s' % ansible.__version__,
    ])


def test_params_not_required_when_not_using_fixture(testdir, option):
    """Verify the ansible parameters are not required if the fixture is not used.
    """

    src = """
        import pytest
        def test_func():
            assert True
    """
    testdir.makepyfile(src)
    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_OK


@pytest.mark.parametrize(
    "fixture_name",
    [
        'ansible_adhoc',
        'ansible_module',
        'ansible_facts',
    ],
)
def test_params_required_when_using_fixture(testdir, option, fixture_name):
    """Verify the ansible parameters are required if the fixture is used.
    """

    src = """
        import pytest
        def test_func({0}):
            {0}
    """.format(fixture_name)
    testdir.makepyfile(src)
    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_USAGEERROR
    result.stderr.fnmatch_lines([
        'ERROR: Missing required parameter --ansible-host-pattern/--host-pattern',
    ])


@pytest.mark.parametrize(
    "fixture_name",
    [
        'ansible_host',
        'ansible_group',
    ],
)
def test_params_required_when_using_generator(testdir, option, fixture_name):
    """Verify the ansible parameters are required when using a fixture generator.
    """

    src = """
        import pytest
        def test_func({0}):
            assert True
    """.format(fixture_name)
    testdir.makepyfile(src)
    result = testdir.runpytest(*option.args)
    assert result.ret == EXIT_INTERRUPTED
    result.stdout.fnmatch_lines([
        'collected 0 items / 1 errors',
        'E   UsageError: Missing required parameter --ansible-host-pattern/--host-pattern',
    ])


@pytest.mark.parametrize(
    "required_value_parameter",
{'fraction_non_alphanumeric': 0.11770169851380043, 'fraction_numerical': 0.0018577494692144374, 'mean_word_length': 3.0197333333333334, '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': '7421155', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2480, 'n_words': 474}