root / trunk / pyopencoin / oc / __init__.py

Revision 196, 3.3 kB (checked in by ocjhb, 4 years ago)

goodbye / done is now used all over

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1"""
2This some playground for me to understand some of the problems involved in getting
3our system working.
4
5This is basically taking Mathews ideas (as far as I understood them), adding a bit of
6my little ideas, and coming to the following idea:
7
8- Protocols that are basically state machines (or workflow engines, me is coming
9  from a plone background). So you have a protocol, which has a state and can consume messages.
10
11- Messages are little objects that have a type and carry data. They can serialize themselves,
12  e.g. to Json.
13
14- Transports, that bascially reflect one side of a communication. They transport messages,
15  and are hooked to protocols. A protocol writes to a transport, and the transport stuffs
16  new messages into the the protocol when it gets some.
17
18- Entities like Wallets. These will then do things, as triggered by the gui (no gui yet)
19
20Testing is done by using a TestTransport, which basically can be connected to any other
21transport (end) to manually communicate with the other side. Check the TestTransport
22for the use of send instead of write!
23
24This alltogether should allow something along the line of:
25    >>> from entities import Wallet
26    >>> from transports import SimpleTestTransport
27
28    >>> w = Wallet()
29    >>> tt = SimpleTestTransport()
30   
31    Pass the wallets side transport to the wallet. With sendMoney it will
32    immediately start to communicate
33    >>> w.sendMoney(tt)
34
35    See, it sends us (we are the other side, pretending to be a wallet
36    receiving money) a message. These are no real messages at all
37    >>> tt.read()
38    <Message('sendMoney',[1, 2])>
39   
40    Any new messages, after we have been doing nothing?
41    >>> tt.read()
42
43    Nope, there weren't. Lets send some nonsense
44    >>> #tt.send('foobar')
45    <Message('PROTOCOL_ERROR','send again')>
46
47    Ok, the protocol does not like other message, but wanted us
48    to send a receipt. If it insists...
49    >>> tt.send('Receipt')
50    <Message('GOODBYE',None)>
51
52    This was so fun, lets see if we can do some more?
53    >>> tt.send('GOODBYE')
54
55    Ok, we are done
56   
57"""
58def _test():
59
60    """You can use python __init__.py [-v] module[.class] to run
61    only selected tests"""
62
63    import doctest,sys
64    import protocols, messages, entities, transports, containers,tests
65
66    if len(sys.argv) > 1 and sys.argv[-1] != '-v':
67        name = sys.argv[-1]
68        gb = globals()
69        gb.update(locals())
70        verbose = '-v' in sys.argv
71        if '.' in name:
72            m,c = name.split('.')
73            mod = gb[m]           
74            obj = getattr(mod,c)
75            gb = mod.__dict__
76            doctest.run_docstring_examples(obj,gb,verbose,name,optionflags=doctest.ELLIPSIS)
77        else:
78            obj = gb[name]
79            doctest.testmod(obj,optionflags=doctest.ELLIPSIS)
80    else:       
81        #doctest.testmod(optionflags=doctest.ELLIPSIS)
82        doctest.testmod(optionflags=doctest.ELLIPSIS)
83        doctest.testmod(protocols,optionflags=doctest.ELLIPSIS)
84        doctest.testmod(messages,optionflags=doctest.ELLIPSIS)
85        doctest.testmod(entities,optionflags=doctest.ELLIPSIS)
86        doctest.testmod(transports,optionflags=doctest.ELLIPSIS)
87        doctest.testmod(containers,optionflags=doctest.ELLIPSIS)
88        doctest.testmod(tests,optionflags=doctest.ELLIPSIS)
89
90if __name__ == "__main__":
91    _test()
Note: See TracBrowser for help on using the browser.