review/tests/util.py @ 0d213b070f79

Mark the internal object commit and delete methods as private.
author Steve Losh <steve@stevelosh.com>
date Thu, 08 Oct 2009 18:12:44 -0400
parents 08528309f7cd
children 9df20fad6514
import os, shutil
import sample_data
from mercurial import commands, hg, ui
from .. import extension_ui


_ui = ui.ui()
def review(init=False, comment=False, signoff=False, yes=False, no=False,
    force=False, message='', rev='.', local_path='', remote_path='', lines='',
    files=None):
    
    files = files if files else []
    
    _ui.pushbuffer()
    extension_ui.review(_ui, get_sandbox_repo(), *files,
        init=init, comment=comment, signoff=signoff, yes=yes, no=no, 
        force=force, message=message, rev=rev,
        local_path=local_path, remote_path=remote_path, lines=lines )
    output = _ui.popbuffer()
    
    print output
    return output


sandbox_path = os.path.join(os.path.realpath('.'), 'sandbox')

def setup_sandbox():
    os.mkdir(sandbox_path)
    os.chdir(sandbox_path)
    
    commands.init(_ui)
    sandbox = get_sandbox_repo()
    
    opts = { 'addremove': True, 'date': None, 'user': 'Review Tester',
             'logfile': None, 'message': "Sandbox commit.", }
    for state in sample_data.log:
        for filename in state:
            dirname, key = None, filename
            
            # Support one-level-deep directories in the sample data.
            if '/' in filename:
                dirname, _, filename = filename.partition('/')
                if not os.path.exists(dirname):
                    os.mkdir(dirname)
                os.chdir(dirname)
            
            with open(filename, 'w') as f:
                f.write(state[key])
            
            if dirname:
                os.chdir('..')
        commands.commit(_ui, sandbox, **opts)

def setup_reviewed_sandbox():
    setup_sandbox()
    sandbox = get_sandbox_repo()
    
    review(init=True)
    
    opts = { 'addremove': True, 'date': None, 'user': 'Review Tester',
             'logfile': None, 'message': "Add the code review.", }
    commands.commit(_ui, sandbox, **opts)

def teardown_sandbox():
    os.chdir(os.path.realpath(os.path.join(sandbox_path, os.pardir)))
    shutil.rmtree(sandbox_path)


def get_sandbox_repo():
    return hg.repository(_ui, sandbox_path)

def get_datastore_repo(path):
    return hg.repository(_ui, path)