382: tests: add some tests for non-ascii diffs by Steve Losh
tests: add some tests for non-ascii diffs
No changeset-level comments yet…
Add a comment on this changeset
Signoffs
No signoffs yet…
Files
cmV2aWV3L2NsaS5weQ==
review/cli.py ↓
| … skipped 268 lines … | ||
| 268 | if ui.quiet: |
|
| 269 | return |
|
| 270 | |
|
| 271 | if not fnames: |
|
| 272 | fnames = rcset.files() |
|
| 273 | + | |
| 274 | fnames = [api.sanitize_path(fname, repo) for fname in fnames] |
|
| 275 | fnames = [fname for fname in fnames if rcset.has_diff(fname)] |
|
| 276 | |
|
| 277 | for filename in fnames: |
|
| 278 | header = messages.REVIEW_LOG_FILE_HEADER % filename |
|
| 279 | - | print '\n\n%s %s' % (header, '-'*(80-(len(header)+1))) |
| 280 | + | ui.write('\n\n%s %s\n' % (header, '-'*(80-(len(header)+1)))) |
| 281 | |
|
| 282 | for comment in rcset.file_level_comments(filename): |
|
| 283 | _print_comment(comment) |
|
| 284 | |
|
| 285 | annotated_diff = rcset.annotated_diff(filename, context) |
|
| … skipped 150 lines … | ||
cmV2aWV3L3Rlc3RzL3NhbXBsZV9kYXRhX2xhdGluMS5weQ==
review/tests/sample_data_latin1.py ↓
| 0 | + | # coding=utf-8 |
| 1 | + | # |
| 2 | + | |
| 3 | + | log = [ |
| 4 | + | # TODO: Figure out how to make this work. |
| 5 | + | # I hate you, Python. |
| 6 | + | #{ u'fil��'.encode('latin-1'): u'on��\ntw��\nthr��e'.encode('latin-1'), }, |
| 7 | + | #{ u'fil��'.encode('latin-1'): u'��ne\ntwo\nthre��'.encode('latin-1'), }, |
| 8 | + | { u'file'.encode('latin-1'): u'on��\ntw��\nthr��e'.encode('latin-1'), }, |
| 9 | + | { u'file'.encode('latin-1'): u'��ne\ntwo\nthre��'.encode('latin-1'), }, |
| 10 | + | ] |
cmV2aWV3L3Rlc3RzL3NhbXBsZV9kYXRhX3V0ZjgucHk=
review/tests/sample_data_utf8.py ↓
| 0 | + | # coding=utf-8 |
| 1 | + | # |
| 2 | + | |
| 3 | + | log = [ |
| 4 | + | { u'fil��'.encode('UTF-8'): u'on��\ntw��\nthr��e'.encode('UTF-8'), }, |
| 5 | + | { u'fil��'.encode('UTF-8'): u'��ne\ntwo\nthre��'.encode('UTF-8'), }, |
| 6 | + | ] |
cmV2aWV3L3Rlc3RzL3Rlc3RfZW5jb2RpbmcucHk=
review/tests/test_encoding.py ↓
| 0 | # coding=utf-8 |
|
| 1 | # |
|
| 2 | import os |
|
| 3 | |
|
| 4 | + | import unicodedata |
| 5 | + | |
| 6 | from nose import with_setup |
|
| 7 | from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with |
|
| 8 | from util import get_datastore_repo, get_sandbox_repo, get_ui |
|
| 9 | from util import check_comment_exists_on_line |
|
| 10 | |
|
| … skipped 27 lines … | ||
| 37 | review(comment=True, message=rutil.tolocal(u'C��mment.')) |
|
| 38 | output = review() |
|
| 39 | assert u'T��st'.encode('ISO-8859-1') in output |
|
| 40 | assert u'C��mment.'.encode('ISO-8859-1') in output |
|
| 41 | |
|
| 42 | + | @with_setup(setup_reviewed_sandbox(username=u'T��st <t��st@test.com>', encoding='UTF-8', file_encoding='UTF-8'), teardown_sandbox) |
| 43 | + | def test_file_encoding_utf8(): |
| 44 | + | review(comment=True, message=rutil.tolocal(u'C��mment.'), rev='1') |
| 45 | + | |
| 46 | + | output = review(rev='1') |
| 47 | + | normal_output = unicodedata.normalize('NFC', output.decode('UTF-8')) |
| 48 | + | |
| 49 | + | assert unicodedata.normalize('NFC', u'fil��') in normal_output |
| 50 | + | assert u'T��st'.encode('UTF-8') in output |
| 51 | + | assert u'C��mment.'.encode('UTF-8') in output |
| 52 | + | |
| 53 | + | assert u'-on��'.encode('UTF-8') in output |
| 54 | + | assert u'+��ne'.encode('UTF-8') in output |
| 55 | + | |
| 56 | + | assert u'-tw��'.encode('UTF-8') in output |
| 57 | + | assert u'+two'.encode('UTF-8') in output |
| 58 | + | |
| 59 | + | assert u'-thr��e'.encode('UTF-8') in output |
| 60 | + | assert u'+thre��'.encode('UTF-8') in output |
| 61 | + | |
| 62 | + | @with_setup(setup_reviewed_sandbox(username=u'T��st <t��st@test.com>', encoding='latin-1', file_encoding='latin-1'), teardown_sandbox) |
| 63 | + | def test_file_encoding_iso88591(): |
| 64 | + | review(comment=True, message=rutil.tolocal(u'C��mment.'), rev='1') |
| 65 | + | |
| 66 | + | output = review(rev='1') |
| 67 | + | |
| 68 | + | # TODO: Make this work. |
| 69 | + | #normal_output = unicodedata.normalize('NFC', output.decode('latin-1')) |
| 70 | + | |
| 71 | + | #assert unicodedata.normalize('NFC', u'fil��') in normal_output |
| 72 | + | assert u'T��st'.encode('latin-1') in output |
| 73 | + | assert u'C��mment.'.encode('latin-1') in output |
| 74 | + | |
| 75 | + | assert u'-on��'.encode('latin-1') in output |
| 76 | + | assert u'+��ne'.encode('latin-1') in output |
| 77 | + | |
| 78 | + | assert u'-tw��'.encode('latin-1') in output |
| 79 | + | assert u'+two'.encode('latin-1') in output |
| 80 | + | |
| 81 | + | assert u'-thr��e'.encode('latin-1') in output |
| 82 | + | assert u'+thre��'.encode('latin-1') in output |
| 83 | + | |
cmV2aWV3L3Rlc3RzL3V0aWwucHk=
review/tests/util.py ↓
| 0 | + | # coding=utf-8 |
| 1 | + | # |
| 2 | from __future__ import with_statement |
|
| 3 | |
|
| 4 | """Utilities for writing unit tests for hg-review.""" |
|
| 5 | |
|
| 6 | import os, shutil |
|
| 7 | - | import sample_data |
| 8 | + | import sample_data, sample_data_utf8, sample_data_latin1 |
| 9 | + | |
| 10 | from mercurial import commands, hg, ui |
|
| 11 | from mercurial import util as hgutil |
|
| 12 | from mercurial import encoding as _encoding |
|
| 13 | from .. import api, cli, messages, rutil |
|
| 14 | |
|
| … skipped 32 lines … | ||
| 46 | sandbox_path = os.path.join(os.path.realpath('.'), 'sandbox') |
|
| 47 | sandbox_repo_path = os.path.join(sandbox_path, 'original') |
|
| 48 | sandbox_clone_path = os.path.join(sandbox_path, 'clone') |
|
| 49 | |
|
| 50 | |
|
| 51 | - | def setup_sandbox(username=None, encoding=None): |
| 52 | + | def setup_sandbox(username=None, encoding=None, file_encoding=None): |
| 53 | if encoding: |
|
| 54 | _encoding.encoding = encoding |
|
| 55 | |
|
| 56 | os.mkdir(sandbox_path) |
|
| 57 | os.chdir(sandbox_path) |
|
| … skipped 11 lines … | ||
| 68 | sandbox = get_sandbox_repo() |
|
| 69 | |
|
| 70 | opts = { 'addremove': True, 'date': None, |
|
| 71 | 'user': rutil.tolocal(username) if username else 'Test <test@test.com>', |
|
| 72 | 'logfile': None, 'message': "Sandbox commit.", } |
|
| 73 | - | for state in sample_data.log: |
| 74 | - | for filename in state: |
| 75 | + | |
| 76 | + | if file_encoding == 'UTF-8': |
| 77 | + | data = sample_data_utf8 |
| 78 | + | elif file_encoding == 'latin-1': |
| 79 | + | data = sample_data_latin1 |
| 80 | + | else: |
| 81 | + | data = sample_data |
| 82 | + | |
| 83 | + | for state in data.log: |
| 84 | + | for filename, data in state.items(): |
| 85 | + | if file_encoding: |
| 86 | + | filename = filename.decode(file_encoding) |
| 87 | + | else: |
| 88 | + | filename = filename.decode('ascii') |
| 89 | + | |
| 90 | dirname, key = None, filename |
|
| 91 | |
|
| 92 | # Support one-level-deep directories in the sample data. |
|
| 93 | if '/' in filename: |
|
| 94 | dirname, _, filename = filename.partition('/') |
|
| 95 | if not os.path.exists(dirname): |
|
| 96 | os.mkdir(dirname) |
|
| 97 | os.chdir(dirname) |
|
| 98 | |
|
| 99 | - | with open(filename, 'w') as f: |
| 100 | - | f.write(state[key]) |
| 101 | + | with open(filename, 'wb') as f: |
| 102 | + | f.write(data) |
| 103 | |
|
| 104 | if dirname: |
|
| 105 | os.chdir('..') |
|
| 106 | commands.commit(_ui, sandbox, **opts) |
|
| 107 | |
|
| 108 | def setup_reviewed_sandbox(username=None, encoding=None, file_encoding=None): |
|
| 109 | def _setup(): |
|
| 110 | - | setup_sandbox(username, encoding) |
| 111 | + | setup_sandbox(username, encoding, file_encoding) |
| 112 | sandbox = get_sandbox_repo() |
|
| 113 | |
|
| 114 | rpath = os.path.join(sandbox.root, api.DEFAULT_DATASTORE_DIRNAME) |
|
| 115 | review(init=True, remote_path=rpath) |
|
| 116 | |
|
| … skipped 80 lines … | ||