コード例 #1
0
ファイル: test_pylint.py プロジェクト: zhoufan766/spyder
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
ファイル: test_pylint.py プロジェクト: andfoy/spyder
def pylint_plugin(mocker, qtbot):
    main_window = MainWindowMock()
    main_window.projects.get_active_project_path = mocker.MagicMock(
        return_value=None)
    plugin = Pylint(parent=main_window, configuration=CONF)
    plugin._register()
    plugin.set_conf("history_filenames", [])
    widget = plugin.get_widget()
    widget.filecombo.clear()
    qtbot.addWidget(widget)
    yield plugin
コード例 #4
0
ファイル: test_pylint.py プロジェクト: zhoufan766/spyder
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
コード例 #5
0
ファイル: test_pylint.py プロジェクト: zhoufan766/spyder
def test_pylint_max_history_conf(pylint_test_scripts, mocker):
    """Regression test for checking max_entries configuration.

    For further information see spyder-ide/spyder#12884
    """
    # 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)
    pylint_widget.filecombo.clear()

    script_0, script_1, script_2 = pylint_test_scripts(
        ["test_script_{}.py".format(n) for n in range(3)])

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

    # Call to set_filename
    pylint_widget.set_filename(filename=script_0)
    assert pylint_widget.filecombo.count() == 1

    # Add to more filenames
    pylint_widget.set_filename(filename=script_1)
    pylint_widget.set_filename(filename=script_2)

    assert pylint_widget.filecombo.count() == 2

    assert 'test_script_2.py' in pylint_widget.curr_filenames[0]
    assert 'test_script_1.py' in pylint_widget.curr_filenames[1]

    # Change the max entry to 1
    pylint_widget.parent.set_option('max_entries', 1)
    pylint_widget.change_history_limit(1)

    assert pylint_widget.filecombo.count() == 1

    assert 'test_script_2.py' in pylint_widget.curr_filenames[0]