rope / ropetest / testutils.py

Ali Gholami Rudi 0306965 
Ali Gholami Rudi e009c98 
Ali Gholami Rudi 9d7bee3 
Ali Gholami Rudi 0306965 
Ali Gholami Rudi 495804b 
Ali Gholami Rudi 9ef5738 
Ali Gholami Rudi 495804b 

Ali Gholami Rudi 4caaaf8 
Ali Gholami Rudi 495804b 

Ali Gholami Rudi 4caaaf8 

Ali Gholami Rudi 495804b 


Ali Gholami Rudi 1d5f2f5 
Ali Gholami Rudi 8562e48 
Ali Gholami Rudi fb7cde1 

Ali Gholami Rudi 1d5f2f5 
Ali Gholami Rudi 495804b 
Ali Gholami Rudi 1d5f2f5 

Ali Gholami Rudi 495804b 
Ali Gholami Rudi 9ef5738 

Ali Gholami Rudi 495804b 





Ali Gholami Rudi e009c98 
Ali Gholami Rudi abae011 









Ali Gholami Rudi 41c4490 
Ali Gholami Rudi abae011 

Ali Gholami Rudi e009c98 
Ali Gholami Rudi 0306965 
Ali Gholami Rudi e009c98 



Ali Gholami Rudi 9d7bee3 
Ali Gholami Rudi ef886bc 
Ali Gholami Rudi 9d7bee3 
Ali Gholami Rudi fe72f3a 
Ali Gholami Rudi 73275ae 
Ali Gholami Rudi 9d7bee3 




Ali Gholami Rudi 36635a6 

Ali Gholami Rudi 4f49c0d 









Ali Gholami Rudi 36635a6 
Ali Gholami Rudi fe72f3a 
Ali Gholami Rudi 36635a6 



import os.path
import shutil
import sys

import rope.base.project
from rope.contrib import generate


def sample_project(root=None, foldername=None, **kwds):
    if root is None:
        root = 'sample_project'
        if foldername:
            root = foldername
        # HACK: Using ``/dev/shm/`` for faster tests
        if os.name == 'posix' and os.path.isdir('/dev/shm'):
            root = '/dev/shm/' + root
    # Using these prefs for faster tests
    prefs = {'save_objectdb': False, 'save_history': False,
             'validate_objectdb': False, 'automatic_soi': False,
             'ignored_resources': ['.ropeproject', '*.pyc']}
    prefs.update(kwds)
    remove_recursively(root)
    project = rope.base.project.Project(root, **prefs)
    return project

create_module = generate.create_module
create_package = generate.create_package

def remove_project(project):
    project.close()
    remove_recursively(project.address)


def remove_recursively(path):
    import time
    if os.name == 'nt':
        for i in range(12):
            try:
                _remove_recursively(path)
            except WindowsError:
                time.sleep(0.3)
            else:
                break
    else:
        _remove_recursively(path)

def _remove_recursively(path):
    if not os.path.exists(path):
        return
    if os.path.isfile(path):
        os.remove(path)
    else:
        shutil.rmtree(path)


def run_only_for_25(func):
    """Should be used as a decorator for a unittest.TestCase test method"""
    if sys.version_info >= (2, 5, 0):
        return func
    else:
        def do_nothing(self):
            pass
        return do_nothing


def run_only_for_unix(func):
    """Should be used as a decorator for a unittest.TestCase test method"""
    if os.name == 'posix':
        return func
    else:
        def do_nothing(self):
            pass
        return do_nothing


def assert_raises(exception_class):
    """Should be used as a decorator for a unittest.TestCase test method"""
    def _assert_raises(func):
        def call_func(self, *args, **kws):
            self.assertRaises(exception_class, func, self, *args, **kws)
        return call_func
    return _assert_raises
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.