##// END OF EJS Templates
tests: do not change sys.path, it can break loading cext.parsers...
Joerg Sonnenberger -
r40134:8a08aefa default
parent child Browse files
Show More
@@ -1,45 +1,39 b''
1 from __future__ import absolute_import, print_function
1 from __future__ import absolute_import, print_function
2
2
3 import os
4 import sys
5
6 # make it runnable using python directly without run-tests.py
7 sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')]
8
9 # Import something from Mercurial, so the module loader gets initialized.
3 # Import something from Mercurial, so the module loader gets initialized.
10 from mercurial import pycompat
4 from mercurial import pycompat
11 del pycompat # unused for now
5 del pycompat # unused for now
12
6
13 from hgext.lfs import pointer
7 from hgext.lfs import pointer
14
8
15 def tryparse(text):
9 def tryparse(text):
16 r = {}
10 r = {}
17 try:
11 try:
18 r = pointer.deserialize(text)
12 r = pointer.deserialize(text)
19 print('ok')
13 print('ok')
20 except Exception as ex:
14 except Exception as ex:
21 print((b'%s' % ex).decode('ascii'))
15 print((b'%s' % ex).decode('ascii'))
22 if r:
16 if r:
23 text2 = r.serialize()
17 text2 = r.serialize()
24 if text2 != text:
18 if text2 != text:
25 print('reconstructed text differs')
19 print('reconstructed text differs')
26 return r
20 return r
27
21
28 t = (b'version https://git-lfs.github.com/spec/v1\n'
22 t = (b'version https://git-lfs.github.com/spec/v1\n'
29 b'oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1'
23 b'oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1'
30 b'258daaa5e2ca24d17e2393\n'
24 b'258daaa5e2ca24d17e2393\n'
31 b'size 12345\n'
25 b'size 12345\n'
32 b'x-foo extra-information\n')
26 b'x-foo extra-information\n')
33
27
34 tryparse(b'')
28 tryparse(b'')
35 tryparse(t)
29 tryparse(t)
36 tryparse(t.replace(b'git-lfs', b'unknown'))
30 tryparse(t.replace(b'git-lfs', b'unknown'))
37 tryparse(t.replace(b'v1\n', b'v1\n\n'))
31 tryparse(t.replace(b'v1\n', b'v1\n\n'))
38 tryparse(t.replace(b'sha256', b'ahs256'))
32 tryparse(t.replace(b'sha256', b'ahs256'))
39 tryparse(t.replace(b'sha256:', b''))
33 tryparse(t.replace(b'sha256:', b''))
40 tryparse(t.replace(b'12345', b'0x12345'))
34 tryparse(t.replace(b'12345', b'0x12345'))
41 tryparse(t.replace(b'extra-information', b'extra\0information'))
35 tryparse(t.replace(b'extra-information', b'extra\0information'))
42 tryparse(t.replace(b'extra-information', b'extra\ninformation'))
36 tryparse(t.replace(b'extra-information', b'extra\ninformation'))
43 tryparse(t.replace(b'x-foo', b'x_foo'))
37 tryparse(t.replace(b'x-foo', b'x_foo'))
44 tryparse(t.replace(b'oid', b'blobid'))
38 tryparse(t.replace(b'oid', b'blobid'))
45 tryparse(t.replace(b'size', b'size-bytes').replace(b'oid', b'object-id'))
39 tryparse(t.replace(b'size', b'size-bytes').replace(b'oid', b'object-id'))
@@ -1,41 +1,35 b''
1 from __future__ import absolute_import
1 from __future__ import absolute_import
2 from __future__ import print_function
2 from __future__ import print_function
3
3
4 import os
5 import sys
6
7 # make it runnable directly without run-tests.py
8 sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')]
9
10 from mercurial import minifileset
4 from mercurial import minifileset
11
5
12 def check(text, truecases, falsecases):
6 def check(text, truecases, falsecases):
13 f = minifileset.compile(text)
7 f = minifileset.compile(text)
14 for args in truecases:
8 for args in truecases:
15 if not f(*args):
9 if not f(*args):
16 print('unexpected: %r should include %r' % (text, args))
10 print('unexpected: %r should include %r' % (text, args))
17 for args in falsecases:
11 for args in falsecases:
18 if f(*args):
12 if f(*args):
19 print('unexpected: %r should exclude %r' % (text, args))
13 print('unexpected: %r should exclude %r' % (text, args))
20
14
21 check(b'all()', [(b'a.php', 123), (b'b.txt', 0)], [])
15 check(b'all()', [(b'a.php', 123), (b'b.txt', 0)], [])
22 check(b'none()', [], [(b'a.php', 123), (b'b.txt', 0)])
16 check(b'none()', [], [(b'a.php', 123), (b'b.txt', 0)])
23 check(b'!!!!((!(!!all())))', [], [(b'a.php', 123), (b'b.txt', 0)])
17 check(b'!!!!((!(!!all())))', [], [(b'a.php', 123), (b'b.txt', 0)])
24
18
25 check(b'"path:a" & (**.b | **.c)',
19 check(b'"path:a" & (**.b | **.c)',
26 [(b'a/b.b', 0), (b'a/c.c', 0)], [(b'b/c.c', 0)])
20 [(b'a/b.b', 0), (b'a/c.c', 0)], [(b'b/c.c', 0)])
27 check(b'(path:a & **.b) | **.c',
21 check(b'(path:a & **.b) | **.c',
28 [(b'a/b.b', 0), (b'a/c.c', 0), (b'b/c.c', 0)], [])
22 [(b'a/b.b', 0), (b'a/c.c', 0), (b'b/c.c', 0)], [])
29
23
30 check(b'**.bin - size("<20B")',
24 check(b'**.bin - size("<20B")',
31 [(b'b.bin', 21)], [(b'a.bin', 11), (b'b.txt', 21)])
25 [(b'b.bin', 21)], [(b'a.bin', 11), (b'b.txt', 21)])
32
26
33 check(b'!!**.bin or size(">20B") + "path:bin" or !size(">10")',
27 check(b'!!**.bin or size(">20B") + "path:bin" or !size(">10")',
34 [(b'a.bin', 11), (b'b.txt', 21), (b'bin/abc', 11)],
28 [(b'a.bin', 11), (b'b.txt', 21), (b'bin/abc', 11)],
35 [(b'a.notbin', 11), (b'b.txt', 11), (b'bin2/abc', 11)])
29 [(b'a.notbin', 11), (b'b.txt', 11), (b'bin2/abc', 11)])
36
30
37 check(
31 check(
38 b'(**.php and size(">10KB")) | **.zip | ("path:bin" & !"path:bin/README") '
32 b'(**.php and size(">10KB")) | **.zip | ("path:bin" & !"path:bin/README") '
39 b' | size(">1M")',
33 b' | size(">1M")',
40 [(b'a.php', 15000), (b'a.zip', 0), (b'bin/a', 0), (b'bin/README', 1e7)],
34 [(b'a.php', 15000), (b'a.zip', 0), (b'bin/a', 0), (b'bin/README', 1e7)],
41 [(b'a.php', 5000), (b'b.zip2', 0), (b't/bin/a', 0), (b'bin/README', 1)])
35 [(b'a.php', 5000), (b'b.zip2', 0), (b't/bin/a', 0), (b'bin/README', 1)])
General Comments 0
You need to be logged in to leave comments. Login now