comparison tests/test-lfs-pointer.py @ 37928:7cd1e1adc471

tests: port test-lfs-pointer.py to Python 3 The weird bit here is having to import /something/ from Mercurial before we touch hgext.* so that the module loader gets initialized. That's probably a bug we should explore at some point? Differential Revision: https://phab.mercurial-scm.org/D3514
author Augie Fackler <augie@google.com>
date Fri, 27 Apr 2018 12:07:57 -0400
parents 66c5a8cf2868
children 8a08aefa9273
comparison
equal deleted inserted replaced
37927:76d0a343c305 37928:7cd1e1adc471
3 import os 3 import os
4 import sys 4 import sys
5 5
6 # make it runnable using python directly without run-tests.py 6 # make it runnable using python directly without run-tests.py
7 sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')] 7 sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')]
8
9 # Import something from Mercurial, so the module loader gets initialized.
10 from mercurial import pycompat
11 del pycompat # unused for now
8 12
9 from hgext.lfs import pointer 13 from hgext.lfs import pointer
10 14
11 def tryparse(text): 15 def tryparse(text):
12 r = {} 16 r = {}
13 try: 17 try:
14 r = pointer.deserialize(text) 18 r = pointer.deserialize(text)
15 print('ok') 19 print('ok')
16 except Exception as ex: 20 except Exception as ex:
17 print(ex) 21 print((b'%s' % ex).decode('ascii'))
18 if r: 22 if r:
19 text2 = r.serialize() 23 text2 = r.serialize()
20 if text2 != text: 24 if text2 != text:
21 print('reconstructed text differs') 25 print('reconstructed text differs')
22 return r 26 return r
23 27
24 t = ('version https://git-lfs.github.com/spec/v1\n' 28 t = (b'version https://git-lfs.github.com/spec/v1\n'
25 'oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1' 29 b'oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1'
26 '258daaa5e2ca24d17e2393\n' 30 b'258daaa5e2ca24d17e2393\n'
27 'size 12345\n' 31 b'size 12345\n'
28 'x-foo extra-information\n') 32 b'x-foo extra-information\n')
29 33
30 tryparse('') 34 tryparse(b'')
31 tryparse(t) 35 tryparse(t)
32 tryparse(t.replace('git-lfs', 'unknown')) 36 tryparse(t.replace(b'git-lfs', b'unknown'))
33 tryparse(t.replace('v1\n', 'v1\n\n')) 37 tryparse(t.replace(b'v1\n', b'v1\n\n'))
34 tryparse(t.replace('sha256', 'ahs256')) 38 tryparse(t.replace(b'sha256', b'ahs256'))
35 tryparse(t.replace('sha256:', '')) 39 tryparse(t.replace(b'sha256:', b''))
36 tryparse(t.replace('12345', '0x12345')) 40 tryparse(t.replace(b'12345', b'0x12345'))
37 tryparse(t.replace('extra-information', 'extra\0information')) 41 tryparse(t.replace(b'extra-information', b'extra\0information'))
38 tryparse(t.replace('extra-information', 'extra\ninformation')) 42 tryparse(t.replace(b'extra-information', b'extra\ninformation'))
39 tryparse(t.replace('x-foo', 'x_foo')) 43 tryparse(t.replace(b'x-foo', b'x_foo'))
40 tryparse(t.replace('oid', 'blobid')) 44 tryparse(t.replace(b'oid', b'blobid'))
41 tryparse(t.replace('size', 'size-bytes').replace('oid', 'object-id')) 45 tryparse(t.replace(b'size', b'size-bytes').replace(b'oid', b'object-id'))