# HG changeset patch # User Benoit Allard # Date 1280229396 -7200 # Node ID 46a08d99f9b9c7817517d9ff9fa1e4eff2eb8f5e # Parent d6523b4269f8ca3fb4a6e34e18e8d40b54ad3265# Parent cada9aab8b6ffeaa69a950cb7b45aa3681de501a merged diff -r d6523b4269f8 -r 46a08d99f9b9 review/cli.py --- a/review/cli.py Tue Jul 27 13:13:43 2010 +0200 +++ b/review/cli.py Tue Jul 27 13:16:36 2010 +0200 @@ -271,12 +271,13 @@ if not fnames: fnames = rcset.files() + fnames = [api.sanitize_path(fname, repo) for fname in fnames] fnames = [fname for fname in fnames if rcset.has_diff(fname)] for filename in fnames: header = messages.REVIEW_LOG_FILE_HEADER % filename - print '\n\n%s %s' % (header, '-'*(80-(len(header)+1))) + ui.write('\n\n%s %s\n' % (header, '-'*(80-(len(header)+1)))) for comment in rcset.file_level_comments(filename): _print_comment(comment) diff -r d6523b4269f8 -r 46a08d99f9b9 review/tests/sample_data_latin1.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/review/tests/sample_data_latin1.py Tue Jul 27 13:16:36 2010 +0200 @@ -0,0 +1,11 @@ +# coding=utf-8 +# + +log = [ + # TODO: Figure out how to make this work. + # I hate you, Python. + #{ u'filé'.encode('latin-1'): u'oné\ntwó\nthrée'.encode('latin-1'), }, + #{ u'filé'.encode('latin-1'): u'óne\ntwo\nthreé'.encode('latin-1'), }, + { u'file'.encode('latin-1'): u'oné\ntwó\nthrée'.encode('latin-1'), }, + { u'file'.encode('latin-1'): u'óne\ntwo\nthreé'.encode('latin-1'), }, +] diff -r d6523b4269f8 -r 46a08d99f9b9 review/tests/sample_data_utf8.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/review/tests/sample_data_utf8.py Tue Jul 27 13:16:36 2010 +0200 @@ -0,0 +1,7 @@ +# coding=utf-8 +# + +log = [ + { u'filé'.encode('UTF-8'): u'oné\ntwó\nthrée'.encode('UTF-8'), }, + { u'filé'.encode('UTF-8'): u'óne\ntwo\nthreé'.encode('UTF-8'), }, +] diff -r d6523b4269f8 -r 46a08d99f9b9 review/tests/test_encoding.py --- a/review/tests/test_encoding.py Tue Jul 27 13:13:43 2010 +0200 +++ b/review/tests/test_encoding.py Tue Jul 27 13:16:36 2010 +0200 @@ -2,6 +2,8 @@ # import os +import unicodedata + from nose import with_setup from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with from util import get_datastore_repo, get_sandbox_repo, get_ui @@ -38,3 +40,45 @@ assert u'Tést'.encode('ISO-8859-1') in output assert u'Cómment.'.encode('ISO-8859-1') in output +@with_setup(setup_reviewed_sandbox(username=u'Tést ', encoding='UTF-8', file_encoding='UTF-8'), teardown_sandbox) +def test_file_encoding_utf8(): + review(comment=True, message=rutil.tolocal(u'Cómment.'), rev='1') + + output = review(rev='1') + normal_output = unicodedata.normalize('NFC', output.decode('UTF-8')) + + assert unicodedata.normalize('NFC', u'filé') in normal_output + assert u'Tést'.encode('UTF-8') in output + assert u'Cómment.'.encode('UTF-8') in output + + assert u'-oné'.encode('UTF-8') in output + assert u'+óne'.encode('UTF-8') in output + + assert u'-twó'.encode('UTF-8') in output + assert u'+two'.encode('UTF-8') in output + + assert u'-thrée'.encode('UTF-8') in output + assert u'+threé'.encode('UTF-8') in output + +@with_setup(setup_reviewed_sandbox(username=u'Tést ', encoding='latin-1', file_encoding='latin-1'), teardown_sandbox) +def test_file_encoding_iso88591(): + review(comment=True, message=rutil.tolocal(u'Cómment.'), rev='1') + + output = review(rev='1') + + # TODO: Make this work. + #normal_output = unicodedata.normalize('NFC', output.decode('latin-1')) + + #assert unicodedata.normalize('NFC', u'filé') in normal_output + assert u'Tést'.encode('latin-1') in output + assert u'Cómment.'.encode('latin-1') in output + + assert u'-oné'.encode('latin-1') in output + assert u'+óne'.encode('latin-1') in output + + assert u'-twó'.encode('latin-1') in output + assert u'+two'.encode('latin-1') in output + + assert u'-thrée'.encode('latin-1') in output + assert u'+threé'.encode('latin-1') in output + diff -r d6523b4269f8 -r 46a08d99f9b9 review/tests/util.py --- a/review/tests/util.py Tue Jul 27 13:13:43 2010 +0200 +++ b/review/tests/util.py Tue Jul 27 13:16:36 2010 +0200 @@ -1,9 +1,12 @@ +# coding=utf-8 +# from __future__ import with_statement """Utilities for writing unit tests for hg-review.""" import os, shutil -import sample_data +import sample_data, sample_data_utf8, sample_data_latin1 + from mercurial import commands, hg, ui from mercurial import util as hgutil from mercurial import encoding as _encoding @@ -45,7 +48,7 @@ sandbox_clone_path = os.path.join(sandbox_path, 'clone') -def setup_sandbox(username=None, encoding=None): +def setup_sandbox(username=None, encoding=None, file_encoding=None): if encoding: _encoding.encoding = encoding @@ -66,8 +69,21 @@ 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: + + if file_encoding == 'UTF-8': + data = sample_data_utf8 + elif file_encoding == 'latin-1': + data = sample_data_latin1 + else: + data = sample_data + + for state in data.log: + for filename, data in state.items(): + if file_encoding: + filename = filename.decode(file_encoding) + else: + filename = filename.decode('ascii') + dirname, key = None, filename # Support one-level-deep directories in the sample data. @@ -77,8 +93,8 @@ os.mkdir(dirname) os.chdir(dirname) - with open(filename, 'w') as f: - f.write(state[key]) + with open(filename, 'wb') as f: + f.write(data) if dirname: os.chdir('..') @@ -86,7 +102,7 @@ def setup_reviewed_sandbox(username=None, encoding=None, file_encoding=None): def _setup(): - setup_sandbox(username, encoding) + setup_sandbox(username, encoding, file_encoding) sandbox = get_sandbox_repo() rpath = os.path.join(sandbox.root, api.DEFAULT_DATASTORE_DIRNAME)