import pytest

from tests.pylint_plugins.utils import create_message, extract_node, skip_if_pylint_unavailable

pytestmark = skip_if_pylint_unavailable()


@pytest.fixture(scope="module")
def test_case():
    import pylint.testutils
    from pylint_plugins import AssertRaisesWithoutMsg

    class TestAssertRaisesWithoutMsg(pylint.testutils.CheckerTestCase):
        CHECKER_CLASS = AssertRaisesWithoutMsg

    test_case = TestAssertRaisesWithoutMsg()
    test_case.setup_method()
    return test_case


def test_assert_raises_without_msg(test_case):
    node = extract_node("self.assertRaises(Exception)")
    with test_case.assertAddsMessages(create_message(test_case.CHECKER_CLASS.name, node)):
        test_case.walk(node)

    node = extract_node("self.assertRaises(Exception, msg='test')")
    with test_case.assertNoMessages():
        test_case.walk(node)

    node = extract_node("pandas.assertRaises(Exception)")
    with test_case.assertNoMessages():
        test_case.walk(node)

[((5, 13, 5, 41), 'tests.pylint_plugins.utils.skip_if_pylint_unavailable', 'skip_if_pylint_unavailable', ({}, {}), '()', False, 'from tests.pylint_plugins.utils import create_message, extract_node, skip_if_pylint_unavailable\n'), ((8, 1, 8, 31), 'pytest.fixture', 'pytest.fixture', (), '', False, 'import pytest\n'), ((22, 11, 22, 55), 'tests.pylint_plugins.utils.extract_node', 'extract_node', ({(22, 24, 22, 54): '"""self.assertRaises(Exception)"""'}, {}), "('self.assertRaises(Exception)')", False, 'from tests.pylint_plugins.utils import create_message, extract_node, skip_if_pylint_unavailable\n'), ((26, 11, 26, 67), 'tests.pylint_plugins.utils.extract_node', 'extract_node', ({(26, 24, 26, 66): '"""self.assertRaises(Exception, msg=\'test\')"""'}, {}), '("self.assertRaises(Exception, msg=\'test\')")', False, 'from tests.pylint_plugins.utils import create_message, extract_node, skip_if_pylint_unavailable\n'), ((30, 11, 30, 57), 'tests.pylint_plugins.utils.extract_node', 'extract_node', ({(30, 24, 30, 56): '"""pandas.assertRaises(Exception)"""'}, {}), "('pandas.assertRaises(Exception)')", False, 'from tests.pylint_plugins.utils import create_message, extract_node, skip_if_pylint_unavailable\n'), ((23, 38, 23, 88), 'tests.pylint_plugins.utils.create_message', 'create_message', ({(23, 53, 23, 81): 'test_case.CHECKER_CLASS.name', (23, 83, 23, 87): 'node'}, {}), '(test_case.CHECKER_CLASS.name, node)', False, 'from tests.pylint_plugins.utils import create_message, extract_node, skip_if_pylint_unavailable\n')]