Repository: spyder-ide/spyder

Issue:
Cannot run static code analysis on Spyder 3.2.4
## Description

**What steps will reproduce the problem?**

1. Open Static code analysis
2. Open A python file
3. Press Analyze button

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

KeyError: None



## Version and main components

* Spyder Version: 3.2.4 
* Python Version: 2.7.14
* Qt Versions: 5.6.2, PyQt5 5.6 on Linux

## Dependencies
```
pyflakes >=0.5.0  :  1.6.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pygments >=2.0    :  2.2.0 (OK)
pandas >=0.13.1   :  0.20.3 (OK)
numpy >=1.7       :  1.11.3 (OK)
sphinx >=0.6.6    :  1.6.3 (OK)
rope >=0.9.4      :  0.10.5 (OK)
jedi >=0.9.0      :  0.10.2 (OK)
psutil >=0.3      :  5.4.0 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  None (NOK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0;<6.0:  5.4.1 (OK)
pylint >=0.25     :  1.7.4 (OK)

```



Discussion:
@dalthviz, please take a look at this one.
This is related to #4922, although the validation is working well, It isn't called at startup (the issue only happens when opening the plugin, and not when editing the filename)

I think is enough to move the rdata loading to the end of the `__init__`, and disable the button if not rdata is found:
https://github.com/spyder-ide/spyder/blob/master/spyder_pylint/widgets/pylintgui.py#L172
```
if self.rdata:
    self.remove_obsolete_items()
    self.filecombo.addItems(self.get_filenames())
else:
    self.start_button.setEnabled(False)
```

Resolving patch:
diff --git a/spyder_pylint/widgets/pylintgui.py b/spyder_pylint/widgets/pylintgui.py
--- a/spyder_pylint/widgets/pylintgui.py
+++ b/spyder_pylint/widgets/pylintgui.py
@@ -167,9 +167,6 @@ def __init__(self, parent, max_entries=100):
                 pass
 
         self.filecombo = PythonModulesComboBox(self)
-        if self.rdata:
-            self.remove_obsolete_items()
-            self.filecombo.addItems(self.get_filenames())
         
         self.start_button = create_toolbutton(self, icon=ima.icon('run'),
                                     text=_("Analyze"),
@@ -218,7 +215,13 @@ def __init__(self, parent, max_entries=100):
         self.process = None
         self.set_running_state(False)
         self.show_data()
-        
+
+        if self.rdata:
+            self.remove_obsolete_items()
+            self.filecombo.addItems(self.get_filenames())
+        else:
+            self.start_button.setEnabled(False)
+
     def analyze(self, filename):
         filename = to_text_string(filename) # filename is a QString instance
         self.kill_if_running()


Test patch:
diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py
--- a/spyder/app/tests/test_mainwindow.py
+++ b/spyder/app/tests/test_mainwindow.py
@@ -71,6 +71,11 @@ def open_file_in_editor(main_window, fname, directory=None):
             input_field.setText(fname)
             QTest.keyClick(w, Qt.Key_Enter)
 
+def get_thirdparty_plugin(main_window, plugin_title):
+    """Get a reference to the thirdparty plugin with the title given."""
+    for plugin in main_window.thirdparty_plugins:
+        if plugin.get_plugin_title() == plugin_title:
+            return plugin
 
 def reset_run_code(qtbot, shell, code_editor, nsb):
     """Reset state after a run code test"""
@@ -1087,5 +1092,37 @@ def test_fileswitcher(main_window, qtbot):
        assert '...' in item_text
 
 
+@flaky(max_runs=3)
+@pytest.mark.skipif(not PYQT5, reason="It times out.")
+def test_run_static_code_analysis(main_window, qtbot):
+    """This tests that the Pylint plugin is working as expected."""
+    # Wait until the window is fully up
+    shell = main_window.ipyconsole.get_current_shellwidget()
+    qtbot.waitUntil(lambda: shell._prompt_html is not None,
+                    timeout=SHELL_TIMEOUT)
+
+    # Select the third-party plugin
+    pylint = get_thirdparty_plugin(main_window, "Static code analysis")
+
+    # Do an analysis
+    test_file = osp.join(LOCATION, 'script.py')
+    main_window.editor.load(test_file)
+    code_editor = main_window.editor.get_focus_widget()
+    qtbot.keyClick(code_editor, Qt.Key_F8)
+    qtbot.wait(500)
+
+    # Perform the test
+    # Check output of the analysis
+    treewidget = pylint.get_focus_widget()
+    qtbot.waitUntil(lambda: treewidget.results is not None,
+                    timeout=SHELL_TIMEOUT)
+    result_content = treewidget.results
+    assert result_content['C:']
+    assert len(result_content['C:']) == 5
+
+    # Close the file
+    main_window.editor.close_file()
+
+
 if __name__ == "__main__":
     pytest.main()