a21fcb365fcd

tests: test for utf-8 and non-utf-8 usernames
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 22 Jul 2010 19:55:52 -0400
parents bef3dce04be6
children cada9aab8b6f d6523b4269f8
branches/tags (none)
files review/tests/test_encoding.py review/tests/util.py

Changes

--- 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 <tést@test.com>', 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 <tést@test.com>', 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
+
--- 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 <test@test.com>',
              '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 <test@test.com>',
                  '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)