bef3dce04be6

tests: generalize setup_reviewed_repo
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 22 Jul 2010 19:12:51 -0400
parents 86031ff88aa1
children a21fcb365fcd
branches/tags (none)
files review/tests/test_check.py review/tests/test_comment.py review/tests/test_delete.py review/tests/test_diffs.py review/tests/test_edit.py review/tests/test_encoding.py review/tests/test_init.py review/tests/test_signoff.py review/tests/util.py

Changes

--- a/review/tests/test_check.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_check.py	Thu Jul 22 19:12:51 2010 -0400
@@ -4,7 +4,7 @@
 
 from .. import messages
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_check_empty():
     def t(rev):
         output = review(check=True, rev=rev)
@@ -28,7 +28,7 @@
     t('.')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_check_no_nos():
     output = review(check=True, verbose=True, no_nos=True)
     assert messages.CHECK_SUCCESS in output
@@ -41,7 +41,7 @@
     output = review(check=True, verbose=True, no_nos=True)
     assert messages.CHECK_SUCCESS in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_check_yeses():
     should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1')
 
@@ -54,7 +54,7 @@
 
     should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='2')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_check_seen():
     should_fail_with(messages.CHECK_UNSEEN, check=True, verbose=True, seen=True)
 
@@ -73,7 +73,7 @@
     output = review(check=True, verbose=True, seen=True)
     assert messages.CHECK_SUCCESS in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_check_priority_no_nos():
     review(signoff=True, no=True, message='.')
     should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, yeses='0')
@@ -91,7 +91,7 @@
     should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True)
     should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True, yeses='0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_check_priority_yeses():
     review(comment=True, message='.')
     should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1', seen=True)
--- a/review/tests/test_comment.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_comment.py	Thu Jul 22 19:12:51 2010 -0400
@@ -13,12 +13,12 @@
 
 a1, a2 = (messages.REVIEW_LOG_COMMENT_AUTHOR % '|').split('|')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_no_comments():
     output = review()
     assert messages.REVIEW_LOG_COMMENTS % (0, 0) in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_comment_formatting():
     review(comment=True, message=' \tTest comment one.\t ')
     output = review()
@@ -38,14 +38,14 @@
     assert messages.REVIEW_LOG_COMMENT_LINE % 'outdented  ' in output
     assert messages.REVIEW_LOG_COMMENT_LINE % 'done' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_comment_styles():
     review(comment=True, message='Test comment one.', mdown=True)
     output = review()
 
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_parent_rev():
     review(comment=True, message='Test comment one.')
 
@@ -64,7 +64,7 @@
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment two.' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_specific_rev():
     review(comment=True, message='Test comment one.', rev='0')
 
@@ -87,7 +87,7 @@
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment two.' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_file():
     review(comment=True, message='Test comment one.', rev='1', args=['file_one'])
 
@@ -104,7 +104,7 @@
     assert a2 not in output
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_multiple_files():
     review(comment=True, message='Test comment.', rev='1',
         args=['file_one', 'always_changing'])
@@ -116,12 +116,12 @@
                      comment=True, rev='1', message='Test bad comment.', lines='1',
                      args=['file_one', 'always_changing'])
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_bad_file():
     should_fail_with(messages.COMMENT_FILE_DOES_NOT_EXIST % ('bad', '2'),
                      comment=True, message='Test comment one.', args=['bad'])
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_file_line():
     should_fail_with(messages.COMMENT_LINES_REQUIRE_FILE,
                      comment=True, rev='1', message='Test bad comment.', lines='1')
@@ -138,7 +138,7 @@
 
     check_comment_exists_on_line(1, files=['file_one'], rev='1')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_file_lines():
     review(comment=True, rev='1', message='Test comment one.',
         args=['file_one'], lines='1,2')
@@ -152,7 +152,7 @@
 
     check_comment_exists_on_line(2, files=['file_one'], rev='1')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_file_in_subdir():
     filename = os.path.join('test_dir', 'test_file')
 
@@ -171,7 +171,7 @@
     assert a2 not in output
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_file_in_cwd():
     os.chdir('test_dir')
     review(comment=True, message='Test comment one.', rev='1', args=['test_file'])
@@ -189,7 +189,7 @@
     assert a2 not in output
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_add_comments_to_file_in_reldir():
     filename = os.path.join('..', 'file_three')
 
@@ -209,7 +209,7 @@
     assert a2 not in output
     assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_comment_identifiers():
     review(comment=True, message='Test comment one.', rev='1', args=['file_one'])
 
--- a/review/tests/test_delete.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_delete.py	Thu Jul 22 19:12:51 2010 -0400
@@ -4,7 +4,7 @@
 
 from .. import messages
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_delete_invalid():
     should_fail_with(messages.REQUIRES_IDS, delete=True)
     should_fail_with(messages.UNKNOWN_ID % 'a', delete=True, args=['a'])
@@ -25,7 +25,7 @@
 
     should_fail_with(messages.AMBIGUOUS_ID % i, delete=True, args=[i])
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_delete_comment():
     def t(rev):
         review(rev=rev, comment=True, message='test')
@@ -57,7 +57,7 @@
     t('.')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_delete_signoff():
     # TODO: test multiple signoff deletions
     review(signoff=True, message='test')
@@ -78,7 +78,7 @@
     assert '(%s)\n' % i1 in output
     assert '(%s)\n' % i2 not in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_delete_both():
     def t(rev):
         review(rev=rev, signoff=True, message='test')
--- a/review/tests/test_diffs.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_diffs.py	Thu Jul 22 19:12:51 2010 -0400
@@ -6,7 +6,7 @@
 a1, a2 = (messages.REVIEW_LOG_COMMENT_AUTHOR % '|').split('|')
 s1, s2 = (messages.REVIEW_LOG_SKIPPED % 1111).split('1111')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_review_diff_default_context():
     output = review(rev='1', args=['long_file'], unified='5')
 
@@ -24,7 +24,7 @@
     assert '20:' not in output
     assert messages.REVIEW_LOG_SKIPPED % 2 in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_review_diff_full_context():
     output = review(rev='1', args=['long_file'], unified='10000')
 
@@ -34,7 +34,7 @@
     for n in range(0, 21):
         assert '%2d:' % n in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_review_diff_small_context():
     output = review(rev='1', args=['long_file'], unified='2')
 
@@ -53,7 +53,7 @@
     assert '17:' not in output
     assert messages.REVIEW_LOG_SKIPPED % 5 in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_review_diff_with_comment():
     review(comment=True, rev='1', message='Test comment one.',
         args=['long_file'], lines='6,7')
@@ -72,7 +72,7 @@
             assert output[n-1].strip().startswith('7')
             break
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_review_diff_with_skipped_comment():
     review(comment=True, rev='1', message='Test comment one.',
         args=['long_file'], lines='3')
--- a/review/tests/test_edit.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_edit.py	Thu Jul 22 19:12:51 2010 -0400
@@ -6,7 +6,7 @@
 
 from .. import messages
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_edit_invalid():
     should_fail_with(messages.UNKNOWN_ID % 'z', edit='z')
 
@@ -27,7 +27,7 @@
     should_fail_with(messages.AMBIGUOUS_ID % i, edit=i)
 
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_touch_comment():
     def t(rev):
         review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
@@ -47,7 +47,7 @@
     t('1')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_edit_comment_message():
     def t(rev):
         review(rev=rev, comment=True, message='test')
@@ -63,7 +63,7 @@
     t('.')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_edit_comment_lines():
     def t(rev):
         review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
@@ -89,7 +89,7 @@
     t('1')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_edit_comment_filename():
     def t(rev):
         review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
@@ -110,7 +110,7 @@
     t('1')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_edit_comment_everything():
     def t(rev):
         review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
@@ -134,7 +134,7 @@
     t('0')
 
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_touch_signoff():
     def t(rev):
         review(rev=rev, signoff=True, message='test', yes=True)
@@ -153,7 +153,7 @@
     t('1')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_edit_signoff_message():
     def t(rev):
         review(rev=rev, signoff=True, message='test')
@@ -169,7 +169,7 @@
     t('.')
     t('0')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_edit_signoff_opinion():
     def t(rev):
         review(rev=rev, signoff=True, message='test')
--- a/review/tests/test_encoding.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_encoding.py	Thu Jul 22 19:12:51 2010 -0400
@@ -12,13 +12,13 @@
 from mercurial.node import hex
 
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_comment_encoding():
     review(comment=True, message=rutil.tolocal(u'Téstíng.'))
     output = review()
     assert messages.REVIEW_LOG_COMMENT_LINE % rutil.tolocal(u'Téstíng.') in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_encoding():
     review(signoff=True, message=rutil.tolocal(u'Téstíng.'))
     output = review()
--- a/review/tests/test_init.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_init.py	Thu Jul 22 19:12:51 2010 -0400
@@ -36,7 +36,7 @@
     review(init=True, remote_path='/sandbox-review')
     should_fail_with(messages.INIT_EXISTS_UNCOMMITTED, init=True, remote_path='/sandbox-review')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_init_clone():
     review(comment=True, message='Test comment one.')
     review(comment=True, rev='0', message='Test comment two.')
--- a/review/tests/test_signoff.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/test_signoff.py	Thu Jul 22 19:12:51 2010 -0400
@@ -12,12 +12,12 @@
 sy1, sy2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'yes')).split('|')
 sn1, sn2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'no')).split('|')
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_no_signoffs():
     output = review()
     assert messages.REVIEW_LOG_SIGNOFFS % (0, 0, 0, 0) in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_formatting():
     review(signoff=True, message=' \tTest signoff one.\t ')
     output = review()
@@ -37,14 +37,14 @@
     assert messages.REVIEW_LOG_SIGNOFF_LINE % 'outdented  ' in output
     assert messages.REVIEW_LOG_SIGNOFF_LINE % 'done' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_styles():
     review(signoff=True, message='Test signoff one.', mdown=True)
     output = review()
 
     assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_on_parent_rev():
     review(signoff=True, message='Test signoff one.')
 
@@ -55,7 +55,7 @@
     assert s1 in output
     assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_on_specific_rev():
     review(signoff=True, message='Test signoff one.', rev='0')
 
@@ -65,7 +65,7 @@
     output = review()
     assert messages.REVIEW_LOG_SIGNOFFS % (0, 0, 0, 0) in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_multiple_signoffs():
     review(signoff=True, message='Test signoff one.')
 
@@ -74,7 +74,7 @@
     output = review()
     assert messages.REVIEW_LOG_SIGNOFFS % (1, 0, 0, 1) in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_yes():
     review(signoff=True, yes=True, message='Test signoff one.')
 
@@ -85,7 +85,7 @@
     assert sy1 in output
     assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_no():
     review(signoff=True, no=True, message='Test signoff one.')
 
@@ -96,7 +96,7 @@
     assert sn1 in output
     assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
 
-@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
 def test_signoff_identifiers():
     review(signoff=True, message='Test signoff one.', rev='0')
 
--- a/review/tests/util.py	Thu Jul 22 18:27:31 2010 -0400
+++ b/review/tests/util.py	Thu Jul 22 19:12:51 2010 -0400
@@ -53,7 +53,7 @@
 
     sandbox_hg_path = os.path.join(sandbox_repo_path, '.hg')
     with open(os.path.join(sandbox_hg_path, 'hgrc'), 'w') as hgrc:
-        hgrc.write('[extensions]\nprogress=!')
+        hgrc.write('[extensions]\nprogress=!\n')
 
     sandbox = get_sandbox_repo()
 
@@ -78,19 +78,21 @@
         commands.commit(_ui, sandbox, **opts)
 
 def setup_reviewed_sandbox():
-    setup_sandbox()
-    sandbox = get_sandbox_repo()
+    def _setup():
+        setup_sandbox()
+        sandbox = get_sandbox_repo()
 
-    rpath = os.path.join(sandbox.root, api.DEFAULT_DATASTORE_DIRNAME)
-    review(init=True, remote_path=rpath)
+        rpath = os.path.join(sandbox.root, api.DEFAULT_DATASTORE_DIRNAME)
+        review(init=True, remote_path=rpath)
 
-    review_hg_path = os.path.join(rpath, '.hg')
-    with open(os.path.join(review_hg_path, 'hgrc'), 'w') as hgrc:
-        hgrc.write('[extensions]\nprogress=!')
+        review_hg_path = os.path.join(rpath, '.hg')
+        with open(os.path.join(review_hg_path, 'hgrc'), 'w') as hgrc:
+            hgrc.write('[extensions]\nprogress=!\n')
 
-    opts = { 'addremove': True, 'date': None, 'user': 'Review Tester',
-             'logfile': None, 'message': "Add the code review.", }
-    commands.commit(_ui, sandbox, **opts)
+        opts = { 'addremove': True, 'date': None, 'user': 'Review Tester',
+                 'logfile': None, 'message': "Add the code review.", }
+        commands.commit(_ui, sandbox, **opts)
+    return _setup
 
 
 def teardown_sandbox():