示例#1
0
def test_pylint_widget_pylintrc(
        pylint_test_script, pylintrc_files, mocker, qtbot):
    """Test that entire pylint widget gets results depending on pylintrc."""
    search_paths, __, bad_names = pylintrc_files
    mocker.patch("pylint.config.os.path.expanduser",
                 return_value=search_paths[HOME_DIR])
    mocker.patch("spyder.plugins.pylint.widgets.pylintgui.getcwd_or_home",
                 return_value=search_paths[WORKING_DIR])
    mocker.patch("spyder.plugins.pylint.widgets.pylintgui.osp.expanduser",
                 return_value=search_paths[HOME_DIR])
    main_window = MainWindowMock()
    main_window.projects.get_active_project_path = mocker.MagicMock(
        return_value=search_paths[PROJECT_DIR])
    pylint_sw = Pylint(parent=main_window)

    pylint_widget = PylintWidget(parent=pylint_sw)
    pylint_widget.analyze(filename=pylint_test_script)
    qtbot.waitUntil(
        lambda: pylint_widget.get_data(pylint_test_script)[1] is not None,
        timeout=5000)
    pylint_data = pylint_widget.get_data(filename=pylint_test_script)
    print(pylint_data)
    assert pylint_data
    conventions = pylint_data[1][3]["C:"]
    assert conventions
    assert len(conventions) == len(bad_names)
    assert all([sum([bad_name in message[2] for message in conventions]) == 1
                for bad_name in bad_names])
示例#2
0
def test_pylint_max_history_conf(pylint_test_script, mocker, qtbot):
    """Regression test for checking max_entries configuration.

    For further information see spyder-ide/spyder#12874
    """
    # Create the pylint widget for code analysis
    main_window = MainWindowMock()
    main_window.projects.get_active_project_path = mocker.MagicMock(
        return_value=None)
    pylint_sw = Pylint(parent=main_window)
    pylint_widget = PylintWidget(parent=pylint_sw)

    # Change the max_entry to 2
    pylint_widget.parent.set_option('max_entries', 2)
    assert pylint_widget.parent.get_option('max_entries') == 2

    # Analyze the test script with 1 as max_entry
    pylint_widget.analyze(filename=pylint_test_script)
    qtbot.waitUntil(
        lambda: pylint_widget.get_data(pylint_test_script)[1] is not None,
        timeout=5000)
    pylint_data = pylint_widget.get_data(filename=pylint_test_script)
    results = pylint_data[1][-1]

    max_entries = pylint_widget.parent.get_option('max_entries')
    for key in results:
        assert len(results[key]) <= max_entries
示例#3
0
def test_pylint_widget_noproject(pylint_test_script, qtbot):
    """Test that pylint works without errors with no project open."""
    pylint_widget = PylintWidget(parent=None)
    pylint_widget.analyze(filename=pylint_test_script)
    qtbot.waitUntil(
        lambda: pylint_widget.get_data(pylint_test_script)[1] is not None,
        timeout=5000)
    pylint_data = pylint_widget.get_data(filename=pylint_test_script)
    print(pylint_data)
    assert pylint_data
    assert pylint_data[0] is not None
    assert pylint_data[1] is not None
示例#4
0
def test_pylint_widget_noproject(pylint_test_script, mocker, qtbot):
    """Test that pylint works without errors with no project open."""
    main_window = MainWindowMock()
    main_window.projects.get_active_project_path = mocker.MagicMock(
        return_value=None)
    pylint_sw = Pylint(parent=main_window)
    pylint_widget = PylintWidget(parent=pylint_sw)
    pylint_widget.analyze(filename=pylint_test_script)
    qtbot.waitUntil(
        lambda: pylint_widget.get_data(pylint_test_script)[1] is not None,
        timeout=5000)
    pylint_data = pylint_widget.get_data(filename=pylint_test_script)
    print(pylint_data)
    assert pylint_data
    assert pylint_data[0] is not None
    assert pylint_data[1] is not None