comparison tests/test-trusted.py @ 41497:3028b4073be1

tests: convert ParseError arguments to str on Python 3 Arguments internally are bytes. Printing the exception on Python 3 will include b'' prefixes. This test file uses a .out file, which doesn't support conditional output. The easiest way to get this to pass on Python 3 is to normalize the exception before printing so there are no b'' prefixes. Differential Revision: https://phab.mercurial-scm.org/D5793
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 01 Feb 2019 09:13:39 -0800
parents 73ccba60aaa1
children 2372284d9457
comparison
equal deleted inserted replaced
41496:e095a9688a31 41497:3028b4073be1
220 bprint(b"# parse error") 220 bprint(b"# parse error")
221 f = open(b'.hg/hgrc', 'wb') 221 f = open(b'.hg/hgrc', 'wb')
222 f.write(b'foo') 222 f.write(b'foo')
223 f.close() 223 f.close()
224 224
225 # This is a hack to remove b'' prefixes from ParseError.__bytes__ on
226 # Python 3.
227 def normalizeparseerror(e):
228 if pycompat.ispy3:
229 args = [a.decode('utf-8') for a in e.args]
230 else:
231 args = e.args
232
233 return error.ParseError(*args)
234
225 try: 235 try:
226 testui(user=b'abc', group=b'def', silent=True) 236 testui(user=b'abc', group=b'def', silent=True)
227 except error.ParseError as inst: 237 except error.ParseError as inst:
228 bprint(inst) 238 bprint(normalizeparseerror(inst))
229 239
230 try: 240 try:
231 testui(debug=True, silent=True) 241 testui(debug=True, silent=True)
232 except error.ParseError as inst: 242 except error.ParseError as inst:
233 bprint(inst) 243 bprint(normalizeparseerror(inst))
234 244
235 print() 245 print()
236 bprint(b'# access typed information') 246 bprint(b'# access typed information')
237 with open(b'.hg/hgrc', 'wb') as f: 247 with open(b'.hg/hgrc', 'wb') as f:
238 f.write(b'''\ 248 f.write(b'''\