<commit_before>import pytest


pytest_plugins = ("pytester",)


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_passing_expect(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest

        def test_func():
            {assume.format(
                expr="1==1",
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(1, 0, 0)
    assert "1 passed" in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_failing_expect(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr="1==2",
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "1 Failed Assumptions" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_multi_pass_one_failing_expect(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr='"xyz" in "abcdefghijklmnopqrstuvwxyz"',
                msg=None
            )}
            {assume.format(
                expr="2==2",
                msg=None,
            )}
            {assume.format(
                expr="1==2",
                msg=None,
            )}
            {assume.format(
                expr='"xyz" in "abcd"',
                msg=None,
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "2 Failed Assumptions" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_passing_expect_doesnt_cloak_assert(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr='1==1',
                msg=None
            )}
            assert 1 == 2
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "AssertionError" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_failing_expect_doesnt_cloak_assert(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr='1==2',
                msg=None
            )}
            assert 1 == 2
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "AssertionError" in result.stdout.str()
    assert "1 Failed Assumptions" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_failing_expect_doesnt_cloak_assert_withrepr(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg=None
            )}
            assert a == b
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "AssertionError" in result.stdout.str()
    assert "1 Failed Assumptions:" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_msg_is_in_output(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg='"a:%s b:%s" % (a,b)'
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "1 Failed Assumptions" in result.stdout.str()
    assert "a:1 b:2" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_with_locals(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess("--showlocals")
    result.assert_outcomes(0, 0, 1)
    stdout = result.stdout.str()
    assert "1 failed" in stdout
    assert "1 Failed Assumptions" in stdout
    assert "a          = 1" in stdout
    assert "b          = 2" in stdout
    assert "pytest_pyfunc_call" not in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_without_locals(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    stdout = result.stdout.str()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in stdout
    assert "1 Failed Assumptions" in stdout
    assert "a          = 1" not in stdout
    assert "b          = 2" not in stdout


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_xfail_assumption(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        @pytest.mark.xfail(run=True, reason="testfail")
        def test_func():
            {assume.format(
                expr='1==2',
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess("-rxs")
    stdout = result.stdout.str()
    outcomes = result.parseoutcomes()
    assert outcomes.get("xfailed", 0) == 1
    assert "testfail" in stdout


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_xpass_assumption(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        @pytest.mark.xfail(run=True, reason="testfail")
        def test_func():
            {assume.format(
                expr=True,
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    outcomes = result.parseoutcomes()
    assert outcomes.get("xpassed", 0) == 1


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_bytecode(testdir, assume):
    testdir.makepyfile(
        b"""
        import pytest

        def test_func():
            pytest.assume(b"\x01" == b"\x5b")
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_unicode(testdir, assume):
    testdir.makepyfile(
        """
        import pytest

        def test_func():
            pytest.assume(u"\x5b" == u"\x5a")
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_mixed_stringtypes(testdir, assume):
    testdir.makepyfile(
        """
        import pytest

        def test_func():
            pytest.assume(b"\x5b" == u"\x5a")
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()


@pytest.mark.parametrize("assume", ["pytest.assume({expr}, {msg})", "with pytest.assume: assert {expr}, {msg}"])
def test_with_tb(testdir, assume):
    testdir.makepyfile(
        f"""<commit_msg>Refactored test parametrization to a fixture.<commit_after>import pytest


pytest_plugins = ("pytester",)


@pytest.fixture(scope="module", params=[
    "pytest.assume({expr}, {msg})",
    "with pytest.assume: assert {expr}, {msg}"
])
def assume(request):
    return request.param


def test_passing_expect(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest

        def test_func():
            {assume.format(
                expr="1==1",
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(1, 0, 0)
    assert "1 passed" in result.stdout.str()


def test_failing_expect(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr="1==2",
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "1 Failed Assumptions" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


def test_multi_pass_one_failing_expect(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr='"xyz" in "abcdefghijklmnopqrstuvwxyz"',
                msg=None
            )}
            {assume.format(
                expr="2==2",
                msg=None,
            )}
            {assume.format(
                expr="1==2",
                msg=None,
            )}
            {assume.format(
                expr='"xyz" in "abcd"',
                msg=None,
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "2 Failed Assumptions" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


def test_passing_expect_doesnt_cloak_assert(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr='1==1',
                msg=None
            )}
            assert 1 == 2
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "AssertionError" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


def test_failing_expect_doesnt_cloak_assert(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            {assume.format(
                expr='1==2',
                msg=None
            )}
            assert 1 == 2
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "AssertionError" in result.stdout.str()
    assert "1 Failed Assumptions" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


def test_failing_expect_doesnt_cloak_assert_withrepr(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg=None
            )}
            assert a == b
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "AssertionError" in result.stdout.str()
    assert "1 Failed Assumptions:" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


def test_msg_is_in_output(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg='"a:%s b:%s" % (a,b)'
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()
    assert "1 Failed Assumptions" in result.stdout.str()
    assert "a:1 b:2" in result.stdout.str()
    assert "pytest_pyfunc_call" not in result.stdout.str()


def test_with_locals(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess("--showlocals")
    result.assert_outcomes(0, 0, 1)
    stdout = result.stdout.str()
    assert "1 failed" in stdout
    assert "1 Failed Assumptions" in stdout
    assert "a          = 1" in stdout
    assert "b          = 2" in stdout
    assert "pytest_pyfunc_call" not in result.stdout.str()


def test_without_locals(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        def test_func():
            a = 1
            b = 2
            {assume.format(
                expr='a==b',
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    stdout = result.stdout.str()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in stdout
    assert "1 Failed Assumptions" in stdout
    assert "a          = 1" not in stdout
    assert "b          = 2" not in stdout


def test_xfail_assumption(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        @pytest.mark.xfail(run=True, reason="testfail")
        def test_func():
            {assume.format(
                expr='1==2',
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess("-rxs")
    stdout = result.stdout.str()
    outcomes = result.parseoutcomes()
    assert outcomes.get("xfailed", 0) == 1
    assert "testfail" in stdout


def test_xpass_assumption(testdir, assume):
    testdir.makepyfile(
        f"""
        import pytest
        @pytest.mark.xfail(run=True, reason="testfail")
        def test_func():
            {assume.format(
                expr=True,
                msg=None
            )}
        """
    )
    result = testdir.runpytest_inprocess()
    outcomes = result.parseoutcomes()
    assert outcomes.get("xpassed", 0) == 1


def test_bytecode(testdir, assume):
    testdir.makepyfile(
        b"""
        import pytest

        def test_func():
            pytest.assume(b"\x01" == b"\x5b")
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()


def test_unicode(testdir, assume):
    testdir.makepyfile(
        """
        import pytest

        def test_func():
            pytest.assume(u"\x5b" == u"\x5a")
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()


def test_mixed_stringtypes(testdir, assume):
    testdir.makepyfile(
        """
        import pytest

        def test_func():
            pytest.assume(b"\x5b" == u"\x5a")
        """
    )
    result = testdir.runpytest_inprocess()
    result.assert_outcomes(0, 0, 1)
    assert "1 failed" in result.stdout.str()


def test_with_tb(testdir, assume):
    testdir.makepyfile(
        f"""
{'fraction_non_alphanumeric': 0.13279132791327913, 'fraction_numerical': 0.012071938901207195, 'mean_word_length': 2.0197135949414173, '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': '6304034', 'n_tokens_mistral': 5497, 'n_tokens_neox': 5373, 'n_words': 1093}