tests/test-wireproto.py
author Chris Jerdonek <chris.jerdonek@gmail.com>
Tue, 31 Dec 2013 00:37:16 -0800
changeset 20740 535283a7f5dd
parent 20686 c69f62906358
child 25708 d3d32643c060
permissions -rw-r--r--
debuginstall: add Python information to debuginstall output (issue4128) This change adds to the output of "hg debuginstall" information about the Python being used by Mercurial. It adds both the path to the Python executable (i.e. the value of sys.executable) and the version of Python (specifically the major, minor, and micro versions). Below is an example of what the output looks like after this change. The marked lines are the new output lines: $ hg debuginstall checking encoding (UTF-8)... -->showing Python executable (/Users/chris/.virtualenvs/default/bin/python) -->showing Python version (2.7.6) checking Python lib (/Users/chris/.virtualenvs/default/lib/python2.7)... checking installed modules (/Users/chris/mercurial)... checking templates (/Users/chris/mercurial/templates)... checking commit editor... checking username... no problems detected Note that we use the word "showing" without an ellipsis for the new lines because, unlike the other lines (except for "Python lib" which will be adjusted in a subsequent commit), no check follows the display of this information.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14622
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     1
from mercurial import wireproto
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     2
14764
a7d5816087a9 classes: fix class style problems found by b071cd58af50
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14622
diff changeset
     3
class proto(object):
14622
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     4
    def __init__(self, args):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     5
        self.args = args
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     6
    def getargs(self, spec):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     7
        args = self.args
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     8
        args.setdefault('*', {})
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
     9
        names = spec.split()
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    10
        return [args[n] for n in names]
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    11
17192
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14765
diff changeset
    12
class clientpeer(wireproto.wirepeer):
14622
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    13
    def __init__(self, serverrepo):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    14
        self.serverrepo = serverrepo
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    15
    def _call(self, cmd, **args):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    16
        return wireproto.dispatch(self.serverrepo, proto(args), cmd)
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    17
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    18
    @wireproto.batchable
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    19
    def greet(self, name):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    20
        f = wireproto.future()
20686
c69f62906358 test-wireproto: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents: 18278
diff changeset
    21
        yield {'name': mangle(name)}, f
14622
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    22
        yield unmangle(f.value)
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    23
14764
a7d5816087a9 classes: fix class style problems found by b071cd58af50
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14622
diff changeset
    24
class serverrepo(object):
14622
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    25
    def greet(self, name):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    26
        return "Hello, " + name
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    27
18278
753acee7d6dd clfilter: make localpeer use a repo with "unserved" filter
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17192
diff changeset
    28
    def filtered(self, name):
753acee7d6dd clfilter: make localpeer use a repo with "unserved" filter
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17192
diff changeset
    29
        return self
753acee7d6dd clfilter: make localpeer use a repo with "unserved" filter
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17192
diff changeset
    30
14622
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    31
def mangle(s):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    32
    return ''.join(chr(ord(c) + 1) for c in s)
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    33
def unmangle(s):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    34
    return ''.join(chr(ord(c) - 1) for c in s)
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    35
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    36
def greet(repo, proto, name):
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    37
    return mangle(repo.greet(unmangle(name)))
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    38
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    39
wireproto.commands['greet'] = (greet, 'name',)
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    40
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    41
srv = serverrepo()
17192
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14765
diff changeset
    42
clt = clientpeer(srv)
14622
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    43
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    44
print clt.greet("Foobar")
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    45
b = clt.batch()
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    46
fs = [b.greet(s) for s in ["Fo, =;o", "Bar"]]
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    47
b.submit()
bd88561afb4b wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
    48
print [f.value for f in fs]