review/tests/test_encoding.py @ bdfacbcf700e
default tip
Friendlier patch urls & mimetype
Replace /changeset/<revset>/patch/ by /changeset/<revset>.patch and set
the mimetype to text/x-diff.
This helps the browser opening the right application thanks to the
mimetype, and the application to better guess the file type thanks
to the '.patch' extension
author |
Christophe de Vienne <christophe@cdevienne.info> |
date |
Fri, 19 Aug 2016 18:58:14 +0200 |
parents |
cada9aab8b6f |
children |
(none) |
# coding=utf-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
from util import check_comment_exists_on_line
from .. import api, messages, rutil
from mercurial.node import hex
@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_comment_encoding():
review(comment=True, message=rutil.tolocal(u'Téstíng.'))
output = review()
assert messages.REVIEW_LOG_COMMENT_LINE % rutil.tolocal(u'Téstíng.') in output
@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_signoff_encoding():
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
@with_setup(setup_reviewed_sandbox(username=u'Tést <tést@test.com>', 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 <tést@test.com>', 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