# HG changeset patch # User Steve Losh # Date 1254687129 14400 # Node ID b5deba11fc17371787a0fe171ed477ef2a0cab86 # Parent 4d7eca6c18324919d4381f2d5385ebef5a045d46 Add working tests. Awesome. diff -r 4d7eca6c1832 -r b5deba11fc17 review/tests/test_init.py --- a/review/tests/test_init.py Sun Oct 04 16:02:27 2009 -0400 +++ b/review/tests/test_init.py Sun Oct 04 16:12:09 2009 -0400 @@ -1,9 +1,73 @@ from nose import * from util import * +import os + + +@with_setup(setup_sandbox, teardown_sandbox) +def test_init(): + sandbox = get_sandbox_repo() + + review(init=True) + + assert '.hgreview' not in sandbox['tip'] + assert os.path.exists('.hgreview') + assert os.path.isdir('.review') + assert get_datastore_repo('.review') + + with open('.hgreview', 'r') as hgrf: + hgr = hgrf.read() + assert 'local = .review' in hgr + assert 'remote = ../sandbox-review' in hgr + @with_setup(setup_sandbox, teardown_sandbox) -def test_default_init(): +def test_init_with_local_path(): + sandbox = get_sandbox_repo() + + review(init=True, local_path='codereview') + + assert '.hgreview' not in sandbox['tip'] + assert os.path.exists('.hgreview') + assert os.path.isdir('codereview') + assert get_datastore_repo('codereview') + + with open('.hgreview', 'r') as hgrf: + hgr = hgrf.read() + assert 'local = codereview' in hgr + assert 'remote = ../sandbox-review' in hgr + + +@with_setup(setup_sandbox, teardown_sandbox) +def test_init_with_remote_path(): sandbox = get_sandbox_repo() - review(init=True) \ No newline at end of file + review(init=True, remote_path='../code-review') + + assert '.hgreview' not in sandbox['tip'] + assert os.path.exists('.hgreview') + assert os.path.isdir('.review') + assert get_datastore_repo('.review') + + with open('.hgreview', 'r') as hgrf: + hgr = hgrf.read() + assert 'local = .review' in hgr + assert 'remote = ../code-review' in hgr + + +@with_setup(setup_sandbox, teardown_sandbox) +def test_init_with_both_paths(): + sandbox = get_sandbox_repo() + + review(init=True, local_path='codereview', remote_path='../code-review') + + assert '.hgreview' not in sandbox['tip'] + assert os.path.exists('.hgreview') + assert os.path.isdir('codereview') + assert get_datastore_repo('codereview') + + with open('.hgreview', 'r') as hgrf: + hgr = hgrf.read() + assert 'local = codereview' in hgr + assert 'remote = ../code-review' in hgr + diff -r 4d7eca6c1832 -r b5deba11fc17 review/tests/util.py --- a/review/tests/util.py Sun Oct 04 16:02:27 2009 -0400 +++ b/review/tests/util.py Sun Oct 04 16:12:09 2009 -0400 @@ -1,15 +1,16 @@ import os, shutil import sample_data from mercurial import commands, hg, ui +from .. import extension_ui -from .. import extension_ui + _ui = ui.ui() def review(init=False, local_path='', remote_path=''): return extension_ui.review(_ui, get_sandbox_repo(), init=init, local_path=local_path, remote_path=remote_path) -sandbox_path = os.path.join(os.path.realpath('.'), 'hgreview_test') +sandbox_path = os.path.join(os.path.realpath('.'), 'sandbox') def setup_sandbox(): os.mkdir(sandbox_path) @@ -30,6 +31,9 @@ os.chdir(os.path.realpath(os.path.join(sandbox_path, os.pardir))) shutil.rmtree(sandbox_path) + def get_sandbox_repo(): - return hg.repository(ui.ui(), '.') + return hg.repository(_ui, '.') +def get_datastore_repo(path): + return hg.repository(_ui, path)