2310846513b8

tests: factor out get_identifiers and log errors better
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 19 Jun 2010 15:43:22 -0400
parents fe2edf9c9098
children 03fded64e34e
branches/tags (none)
files review/tests/test_delete.py review/tests/util.py

Changes

--- a/review/tests/test_delete.py	Sat Jun 19 13:44:29 2010 -0400
+++ b/review/tests/test_delete.py	Sat Jun 19 15:43:22 2010 -0400
@@ -1,43 +1,35 @@
 from nose import with_setup
 from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with
+from util import get_identifiers
 
 from .. import messages
 
-a1, a2 = (messages.REVIEW_LOG_COMMENT_AUTHOR % '|').split('|')
-s1, s2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'neutral')).split('|')
-
-def _get_identifiers(rev='.'):
-    return [l.split(' ')[-1].strip('()\n')
-            for l in review(rev=rev, verbose=True).splitlines()
-            if (a1 in l and a2 in l) or (s1 in l and s2 in l)]
-
-
 @with_setup(setup_reviewed_sandbox, teardown_sandbox)
 def test_delete_invalid():
-    should_fail_with(messages.DELETE_REQUIRES_IDS, delete=True)
-    should_fail_with(messages.DELETE_UNKNOWN_ID % 'a', delete=True, args=['a'])
+    should_fail_with(messages.REQUIRES_IDS, delete=True)
+    should_fail_with(messages.UNKNOWN_ID % 'a', delete=True, args=['a'])
 
     review(comment=True, message='test')
 
-    should_fail_with(messages.DELETE_UNKNOWN_ID % 'z', delete=True, args=['z'])
+    should_fail_with(messages.UNKNOWN_ID % 'z', delete=True, args=['z'])
 
     # Use the pidgeonhole princicple to create ambiguous identifiers.
     for i in range(17):
         review(comment=True, message='test%d' % i)
 
-    ids = _get_identifiers()
+    ids = get_identifiers()
     id_map = {}
     for i in ids:
         id_map[i[0]] = id_map.get(i[0], 0) + 1
     i = str(filter(lambda k: id_map[k] > 1, id_map.keys())[0])
 
-    should_fail_with(messages.DELETE_AMBIGUOUS_ID % i, delete=True, args=[i])
+    should_fail_with(messages.AMBIGUOUS_ID % i, delete=True, args=[i])
 
 @with_setup(setup_reviewed_sandbox, teardown_sandbox)
 def test_delete_comment():
     def t(rev):
         review(rev=rev, comment=True, message='test')
-        i = _get_identifiers(rev)[0]
+        i = get_identifiers(rev)[0]
 
         output = review(rev=rev, delete=True, args=[i])
         assert not output
@@ -46,7 +38,7 @@
 
         review(rev=rev, comment=True, message='test2')
         review(rev=rev, comment=True, message='test3')
-        i1, i2 = _get_identifiers(rev)
+        i1, i2 = get_identifiers(rev)
 
         output = review(rev=rev, delete=True, args=[i1])
         assert not output
@@ -55,7 +47,7 @@
         assert '(%s)\n' % i2 in output
 
         review(rev=rev, comment=True, message='test4')
-        i1, i2 = _get_identifiers(rev)
+        i1, i2 = get_identifiers(rev)
 
         output = review(rev=rev, delete=True, args=[i1, i2])
         assert not output
@@ -69,7 +61,7 @@
 def test_delete_signoff():
     # TODO: test multiple signoff deletions
     review(signoff=True, message='test')
-    i = _get_identifiers()[0]
+    i = get_identifiers()[0]
 
     output = review(delete=True, args=[i])
     assert not output
@@ -78,7 +70,7 @@
 
     review(comment=True, message='test2')
     review(signoff=True, message='test3')
-    i1, i2 = _get_identifiers()
+    i1, i2 = get_identifiers()
 
     output = review(delete=True, args=[i2])
     assert not output
@@ -91,7 +83,7 @@
     def t(rev):
         review(rev=rev, signoff=True, message='test')
         review(rev=rev, comment=True, message='test')
-        ids = _get_identifiers(rev)
+        ids = get_identifiers(rev)
 
         output = review(rev=rev, delete=True, args=ids)
         assert not output
@@ -102,7 +94,7 @@
         review(rev=rev, signoff=True, message='test2')
         review(rev=rev, comment=True, message='test3')
         review(rev=rev, comment=True, message='test4')
-        ids = _get_identifiers(rev)
+        ids = get_identifiers(rev)
 
         output = review(rev=rev, delete=True, args=ids[:2])
         assert not output
--- a/review/tests/util.py	Sat Jun 19 13:44:29 2010 -0400
+++ b/review/tests/util.py	Sat Jun 19 15:43:22 2010 -0400
@@ -6,14 +6,14 @@
 import sample_data
 from mercurial import cmdutil, commands, hg, ui
 from mercurial import util as hgutil
-from .. import api, cli
+from .. import api, cli, messages
 
 _ui = ui.ui()
 _ui.setconfig('extensions', 'progress', '!')
 def review(init=False, comment=False, signoff=False, check=False, yes=False,
     no=False, force=False, message='', rev='.', remote_path='', lines='',
     args=None, unified='5', web=False, verbose=False, debug=False, mdown=False,
-    seen=False, yeses='', no_nos=False, delete=False):
+    seen=False, yeses='', no_nos=False, delete=False, edit=''):
 
     args = args or []
 
@@ -27,7 +27,7 @@
             init=init, comment=comment, signoff=signoff, check=check, yes=yes,
             no=no, force=force, message=message, rev=rev, remote_path=remote_path,
             lines=lines, unified=unified, web=web, mdown=mdown, seen=seen,
-            yeses=yeses, no_nos=no_nos, delete=delete
+            yeses=yeses, no_nos=no_nos, delete=delete, edit=edit
         )
     )
     _ui.verbose, _ui.debugflag = False, False
@@ -111,11 +111,16 @@
 def get_ui():
     return _ui
 
+WRONG_ERROR = '''\
+The wrong error was printed.
 
+Expected: %s
+Actual:   %s'''
 BAD_ERROR = 'The correct error message was not printed.'
 def _check_e(e, m):
     error = str(e)
-    assert m in e
+    assert m in e, WRONG_ERROR % (repr(m), repr(error))
+
 
 def should_fail_with(m, **kwargs):
     try:
@@ -125,3 +130,11 @@
     else:
         assert False, BAD_ERROR
 
+
+a1, a2 = (messages.REVIEW_LOG_COMMENT_AUTHOR % '|').split('|')
+s1, s2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'neutral')).split('|')
+
+def get_identifiers(rev='.'):
+    return [l.split(' ')[-1].strip('()\n')
+            for l in review(rev=rev, verbose=True).splitlines()
+            if (a1 in l and a2 in l) or (s1 in l and s2 in l)]