# HG changeset patch # User Steve Losh # Date 1279842952 14400 # Node ID a21fcb365fcd8af67bdbc4e06d171c72b8d66d63 # Parent bef3dce04be61026f56b6b30865b6c2947161ded tests: test for utf-8 and non-utf-8 usernames diff -r bef3dce04be6 -r a21fcb365fcd review/tests/test_encoding.py --- a/review/tests/test_encoding.py Thu Jul 22 19:12:51 2010 -0400 +++ b/review/tests/test_encoding.py Thu Jul 22 19:55:52 2010 -0400 @@ -23,3 +23,18 @@ review(signoff=True, message=rutil.tolocal(u'Téstíng.')) output = review() assert messages.REVIEW_LOG_SIGNOFF_LINE % rutil.tolocal(u'Téstíng.') in output + +@with_setup(setup_reviewed_sandbox(username=u'Tést ', encoding='UTF-8'), teardown_sandbox) +def test_username_encoding_utf8(): + review(comment=True, message=rutil.tolocal(u'Cómment.')) + output = review() + assert u'Tést'.encode('UTF-8') in output + assert u'Cómment.'.encode('UTF-8') in output + +@with_setup(setup_reviewed_sandbox(username=u'Tést ', encoding='ISO-8859-1'), teardown_sandbox) +def test_username_encoding_iso_8859_1(): + review(comment=True, message=rutil.tolocal(u'Cómment.')) + output = review() + assert u'Tést'.encode('ISO-8859-1') in output + assert u'Cómment.'.encode('ISO-8859-1') in output + diff -r bef3dce04be6 -r a21fcb365fcd review/tests/util.py --- a/review/tests/util.py Thu Jul 22 19:12:51 2010 -0400 +++ b/review/tests/util.py Thu Jul 22 19:55:52 2010 -0400 @@ -6,7 +6,10 @@ import sample_data from mercurial import commands, hg, ui from mercurial import util as hgutil -from .. import api, cli, messages +from mercurial import encoding as _encoding +from .. import api, cli, messages, rutil + +orig_encoding = _encoding.encoding _ui = ui.ui() _ui.setconfig('extensions', 'progress', '!') @@ -42,7 +45,10 @@ sandbox_clone_path = os.path.join(sandbox_path, 'clone') -def setup_sandbox(): +def setup_sandbox(username=None, encoding=None): + if encoding: + _encoding.encoding = encoding + os.mkdir(sandbox_path) os.chdir(sandbox_path) @@ -57,7 +63,8 @@ sandbox = get_sandbox_repo() - opts = { 'addremove': True, 'date': None, 'user': 'Review Tester', + opts = { 'addremove': True, 'date': None, + 'user': rutil.tolocal(username) if username else 'Test ', 'logfile': None, 'message': "Sandbox commit.", } for state in sample_data.log: for filename in state: @@ -77,9 +84,9 @@ os.chdir('..') commands.commit(_ui, sandbox, **opts) -def setup_reviewed_sandbox(): +def setup_reviewed_sandbox(username=None, encoding=None, file_encoding=None): def _setup(): - setup_sandbox() + setup_sandbox(username, encoding) sandbox = get_sandbox_repo() rpath = os.path.join(sandbox.root, api.DEFAULT_DATASTORE_DIRNAME) @@ -88,14 +95,19 @@ 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') + if username: + un = u'[ui]\nusername=%s\n' % username + hgrc.write(rutil.tolocal(un)) - opts = { 'addremove': True, 'date': None, 'user': 'Review Tester', + opts = { 'addremove': True, 'date': None, + 'user': rutil.tolocal(username) if username else 'Test ', 'logfile': None, 'message': "Add the code review.", } commands.commit(_ui, sandbox, **opts) return _setup def teardown_sandbox(): + _encoding.encoding = orig_encoding os.chdir(os.path.realpath(os.path.join(sandbox_path, os.pardir))) shutil.rmtree(sandbox_path)