b5deba11fc17

Add working tests.  Awesome.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 04 Oct 2009 16:12:09 -0400
parents 4d7eca6c1832
children d02c0ed2f109
branches/tags (none)
files review/tests/test_init.py review/tests/util.py

Changes

--- 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
+
--- 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)