review/tests/util.py @ 22d5187cb76e

Big API changes.
author Steve Losh <steve@stevelosh.com>
date Sun, 04 Oct 2009 20:19:32 -0400
parents 467dacbab7d6
children 1280679a055d
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, message='', rev='.',
    local_path='', remote_path=''):
    return extension_ui.review(_ui, get_sandbox_repo(),
        init=init, comment=comment, message=message, rev=rev,
        local_path=local_path, remote_path=remote_path)


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:
            with open(filename, 'w') as f:
                f.write(state[filename])
        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, '.')

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

def gather_output():
    _ui.pushbuffer()

def grab_output():
    output = _ui.popbuffer()
    print output
    
    return output