Skip to content

Commit

Permalink
Merge pull request #8686 from ccordoba12/backport-8452
Browse files Browse the repository at this point in the history
PR: Backport PR 8452
  • Loading branch information
ccordoba12 authored Feb 2, 2019
2 parents 6a97e3f + f598e5b commit 35ad7f5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
16 changes: 7 additions & 9 deletions spyder/plugins/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def switch_to_plugin(self):
self.toggle_view_action.setChecked(True)
self.visibility_changed(True)

#------ Public API ---------------------------------------------------------
# ------ Public API -------------------------------------------------------
def setup_menu_actions(self):
"""Setup and update the menu actions."""
self.recent_project_menu.clear()
Expand All @@ -188,15 +188,13 @@ def setup_menu_actions(self):
for project in self.recent_projects:
if self.is_valid_project(project):
name = project.replace(get_home_dir(), '~')

def slot():
self.switch_to_plugin()
self.open_project(path=project)

action = create_action(self,
action = create_action(
self,
name,
icon = ima.icon('project'),
triggered=slot)
icon=ima.icon('project'),
triggered=(
lambda _, p=project: self.open_project(path=p))
)
self.recent_projects_actions.append(action)
else:
self.recent_projects.remove(project)
Expand Down
30 changes: 30 additions & 0 deletions spyder/plugins/tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,35 @@ def test_open_project_uses_visible_config(projects, tmpdir, value):
assert projects.dockwidget.isVisible() == value


def test_recent_projects_menu_action(projects, tmpdir):
"""
Test that the actions of the submenu 'Recent Projects' in the 'Projects'
main menu are working as expected.
Regression test for Issue #8450.
"""
recent_projects_len = len(projects.recent_projects)

# Create the directories.
path0 = to_text_string(tmpdir.mkdir('project0'))
path1 = to_text_string(tmpdir.mkdir('project1'))
path2 = to_text_string(tmpdir.mkdir('project2'))

# Open projects in path0, path1, and path2.
projects.open_project(path=path0)
projects.open_project(path=path1)
projects.open_project(path=path2)
assert (len(projects.recent_projects_actions) ==
recent_projects_len + 3 + 2)
assert projects.get_active_project().root_path == path2

# Trigger project1 in the list of Recent Projects actions.
projects.recent_projects_actions[1].trigger()
assert projects.get_active_project().root_path == path1

# Trigger project0 in the list of Recent Projects actions.
projects.recent_projects_actions[2].trigger()
assert projects.get_active_project().root_path == path0


if __name__ == "__main__":
pytest.main()

0 comments on commit 35ad7f5

Please sign in to comment.