# -*- coding: utf-8 -*-

TEST_FACTORIAL = """
def test_factorial(wish):
    assert wish(0) == 1
    assert wish(1) == 1
    assert wish(21) == 51090942171709440000
"""


def test_import_coverage():
    """Fix the coverage by pytest-cov, that may trigger after pytest_wish is already imported."""
    from imp import reload  # Python 2 and 3 reload
    import pytest_wish
    reload(pytest_wish)


def test_help_message(testdir):
    result = testdir.runpytest(
        '--help',
    )
    # fnmatch_lines does an assertion internally
    result.stdout.fnmatch_lines([
        'wish:',
        '*--wish-modules*',
        '*--wish-fail*',
    ])


def test_skip_tests(testdir):
    """Make sure that pytest accepts our fixture."""

    # create a temporary pytest test module
    testdir.makepyfile(TEST_FACTORIAL)

    # run pytest with the following cmd args
    result = testdir.runpytest(
        '-v',
    )

    # fnmatch_lines does an assertion internally
    result.stdout.fnmatch_lines([
        '*::test_factorial*wish*SKIPPED',
    ])

    # make sure that that we get a '0' exit code for the testsuite
    assert result.ret == 0


def test_generate_tests(testdir):
    """Make sure that pytest accepts our fixture."""

    # create a temporary pytest test module
    testdir.makepyfile(TEST_FACTORIAL)

    # run pytest with the following cmd args
    result = testdir.runpytest(
        '--wish-modules=math',
        '-v',
    )

    # fnmatch_lines does an assertion internally
    result.stdout.fnmatch_lines([
        '*::test_factorial*math:factorial*XPASS',
    ])

    # make sure that that we get a '0' exit code for the testsuite
    assert result.ret == 0

# -*- coding: utf-8 -*-

TEST_FACTORIAL = """
def test_factorial(wish):
    assert wish(0) == 1
    assert wish(1) == 1
    assert wish(21) == 51090942171709440000
"""


def test_import_coverage():
    """Fix the coverage by pytest-cov, that may trigger after pytest_wish is already imported."""
    from imp import reload  # Python 2 and 3 reload
    import pytest_wish
    reload(pytest_wish)


def test_help_message(testdir):
    result = testdir.runpytest(
        '--help',
    )
    # fnmatch_lines does an assertion internally
    result.stdout.fnmatch_lines([
        'wish:',
        '*--wish-modules*',
        '*--wish-fail*',
    ])


def test_skip_tests(testdir):
    """Make sure that pytest accepts our fixture."""

    # create a temporary pytest test module
    testdir.makepyfile(TEST_FACTORIAL)

    # run pytest with the following cmd args
    result = testdir.runpytest(
        '-v',
    )

    # fnmatch_lines does an assertion internally
    result.stdout.fnmatch_lines([
        '*test_factorial*wish*SKIPPED',
    ])

    # make sure that that we get a '0' exit code for the testsuite
    assert result.ret == 0


def test_generate_tests(testdir):
    """Make sure that pytest accepts our fixture."""

    # create a temporary pytest test module
    testdir.makepyfile(TEST_FACTORIAL)

    # run pytest with the following cmd args
    result = testdir.runpytest(
        '--wish-modules=math',
        '-v',
    )

    # fnmatch_lines does an assertion internally
    result.stdout.fnmatch_lines([
        '*test_factorial*math:fabs*xfail',
        '*test_factorial*math:factorial*XPASS',
    ])

    # make sure that that we get a '0' exit code for the testsuite
    assert result.ret == 0


def test_generate_fail_tests(testdir):
    testdir.makepyfile(TEST_FACTORIAL)
    result = testdir.runpytest(
        '--wish-modules=math',
        '--wish-fail',
        '-v',
    )
    result.stdout.fnmatch_lines([
        '*test_factorial*math:fabs*FAILED',
        '*test_factorial*math:factorial*PASSED',
    ])
    assert result.ret == 1

add test for wish_fail and broader tests