Commits

Ali Gholami Rudi  committed 495804b

Adding Project.close()
Adding testutils.sample_project() and testutils.remove_project()

  • Participants
  • Parent commits b499c8d

Comments (0)

Files changed (24)

File docs/dev/issues.txt

 * Should every unknown be calculated everytime?
 * When to forget old results?
 * Returning a `Generator` for generator functions with unknown return type?
-* Changing `callinfo` to match not exactly the same but similar args
-* Using `sqlite3` to prevent holding information in memory? mocks?
-* Saving `AbstractXxx`
+* Changing `callinfo` to match similar args
+* Saving `AbstractXxx`\s
 * Better per name data holding in `callinfo`
 * Not overwriting useful per object data in `callinfo`
 * Some `self`\s are unknown!
 information and testing.
 
 
-An Implementation Proposal
---------------------------
+Using `shelve` For `_DiskObjectDB`
+----------------------------------
 
 We probably have to extend the information we hold for each individual
 call info.::
 * What to do with per name information
 * The values are very long; shelve might fail
 * The pickling might be very inefficient
+* More than one rope on a project
 
-The most complex part is when to invalidate data.  Before going on we
-should keep in mind that whatever we do is only an approaximation and
-does not solve all problems.  That is mainly because even when no
-resource changes it is possible that by running SOI multiple times
-better data might be calculated and we can not know that.  But at
-least we know that a good call info remains valid as long as no
-resource gets changed.
+
+Using `sqlite3`
+---------------
+
+Scope:
+
+=========  ========
+path       key
+=========  ========
+=========  ========
+
+
+Call info:
+
+==========  ======  ==========
+scope fk    args    returned
+==========  ======  ==========
+==========  ======  ==========
+
+
+Per name:
+
+==========  ======  ==========
+scope fk    name    value
+==========  ======  ==========
+==========  ======  ==========
 
 
 Better Concluded Data

File docs/dev/workingon.txt

 Moving CallInfo To Disk
 =======================
 
-- Adding ``Edit Project Config`` action
-- Added ``DiskObjectDB``
+- Adding `Project.close()`
+- `testutils.sample_project()` and `testutils.remove_project()`
+- Calling `Project.close()` in all tests
 
-* Adding `Project.close()` to sync `objectdb`
-* Renaming `Project.close()` to `sync()` or we should change all tests
-* Adding `testutils.get_sample_dir()` to use ``/dev/shm``
+* Documenting `Project.close()`
+* Use ``/dev/shm/sample_project`` as project root for faster testing?
 * Adding ``use_memory_db`` config
 * Adding clear objectdb command
 * Multiple ropes on one project; problems for objectdb

File rope/base/oi/callinfo.py

-import compiler.consts
 import os
 import re
 import shelve
         if path not in self.cache:
             if path not in self.index:
                 # TODO: Use better and shorter names
-                self.index[path] = path.replace('/', '$')
+                self.index[path] = os.path.basename(path) + \
+                                   str(hash(path)) + '.shelve'
             name = self.index[path]
             resource = self.project.get_file(self.root.path + '/' + name)
             if not create and not resource.exists():

File ropetest/builtintest.py

 import unittest
 
-import rope.base.project
-import ropetest
 from rope.base import pyobjects, builtins
+from ropetest import testutils
 
 
 class BuiltinTypesTest(unittest.TestCase):
 
     def setUp(self):
         super(BuiltinTypesTest, self).setUp()
-        ropetest.testutils.remove_recursively(self.project_root)
-        self.project = rope.base.project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
 
-    project_root = 'sample_project'
-
     def tearDown(self):
-        ropetest.testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(BuiltinTypesTest, self).tearDown()
 
     def test_simple_case(self):
         self.mod.write('for line in open("file.txt"):\n    a_var = line\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         a_var = pymod.get_attribute('a_var').get_object()
-        self.assertTrue(isinstance(a_var.get_type(), rope.base.builtins.Str))
+        self.assertTrue(isinstance(a_var.get_type(), builtins.Str))
 
     def test_file_builtin_type2(self):
         self.mod.write('p = property()\n')

File ropetest/codeanalyzetest.py

                                    SourceLinesAdapter, WordRangeFinder,
                                    ScopeNameFinder, LogicalLineFinder,
                                    get_block_start)
-from rope.base.project import Project
 from ropetest import testutils
 
 
 
     def setUp(self):
         super(ScopeNameFinderTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(ScopeNameFinderTest, self).tearDown()
 
     # FIXME: in normal scopes the interpreter raises `UnboundLocalName`

File ropetest/historytest.py

 import unittest
 
 import rope.base.history
-from rope.base import exceptions, project
+from rope.base import exceptions
 from rope.base.change import *
 from ropetest import testutils
 
 
     def setUp(self):
         super(HistoryTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.history = self.project.history
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(HistoryTest, self).tearDown()
 
     def test_undoing_writes(self):
 
     def setUp(self):
         super(IsolatedHistoryTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.history = rope.base.history.History()
         self.file1 = self.project.root.create_file('file1.txt')
         self.file2 = self.project.root.create_file('file2.txt')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(IsolatedHistoryTest, self).tearDown()
 
     def test_simple_undo(self):

File ropetest/ide/codeassisttest.py

-import os
 import unittest
 
-from rope.base.project import Project
-from rope.ide.codeassist import PythonCodeAssist, RopeSyntaxError, Template, ProposalSorter
+from rope.ide.codeassist import (PythonCodeAssist, RopeSyntaxError,
+                                 Template, ProposalSorter)
 from ropetest import testutils
 
 
 
     def setUp(self):
         super(CodeAssistTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        os.mkdir(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.assist = PythonCodeAssist(self.project)
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(CodeAssistTest, self).tearDown()
 
     def test_simple_assist(self):
 
     def setUp(self):
         super(CodeAssistInProjectsTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        os.mkdir(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.assist = PythonCodeAssist(self.project)
         self.pycore = self.project.get_pycore()
         samplemod = self.pycore.create_module(self.project.root, 'samplemod')
                 self.fail('completion <%s> was proposed' % name)
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(self.__class__, self).tearDown()
 
     def test_simple_import(self):

File ropetest/ide/generatetest.py

 import unittest
 
-import rope.base.project
 from rope.base import exceptions
+from rope.ide import generate
 from ropetest import testutils
-from rope.ide import generate
 
 
 class GenerateTest(unittest.TestCase):
 
     def setUp(self):
         super(GenerateTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = rope.base.project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod1')
         self.mod2 = self.pycore.create_module(self.project.root, 'mod2')
         self.pkg = self.pycore.create_package(self.project.root, 'pkg')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(GenerateTest, self).tearDown()
 
     def _get_generate(self, offset):

File ropetest/ide/notestest.py

 import unittest
 
-from rope.base.project import Project
 from rope.ide import notes
 from ropetest import testutils
 
 
     def setUp(self):
         super(AnnotationsTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.tags = notes.Codetags()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(AnnotationsTest, self).tearDown()
 
     def test_tags_empty_input(self):

File ropetest/ide/outlinetest.py

-import os
 import unittest
 
-from rope.base.project import Project
 from rope.ide.outline import PythonOutline
 from ropetest import testutils
 
 
     def setUp(self):
         super(OutlineTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        os.mkdir(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.outline = PythonOutline(self.project)
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(OutlineTest, self).tearDown()
 
     def test_simple_outline(self):

File ropetest/objectinfertest.py

 import unittest
 
-from rope.base.project import Project
-import rope.base.builtins
+import rope.base.project
+from rope.base import builtins
 from rope.base.oi import callinfo
 from ropetest import testutils
 
 
     def setUp(self):
         super(ObjectInferTest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(ObjectInferTest, self).tearDown()
 
     def test_simple_type_inferencing(self):
                   'for s in f():\n    a_var = s\n')
         pymod = self.pycore.resource_to_pyobject(mod)
         a_var = pymod.get_attribute('a_var').get_object()
-        self.assertTrue(isinstance(a_var.get_type(), rope.base.builtins.Str))
+        self.assertTrue(isinstance(a_var.get_type(), builtins.Str))
 
     def test_considering_nones_to_be_unknowns(self):
         mod = self.pycore.get_string_module(
 
     def setUp(self):
         super(NewStaticOITest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(NewStaticOITest, self).tearDown()
 
     def test_static_oi_for_simple_function_calls(self):
         pymod = self.pycore.resource_to_pyobject(self.mod)
         a_var = pymod.get_attribute('a_var').get_object()
         self.assertTrue(isinstance(a_var.get_type(),
-                                   rope.base.builtins.Generator))
+                                   builtins.Generator))
 
     def test_static_oi_for_lists_depending_on_append_function(self):
         code = 'class C(object):\n    pass\nl = list()\n' \
 
     def setUp(self):
         super(DynamicOITest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(DynamicOITest, self).tearDown()
 
     def test_simple_dti(self):
         self.pycore.run_module(mod).wait_process()
         pymod = self.pycore.resource_to_pyobject(mod)
         a_var = pymod.get_attribute('a_var').get_object()
-        self.assertTrue(isinstance(a_var.get_type(), rope.base.builtins.Str))
+        self.assertTrue(isinstance(a_var.get_type(), builtins.Str))
 
     def test_textual_transformations(self):
         mod = self.pycore.create_module(self.project.root, 'mod')
             var = pymod.get_attribute(name).get_object()
             self.assertEquals(to_textual.transform(var), complex_to_textual(var))
         self.assertEquals(to_textual.transform(pymod), complex_to_textual(pymod))
-        enumerate_func = rope.base.builtins.builtins['enumerate'].get_object()
+        enumerate_func = builtins.builtins['enumerate'].get_object()
         self.assertEquals(to_textual.transform(enumerate_func),
                           complex_to_textual(enumerate_func))
 

File ropetest/projecttest.py

         sample.close()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         unittest.TestCase.tearDown(self)
 
     def test_project_creation(self):
         self.fail('Should have failed')
 
     def test_making_root_folder_if_it_does_not_exist(self):
-        projectRoot = 'SampleProject2'
+        project_root = 'SampleProject2'
         try:
-            project = Project(projectRoot)
-            self.assertTrue(os.path.exists(projectRoot) and os.path.isdir(projectRoot))
+            project = Project(project_root)
+            self.assertTrue(os.path.exists(project_root) and os.path.isdir(project_root))
         finally:
-            testutils.remove_recursively(projectRoot)
+            testutils.remove_recursively(project_root)
 
     @testutils.assert_raises(RopeError)
     def test_failure_when_project_root_exists_and_is_a_file(self):
         try:
-            projectRoot = 'SampleProject2'
-            open(projectRoot, 'w').close()
-            project = Project(projectRoot)
+            project_root = 'SampleProject2'
+            open(project_root, 'w').close()
+            project = Project(project_root)
         finally:
-            os.remove(projectRoot)
+            os.remove(project_root)
 
     def test_creating_folders(self):
         folderName = 'SampleFolder'
 
     def setUp(self):
         super(ResourceObserverTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(ResourceObserverTest, self).tearDown()
 
     def test_resource_change_observer(self):
 
     def setUp(self):
         super(OutOfProjectTest, self).setUp()
-        self.project_root = 'sample_project'
         self.test_directory = 'temp_test_directory'
-        testutils.remove_recursively(self.project_root)
         testutils.remove_recursively(self.test_directory)
         os.mkdir(self.test_directory)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.no_project = NoProject()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         testutils.remove_recursively(self.test_directory)
         super(OutOfProjectTest, self).tearDown()
 
 
     def setUp(self):
         super(RopeFolderTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
+        self.project = None
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        if self.project:
+            testutils.remove_project(self.project)
         super(RopeFolderTest, self).tearDown()
 
     def test_none_project_rope_folder(self):
-        project = Project(self.project_root, ropefolder=None)
-        self.assertTrue(project.ropefolder is None)
+        self.project = testutils.sample_project(ropefolder=None)
+        self.assertTrue(self.project.ropefolder is None)
 
     def test_getting_project_rope_folder(self):
-        project = Project(self.project_root, ropefolder='.ropeproject')
-        self.assertTrue(project.ropefolder.exists())
-        self.assertTrue('.ropeproject', project.ropefolder.path)
+        self.project = testutils.sample_project(ropefolder='.ropeproject')
+        self.assertTrue(self.project.ropefolder.exists())
+        self.assertTrue('.ropeproject', self.project.ropefolder.path)
 
     def test_setting_ignored_resources(self):
-        project = Project(self.project_root)
-        project.set_ignored_resources(['myfile.txt'])
-        myfile = project.get_file('myfile.txt')
-        file2 = project.get_file('file2.txt')
-        self.assertTrue(project.is_ignored(myfile))
-        self.assertFalse(project.is_ignored(file2))
+        self.project = testutils.sample_project()
+        self.project.set_ignored_resources(['myfile.txt'])
+        myfile = self.project.get_file('myfile.txt')
+        file2 = self.project.get_file('file2.txt')
+        self.assertTrue(self.project.is_ignored(myfile))
+        self.assertFalse(self.project.is_ignored(file2))
 
     def test_ignored_folders(self):
-        project = Project(self.project_root)
-        project.set_ignored_resources(['myfolder'])
-        myfolder = project.root.create_folder('myfolder')
-        self.assertTrue(project.is_ignored(myfolder))
+        self.project = testutils.sample_project()
+        self.project.set_ignored_resources(['myfolder'])
+        myfolder = self.project.root.create_folder('myfolder')
+        self.assertTrue(self.project.is_ignored(myfolder))
         myfile = myfolder.create_file('myfile.txt')
-        self.assertTrue(project.is_ignored(myfile))
+        self.assertTrue(self.project.is_ignored(myfile))
 
     def test_setting_ignored_resources_patterns(self):
-        project = Project(self.project_root)
-        project.set_ignored_resources(['m?file.*'])
-        myfile = project.get_file('myfile.txt')
-        file2 = project.get_file('file2.txt')
-        self.assertTrue(project.is_ignored(myfile))
-        self.assertFalse(project.is_ignored(file2))
+        self.project = testutils.sample_project()
+        self.project.set_ignored_resources(['m?file.*'])
+        myfile = self.project.get_file('myfile.txt')
+        file2 = self.project.get_file('file2.txt')
+        self.assertTrue(self.project.is_ignored(myfile))
+        self.assertFalse(self.project.is_ignored(file2))
 
     def test_normal_fscommands(self):
         fscommands = _MockFSCommands()
-        project = Project(self.project_root, fscommands=fscommands)
-        myfile = project.get_file('myfile.txt')
+        self.project = testutils.sample_project(fscommands=fscommands)
+        myfile = self.project.get_file('myfile.txt')
         myfile.create()
         self.assertTrue('create_file ', fscommands.log)
 
     def test_fscommands_and_ignored_resources(self):
         fscommands = _MockFSCommands()
-        project = Project(self.project_root, fscommands=fscommands)
-        project.set_ignored_resources(['myfile.txt'])
-        myfile = project.get_file('myfile.txt')
+        self.project = testutils.sample_project(fscommands=fscommands)
+        self.project.set_ignored_resources(['myfile.txt'])
+        myfile = self.project.get_file('myfile.txt')
         myfile.create()
         self.assertEquals('', fscommands.log)
 
     def test_loading_config_dot_py(self):
-        project = Project(self.project_root, ropefolder='.ropeproject')
-        config = project.get_file('.ropeproject/config.py')
+        self.project = testutils.sample_project(ropefolder='.ropeproject')
+        config = self.project.get_file('.ropeproject/config.py')
         if not config.exists():
             config.create()
         config.write('def opening_project(project):\n'
                      '    project.root.create_file("loaded")\n')
-        project = Project(self.project_root, ropefolder='.ropeproject')
-        self.assertTrue(project.get_file('loaded').exists())
+        self.project.close()
+        self.project = Project(self.project.address, ropefolder='.ropeproject')
+        self.assertTrue(self.project.get_file('loaded').exists())
 
 
 def suite():

File ropetest/pycoretest.py

-import os
 import sys
 import unittest
 
-from rope.base.project import Project
 from rope.base.pycore import ModuleNotFoundError
 from rope.base.pyobjects import get_base_type
 from ropetest import testutils
 
     def setUp(self):
         super(PyCoreTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(PyCoreTest, self).tearDown()
 
     def test_simple_module(self):
 
     def setUp(self):
         super(self.__class__, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        os.mkdir(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         samplemod = self.pycore.create_module(self.project.root, 'samplemod')
         samplemod.write("class SampleClass(object):\n    def sample_method():\n        pass" + \
         nestedmod = self.pycore.create_module(package, 'nestedmod')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(self.__class__, self).tearDown()
 
     def test_simple_import(self):
 
     def setUp(self):
         super(ClassHierarchyTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(ClassHierarchyTest, self).tearDown()
 
     def test_empty_get_superclasses(self):

File ropetest/pyscopestest.py

 import unittest
 
-from rope.base.project import Project
 from rope.base.pyobjects import get_base_type
 from ropetest import testutils
 
 
     def setUp(self):
         super(PyCoreScopesTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(PyCoreScopesTest, self).tearDown()
 
     def test_simple_scope(self):

File ropetest/refactor/__init__.py

 import ropetest.refactor.movetest
 import ropetest.refactor.renametest
 from rope.base.exceptions import RefactoringError
-from rope.base.project import Project
 from rope.refactor.encapsulate_field import EncapsulateField
 from rope.refactor.introduce_factory import IntroduceFactoryRefactoring
 from rope.refactor.localtofield import LocalToField
 
     def setUp(self):
         super(MethodObjectTest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(MethodObjectTest, self).tearDown()
 
     def test_empty_method(self):
 
     def setUp(self):
         super(IntroduceFactoryTest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(IntroduceFactoryTest, self).tearDown()
 
     def _introduce_factory(self, resource, offset, factory_name,
 
     def setUp(self):
         super(EncapsulateFieldTest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
         self.mod1 = self.pycore.create_module(self.project.root, 'mod1')
                             '    def set_attr(self, value):\n        self.attr = value\n'
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(EncapsulateFieldTest, self).tearDown()
 
     def _perform_encapsulate_field(self, resource, offset):
 
     def setUp(self):
         super(LocalToFieldTest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(LocalToFieldTest, self).tearDown()
 
     def _perform_convert_local_variable_to_field(self, resource, offset):
 
     def setUp(self):
         super(IntroduceParameterTest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(IntroduceParameterTest, self).tearDown()
 
     def _introduce_parameter(self, offset, name):

File ropetest/refactor/change_signature_test.py

 import unittest
 
 import rope.base.exceptions
-import rope.base.project
 from rope.refactor import change_signature
 from rope.refactor.change_signature import ChangeSignature
 from ropetest import testutils
 
     def setUp(self):
         super(ChangeSignatureTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = rope.base.project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(ChangeSignatureTest, self).tearDown()
 
     def test_normalizing_parameters_for_trivial_case(self):

File ropetest/refactor/extracttest.py

 
 import rope.base.codeanalyze
 import rope.base.exceptions
-import rope.base.project
 import ropetest.testutils as testutils
 from rope.refactor import extract
 
 
     def setUp(self):
         super(ExtractMethodTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = rope.base.project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(ExtractMethodTest, self).tearDown()
 
     def do_extract_method(self, source_code, start, end, extracted):

File ropetest/refactor/importutilstest.py

 import unittest
 
-from rope.base.project import Project
 from rope.refactor.importutils import ImportTools
 from ropetest import testutils
 
 
     def setUp(self):
         super(ImportUtilsTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.import_tools = ImportTools(self.pycore)
 
         m1 = self.pycore.create_module(p3, 'm1')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(ImportUtilsTest, self).tearDown()
 
     def test_get_import_for_module(self):

File ropetest/refactor/inlinetest.py

 import unittest
 
 import rope.base.exceptions
-import rope.base.project
 from rope.refactor.inline import Inline
 from ropetest import testutils
 
 
     def setUp(self):
         super(InlineTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = rope.base.project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod = self.pycore.create_module(self.project.root, 'mod')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(InlineTest, self).tearDown()
 
     def _inline(self, code, offset):

File ropetest/refactor/movetest.py

 import unittest
 
-import rope.base.project
 from rope.base import exceptions
 from rope.refactor import move
 from ropetest import testutils
 
     def setUp(self):
         super(MoveRefactoringTest, self).setUp()
-        self.project_root = 'sampleproject'
-        testutils.remove_recursively(self.project_root)
-        self.project = rope.base.project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
         self.mod1 = self.pycore.create_module(self.project.root, 'mod1')
         self.mod2 = self.pycore.create_module(self.project.root, 'mod2')
         self.mod5 = self.pycore.create_module(self.pkg, 'mod5')
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(MoveRefactoringTest, self).tearDown()
 
     def _move(self, resource, offset, dest_resource):

File ropetest/refactor/renametest.py

 import unittest
 
 import rope.base.codeanalyze
-import rope.base.project
 import rope.refactor.occurrences
-import ropetest
 from rope.refactor import rename
 from rope.refactor.rename import Rename
+from ropetest import testutils
 
 
 class RenameRefactoringTest(unittest.TestCase):
 
     def setUp(self):
         super(RenameRefactoringTest, self).setUp()
-        self.project_root = 'sample_project'
-        ropetest.testutils.remove_recursively(self.project_root)
-        self.project = rope.base.project.Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        ropetest.testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(RenameRefactoringTest, self).tearDown()
 
     def _local_rename(self, source_code, offset, new_name):
 class ChangeOccurrencesTest(unittest.TestCase):
 
     def setUp(self):
-        super(ChangeOccurrencesTest, self).setUp()
-        ropetest.testutils.remove_recursively('sample_project')
-        self.project = rope.base.project.Project('sample_project')
+        self.project = testutils.sample_project()
         self.mod = self.project.get_pycore().create_module(
             self.project.root, 'mod')
 
     def tearDown(self):
-        ropetest.testutils.remove_recursively('sample_project')
+        testutils.remove_project(self.project)
         super(ChangeOccurrencesTest, self).tearDown()
 
     def test_simple_case(self):

File ropetest/runmodtest.py

 import os
 import unittest
 
-from rope.base.project import Project
 from rope.base.exceptions import RopeError
 from ropetest import testutils
 
+
 class PythonFileRunnerTest(unittest.TestCase):
 
     def setUp(self):
         super(PythonFileRunnerTest, self).setUp()
-        self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
-        self.project = Project(self.project_root)
+        self.project = testutils.sample_project()
         self.pycore = self.project.get_pycore()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         super(PythonFileRunnerTest, self).tearDown()
 
     def make_sample_python_file(self, file_path, get_text_function_source=None):

File ropetest/testutils.py

-import os
 import os.path
 import shutil
 import sys
 
+import rope.base.project
+
+
+def sample_project(root=None, **kwds):
+    if root is None:
+        root = 'sample_project'
+        # HACK: Using ``/dev/shm/`` for faster tests
+        if os.name == 'posix' and os.path.isdir('/dev/shm'):
+            root = '/dev/shm/' + root
+    remove_recursively(root)
+    return rope.base.project.Project(root, **kwds)
+
+
+def remove_project(project):
+    project.close()
+    remove_recursively(project.address)
+
+
 def remove_recursively(path):
     import time
     if os.name == 'nt':

File ropetest/ui/fileeditortest.py

 
 import Tkinter
 
-from rope.base.project import Project
 from rope.ui.editor import *
 from rope.ui.fileeditor import *
+from ropetest import testutils
 from ropetest.ui.mockeditortest import get_sample_editingcontext
-from ropetest import testutils
 
 
 class FileEditorTest(unittest.TestCase):
     def setUp(self):
         unittest.TestCase.setUp(self)
         self.project_root = 'sample_project'
-        testutils.remove_recursively(self.project_root)
+        self.project = testutils.sample_project(self.project_root)
         self._make_sample_project()
         self.fileName = self.sample_file
-        self.project = Project(self.project_root)
         get_sample_editingcontext()
         self.editor = FileEditor(self.project, self.project.get_resource(self.fileName),
                                  GraphicalEditorFactory(Tkinter.Frame()))
     def _make_sample_project(self):
         self.sample_file = 'sample_file.txt'
         self.sample_path = os.path.join(self.project_root, 'sample_file.txt')
-        os.mkdir(self.project_root)
         sample = open(self.sample_path, 'w')
         sample.write('sample text\n')
         sample.close()
 
     def tearDown(self):
-        testutils.remove_recursively(self.project_root)
+        testutils.remove_project(self.project)
         unittest.TestCase.tearDown(self)
 
     def test_creation(self):