Erlang port protocol
====================

Setup test modules, classes and functions:

    >>> import os
    >>> from erlport.erlproto import Port, Protocol
    >>> from erlport.erlterms import Atom, encode, decode

    >>> class TestProtocol(Protocol):
    ...
    ...     def handle_test(self, value="test"):
    ...         return value

    >>> def get_test_proto(proto, packet=1):
    ...     def test(request):
    ...         r, out_d = os.pipe()
    ...         in_d, w = os.pipe()
    ...         port = Port(packet, descriptors=(r, w))
    ...         port2 = Port(packet, descriptors=(in_d, out_d))
    ...         port2.write(request)
    ...         proto.handle(port, port.read())
    ...         return port2.read()
    ...     return test

Test protocol with different options:

    >>> test = get_test_proto(TestProtocol())
    >>> test((Atom("test"), "value"))
    'value'
    >>> test(Atom("test"))
    'test'
    >>> test("unknown")
    (atom(error), atom(badarg))
    >>> test(Atom("unknown"))
    (atom(error), atom(undef))
    >>> test((Atom("test"), 1, 2))
    (atom(error), atom(function_clause))

    >>> test = get_test_proto(TestProtocol(), packet=2)
    >>> test((Atom("test"), "value"))
    'value'

    >>> test = get_test_proto(TestProtocol(), packet=4)
    >>> test((Atom("test"), "value"))
    'value'
