Skip to content

Commit

Permalink
Merge from 3.x: PR #4880
Browse files Browse the repository at this point in the history
Fixes #4839
  • Loading branch information
ccordoba12 committed Aug 13, 2017
2 parents 539b471 + 6b464b3 commit 9474952
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
77 changes: 77 additions & 0 deletions spyder/widgets/projects/tests/test_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
"""
Tests for __init__.py.
"""

# Test library imports
import pytest
import os.path as osp

# Local imports
from spyder.widgets.projects import EmptyProject

from spyder.widgets.projects.config import (CODESTYLE, WORKSPACE, ENCODING,
VCS)


@pytest.fixture(scope='session')
def project_test(tmpdir_factory):
"""
Fixture for create a temporary project.
Returns:
project_dir: fixture of temporary project dir.
project: EmptyProject object.
"""
project_dir = tmpdir_factory.mktemp("test_project")
project = EmptyProject(str(project_dir))
return project_dir, project


def test_empty_project(project_test):
"""Test creation of anEmpy project, and its configuration files."""
project_dir, project = project_test
assert project.root_path == str(project_dir)

# Assert Project onfigs
conf_files = project.get_conf_files()
for dir_ in [CODESTYLE, WORKSPACE, ENCODING, VCS]:
assert dir_ in conf_files
project_config = conf_files[dir_]

# assert configurations files
assert osp.exists(project_config.filename())


def test_set_load_recent_files(project_test):
"""Test saving and loading files from the configuration.
Saving/loading should preserved the order, and remove duplicates.
"""
project_dir, project = project_test

# Create some files for testing
files_paths = []
for f in ['a.py', 'b.py', 'c.py']:
file_ = project_dir.join(f)
file_.write('# Some dummy content')
files_paths.append(str(file_))

# setting and loading
project.set_recent_files(files_paths[:])
assert project.get_recent_files() == files_paths

# adding a duplicate elemnent
files_paths_duplicate = files_paths + [files_paths[0]]
assert len(files_paths_duplicate) == len(files_paths) + 1

project.set_recent_files(files_paths_duplicate[:])
assert project.get_recent_files() == files_paths


if __name__ == "__main__":
pytest.main()
5 changes: 3 additions & 2 deletions spyder/widgets/projects/type/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os
import os.path as osp
from collections import OrderedDict

from spyder.config.base import _
from spyder.py3compat import to_text_string
Expand Down Expand Up @@ -70,7 +71,7 @@ def set_recent_files(self, recent_files):
if not os.path.isfile(recent_file):
recent_files.remove(recent_file)
self.CONF[WORKSPACE].set('main', 'recent_files',
list(set(recent_files)))
list(OrderedDict.fromkeys(recent_files)))

def get_recent_files(self):
"""Return a list of files opened by the project."""
Expand All @@ -79,7 +80,7 @@ def get_recent_files(self):
for recent_file in recent_files[:]:
if not os.path.isfile(recent_file):
recent_files.remove(recent_file)
return list(set(recent_files))
return list(OrderedDict.fromkeys(recent_files))

def create_project_config_files(self):
""" """
Expand Down

0 comments on commit 9474952

Please sign in to comment.