def new_run_command(command, context): run_command_params.append(command) run_command_params.append(context) if create_dir is not None: working_dir = path(context.working_dir) (working_dir / create_dir).mkdir() return command.process_output(0, StringIO(command_output))
def test_push_command_before_commit(): commit_file = path(test_context.working_dir) / ".svn_commit_messages" if commit_file.exists(): commit_file.unlink() generic_push = commands.push(test_context, []) result = dialect.convert(generic_push) assert result.get_command_line() == None assert str(result.get_output()) == "Nothing to push. Run commit first."
def __init__(self, working_dir, auth=None): """working_dir is the working directory in which commands should run. auth is a dictionary of authentication information: * type: 'ssh' or 'password' * key: for SSH, this should be the path to the user's private key * username: for SSH or password auth, this is the username to use * password: for password auth, this is the password to use""" self.working_dir = path(working_dir) self.auth = auth
def test_remove_command_no_targets(): myfile = path(topdir) / "myfile" myfile.write_bytes("test data") try: generic_remove = commands.remove(context, ["myfile"]) remove = hg.remove(generic_remove) finally: myfile.unlink() assert not remove.reads_remote assert not remove.writes_remote assert remove.get_command_line() == ["hg", "remove", "-f", "myfile"]
def test_resolved_command_no_targets(): myfile = path(topdir) / "myfile" myfile.write_bytes("test data") try: generic_resolved = commands.resolved(context, []) resolved = hg.resolved(generic_resolved) finally: myfile.unlink() assert not resolved.reads_remote assert not resolved.writes_remote assert resolved.get_command_line() == ["hg", "resolve", "-m", "-a"]
def test_revert_command(): myfile = path(topdir) / "myfile" myfile.write_bytes("test data") try: generic_revert = commands.revert(context, []) revert = hg.revert(generic_revert) finally: myfile.unlink() assert not revert.reads_remote assert not revert.writes_remote assert revert.get_command_line() == ["hg", "revert", "--no-backup", "-a"]
def test_commit_command(): commit_file = path(test_context.working_dir) / ".svn_commit_messages" if commit_file.exists(): commit_file.unlink() generic_commit = commands.commit(test_context, ["-m", "test message", "foo", "bar"]) result = dialect.convert(generic_commit) assert result.get_command_line() == None assert str(result.get_output()) == "Commit message saved. Don't forget to push to save to the remote repository!" assert commit_file.exists(), "Expected commit file at " + commit_file assert commit_file.text() == "test message\n\n"
def test_push_after_commit(): commit_file = path(test_context.working_dir) / ".svn_commit_messages" if commit_file.exists(): commit_file.unlink() generic_commit = commands.commit(test_context, ["-m", "test message1", "foo", "bar"]) result = dialect.convert(generic_commit) result.get_output() generic_commit = commands.commit(test_context, ["-m", "test message2", "foo", "bar"]) result = dialect.convert(generic_commit) result.get_output() generic_push = commands.push(test_context, []) result = dialect.convert(generic_push) assert result.get_command_line() == ["svn", "commit", "-m", "test message1\n\ntest message2\n\n"]
from uvc.path import path from uvc import commands from uvc.tests.util import test_context from uvc.main import Context, SecureContext from uvc.exc import UVCError topdir = (path(__file__).parent.parent.parent) / "testfiles" context = None secure_context = None def setup_module(module): global context, secure_context if not topdir.exists: topdir.mkdir() context = Context(topdir) secure_context = SecureContext(topdir) def test_create_clone_command(): clone = commands.clone(context, ["http://hg.mozilla.org/labs/bespin", "bespin"]) assert clone.reads_remote assert not clone.writes_remote assert clone.source == "http://hg.mozilla.org/labs/bespin" assert clone.dest == "bespin" assert str(clone) == "clone http://hg.mozilla.org/labs/bespin bespin" def test_bad_clone_command(): try: clone = commands.clone(context, [])
"""Utilities for testing VCS, specifically for working around not acually needing to run a VCS.""" from functools import wraps from cStringIO import StringIO from uvc import main, commands from uvc.path import path topdir = (path(__file__).parent) def mock_run_command(command_output, create_dir=None): """Monkeypatches in a new run_command function in uvc.main so that we can pretend about what happens when you run the command.""" run_command_params = [] def new_run_command(command, context): run_command_params.append(command) run_command_params.append(context) if create_dir is not None: working_dir = path(context.working_dir) (working_dir / create_dir).mkdir() return command.process_output(0, StringIO(command_output)) def entangle(func): @wraps(func) def new_one(): old_run_command = main.run_command try: main.run_command = new_run_command return func(run_command_params) finally:
import os from cStringIO import StringIO from uvc.path import path from uvc import commands, svn, main, exc, util from uvc.tests.util import test_context from uvc.tests.mock import patch StatusOutput = commands.StatusOutput dialect = svn.SVNDialect() topdir = path(__file__).dirname().abspath() / ".." / ".." / "testfiles" context = None def setup_module(module): global context if not os.path.exists(topdir): os.mkdir(topdir) context = main.Context(topdir) def test_clone_command_conversion(): generic_clone = commands.clone(context, ["http://paver.googlecode.com/svn/trunk/", "paver"]) svn_clone = svn.clone(generic_clone) svn_clone_command = " ".join(svn_clone.get_command_line()) assert svn_clone_command == "svn checkout http://paver.googlecode.com/svn/trunk/ paver" def test_convert_function(): generic_clone = commands.clone(context, ["http://paver.googlecode.com/svn/trunk/",
def _normalize_path(self, unnorm_path): norm_path = self.working_dir / path(unnorm_path) norm_path = norm_path.normpath() norm_path = norm_path.realpath() norm_path = norm_path.abspath() return norm_path