# HG changeset patch # User Brett Cannon # Date 1427475478 14400 # Node ID 16496e0f3c091820879271137495914ec528c9fa # Parent 2104fc9aa513320587d4900f0074a43d6a62dee4 util: update doctests to work with bytes (issue4520) diff -r 2104fc9aa513 -r 16496e0f3c09 hglib/util.py --- a/hglib/util.py Fri Mar 27 10:45:26 2015 -0400 +++ b/hglib/util.py Fri Mar 27 12:57:58 2015 -0400 @@ -32,14 +32,14 @@ def eatlines(s, n): """ - >>> eatlines("1\\n2", 1) - '2' - >>> eatlines("1\\n2", 2) - '' - >>> eatlines("1\\n2", 3) - '' - >>> eatlines("1\\n2\\n3", 1) - '2\\n3' + >>> eatlines(b("1\\n2"), 1) == b('2') + True + >>> eatlines(b("1\\n2"), 2) == b('') + True + >>> eatlines(b("1\\n2"), 3) == b('') + True + >>> eatlines(b("1\\n2\\n3"), 1) == b('2\\n3') + True """ cs = BytesIO(s) @@ -53,14 +53,14 @@ """ Skip lines starting with prefix in s - >>> skiplines('a\\nb\\na\\n', 'a') - 'b\\na\\n' - >>> skiplines('a\\na\\n', 'a') - '' - >>> skiplines('', 'a') - '' - >>> skiplines('a\\nb', 'b') - 'a\\nb' + >>> skiplines(b('a\\nb\\na\\n'), b('a')) == b('b\\na\\n') + True + >>> skiplines(b('a\\na\\n'), b('a')) == b('') + True + >>> skiplines(b(''), b('a')) == b('') + True + >>> skiplines(b('a\\nb'), b('b')) == b('a\\nb') + True """ cs = BytesIO(s) @@ -174,17 +174,22 @@ """ Decorator that remembers the return value of a function call. + >>> execcount = 0 >>> class obj(object): ... def func(self): - ... print 'func' + ... global execcount + ... execcount += 1 ... return [] ... func = propertycache(func) >>> o = obj() >>> o.func - func [] + >>> execcount + 1 >>> o.func [] + >>> execcount + 1 """ def __init__(self, func): self.func = func