##// END OF EJS Templates
phabricator: warn if unable to amend, instead of aborting after posting...
phabricator: warn if unable to amend, instead of aborting after posting There was a divergence in behavior here between obsolete and strip based amending. I first noticed the abort when testing outside of the test harness, but then had trouble recreating it here after reverting the code changes. It turns out, strip based amend was successfully amending the public commit after it was posted! It looks like the protection is in the `commit --amend` command, not in the underlying code that it calls. I considered doing a preflight check and aborting. But the locks are only acquired at the end, if amending, and this is too large a section of code to be wrapped in a maybe-it's-held-or-not context manager for my tastes. Additionally, some people do post-push reviews, and amending is the default behavior, so they shouldn't see a misleading error message. The lack of a 'Differential Revision' entry in the commit message breaks a {phabreview} test, so it had to be partially conditionalized.

File last commit:

r37966:3ea3c96a default
r41198:0101a35d default
Show More
test-encoding-func.py
80 lines | 2.3 KiB | text/x-python | PythonLexer
/ tests / test-encoding-func.py
Yuya Nishihara
encoding: add function to test if a str consists of ASCII characters...
r33927 from __future__ import absolute_import
import unittest
from mercurial import (
encoding,
)
class IsasciistrTest(unittest.TestCase):
asciistrs = [
b'a',
b'ab',
b'abc',
b'abcd',
b'abcde',
b'abcdefghi',
b'abcd\0fghi',
]
def testascii(self):
for s in self.asciistrs:
self.assertTrue(encoding.isasciistr(s))
def testnonasciichar(self):
for s in self.asciistrs:
for i in range(len(s)):
t = bytearray(s)
t[i] |= 0x80
self.assertFalse(encoding.isasciistr(bytes(t)))
Yuya Nishihara
encoding: add fast path of from/tolocal() for ASCII strings...
r33928 class LocalEncodingTest(unittest.TestCase):
def testasciifastpath(self):
s = b'\0' * 100
self.assertTrue(s is encoding.tolocal(s))
self.assertTrue(s is encoding.fromlocal(s))
Yuya Nishihara
encoding: add fast path of from/toutf8b() for ASCII strings...
r33929 class Utf8bEncodingTest(unittest.TestCase):
Yuya Nishihara
encoding: fix toutf8b() to resurrect lossy characters even if "\xed" in it...
r37965 def setUp(self):
self.origencoding = encoding.encoding
def tearDown(self):
encoding.encoding = self.origencoding
Yuya Nishihara
encoding: add fast path of from/toutf8b() for ASCII strings...
r33929 def testasciifastpath(self):
s = b'\0' * 100
self.assertTrue(s is encoding.toutf8b(s))
self.assertTrue(s is encoding.fromutf8b(s))
Yuya Nishihara
encoding: fix toutf8b() to resurrect lossy characters even if "\xed" in it...
r37965 def testlossylatin(self):
encoding.encoding = b'ascii'
s = u'\xc0'.encode('utf-8')
l = encoding.tolocal(s)
self.assertEqual(l, b'?') # lossy
self.assertEqual(s, encoding.toutf8b(l)) # utf8 sequence preserved
Yuya Nishihara
encoding: introduce tagging type for non-lossy non-ASCII string...
r37966 def testlosslesslatin(self):
encoding.encoding = b'latin-1'
s = u'\xc0'.encode('utf-8')
l = encoding.tolocal(s)
self.assertEqual(l, b'\xc0') # lossless
self.assertEqual(s, encoding.toutf8b(l)) # convert back to utf-8
Yuya Nishihara
encoding: fix toutf8b() to resurrect lossy characters even if "\xed" in it...
r37965 def testlossy0xed(self):
encoding.encoding = b'euc-kr' # U+Dxxx Hangul
s = u'\ud1bc\xc0'.encode('utf-8')
l = encoding.tolocal(s)
self.assertIn(b'\xed', l)
self.assertTrue(l.endswith(b'?')) # lossy
self.assertEqual(s, encoding.toutf8b(l)) # utf8 sequence preserved
Yuya Nishihara
encoding: introduce tagging type for non-lossy non-ASCII string...
r37966 def testlossless0xed(self):
encoding.encoding = b'euc-kr' # U+Dxxx Hangul
s = u'\ud1bc'.encode('utf-8')
l = encoding.tolocal(s)
self.assertEqual(l, b'\xc5\xed') # lossless
self.assertEqual(s, encoding.toutf8b(l)) # convert back to utf-8
Yuya Nishihara
encoding: add function to test if a str consists of ASCII characters...
r33927 if __name__ == '__main__':
import silenttestrunner
silenttestrunner.main(__name__)