Mercurial > hg
comparison tests/test-ancestor.py @ 28723:18e738038d78
py3: use print_function in test-ancestor.py
author | Robert Stanca <robert.stanca7@gmail.com> |
---|---|
date | Sat, 02 Apr 2016 17:33:11 +0300 |
parents | 4056fdf71aff |
children | 21a507f9a6cd |
comparison
equal
deleted
inserted
replaced
28722:2cd8c3b0bd11 | 28723:18e738038d78 |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import, print_function |
2 | 2 |
3 import binascii | 3 import binascii |
4 import getopt | 4 import getopt |
5 import math | 5 import math |
6 import os | 6 import os |
92 count = min(lognormrandom(mu, sigma), len(nodes)) | 92 count = min(lognormrandom(mu, sigma), len(nodes)) |
93 return rng.sample(nodes, count) | 93 return rng.sample(nodes, count) |
94 | 94 |
95 def err(seed, graph, bases, seq, output, expected): | 95 def err(seed, graph, bases, seq, output, expected): |
96 if nerrs[0] == 0: | 96 if nerrs[0] == 0: |
97 print >> sys.stderr, 'seed:', hex(seed)[:-1] | 97 print('seed:', hex(seed)[:-1], file=sys.stderr) |
98 if gerrs[0] == 0: | 98 if gerrs[0] == 0: |
99 print >> sys.stderr, 'graph:', graph | 99 print('graph:', graph, file=sys.stderr) |
100 print >> sys.stderr, '* bases:', bases | 100 print('* bases:', bases, file=sys.stderr) |
101 print >> sys.stderr, '* seq: ', seq | 101 print('* seq: ', seq, file=sys.stderr) |
102 print >> sys.stderr, '* output: ', output | 102 print('* output: ', output, file=sys.stderr) |
103 print >> sys.stderr, '* expected:', expected | 103 print('* expected:', expected, file=sys.stderr) |
104 nerrs[0] += 1 | 104 nerrs[0] += 1 |
105 gerrs[0] += 1 | 105 gerrs[0] += 1 |
106 | 106 |
107 for g in xrange(graphcount): | 107 for g in xrange(graphcount): |
108 graph = buildgraph(rng) | 108 graph = buildgraph(rng) |
176 graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4], | 176 graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4], |
177 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9], | 177 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9], |
178 13: [8]} | 178 13: [8]} |
179 | 179 |
180 def genlazyancestors(revs, stoprev=0, inclusive=False): | 180 def genlazyancestors(revs, stoprev=0, inclusive=False): |
181 print ("%% lazy ancestor set for %s, stoprev = %s, inclusive = %s" % | 181 print(("%% lazy ancestor set for %s, stoprev = %s, inclusive = %s" % |
182 (revs, stoprev, inclusive)) | 182 (revs, stoprev, inclusive))) |
183 return ancestor.lazyancestors(graph.get, revs, stoprev=stoprev, | 183 return ancestor.lazyancestors(graph.get, revs, stoprev=stoprev, |
184 inclusive=inclusive) | 184 inclusive=inclusive) |
185 | 185 |
186 def printlazyancestors(s, l): | 186 def printlazyancestors(s, l): |
187 print 'membership: %r' % [n for n in l if n in s] | 187 print('membership: %r' % [n for n in l if n in s]) |
188 print 'iteration: %r' % list(s) | 188 print('iteration: %r' % list(s)) |
189 | 189 |
190 def test_lazyancestors(): | 190 def test_lazyancestors(): |
191 # Empty revs | 191 # Empty revs |
192 s = genlazyancestors([]) | 192 s = genlazyancestors([]) |
193 printlazyancestors(s, [3, 0, -1]) | 193 printlazyancestors(s, [3, 0, -1]) |
233 for a in cl: | 233 for a in cl: |
234 for b in cl: | 234 for b in cl: |
235 cgcas = sorted(cl.index.ancestors(a, b)) | 235 cgcas = sorted(cl.index.ancestors(a, b)) |
236 pygcas = sorted(ancestor.ancestors(cl.parentrevs, a, b)) | 236 pygcas = sorted(ancestor.ancestors(cl.parentrevs, a, b)) |
237 if cgcas != pygcas: | 237 if cgcas != pygcas: |
238 print "test_gca: for dag %s, gcas for %d, %d:" % (dag, a, b) | 238 print("test_gca: for dag %s, gcas for %d, %d:" |
239 print " C returned: %s" % cgcas | 239 % (dag, a, b)) |
240 print " Python returned: %s" % pygcas | 240 print(" C returned: %s" % cgcas) |
241 print(" Python returned: %s" % pygcas) | |
241 | 242 |
242 def main(): | 243 def main(): |
243 seed = None | 244 seed = None |
244 opts, args = getopt.getopt(sys.argv[1:], 's:', ['seed=']) | 245 opts, args = getopt.getopt(sys.argv[1:], 's:', ['seed=']) |
245 for o, a in opts: | 246 for o, a in opts: |