annotate tests/doctest.txt @ 40:00aee7b82657

notes
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 11 Apr 2013 13:50:51 -0700
parents d1e9602145fa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cfcfa093e4b4 initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 Test WSGraph
26
60d7e38a20cd mostly notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
2 ============
0
cfcfa093e4b4 initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
cfcfa093e4b4 initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 The obligatory imports:
cfcfa093e4b4 initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
29
2e4ed8e0a103 passing pretend tests
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
6 >>> from wsgraph.model import MemoryCache
0
cfcfa093e4b4 initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
30
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
8 Make a graph:
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
9
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
10 >>> graph = MemoryCache()
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
11
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
12 The graph starts off empty:
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
13
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
14 >>> graph() == {'nodes': {}, 'edges': {}}
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
15 True
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
16 >>> graph.nodes()
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
17 []
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
18 >>> graph.edges()
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
19 []
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
20 >>> graph.node('A') is None
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
21 True
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
22 >>> graph['A'] is None
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
23 True
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
24 >>> graph.edge('A', 'B') is None
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
25 True
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
26 >>> graph[('A', 'B')] is None
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
27 True
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
28 >>> 'A' in graph
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
29 False
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
30 >>> ('A', 'B') in graph
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
31 False
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
32
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
33 Let's add stuff to it:
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
34
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
35 >>> nodeA = {'hello': "is it me you're looking for?"}
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
36 >>> graph['A'] = nodeA
32
943a4b7097af fix tests
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
37 >>> graph.edge('A', 'B', dict(foo='bar'))
30
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
38 >>> 'A' in graph
2fe3933f8eca Yay! we now haz failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
39 True
35
52dedd2a8ffb add some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
40 >>> graph['A'] == nodeA
52dedd2a8ffb add some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
41 True
34
16673636dcb6 wow, testing is fun!
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
42 >>> ['A', 'B'] in graph
16673636dcb6 wow, testing is fun!
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
43 True
16673636dcb6 wow, testing is fun!
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
44 >>> graph[('A', 'C')] = {'why': "this will add 'C' to the graph"}
16673636dcb6 wow, testing is fun!
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
45 >>> 'C' in graph
16673636dcb6 wow, testing is fun!
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
46 True
16673636dcb6 wow, testing is fun!
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
47 >>> graph['C']
16673636dcb6 wow, testing is fun!
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
48 {}
35
52dedd2a8ffb add some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
49 >>> sorted(graph.nodes())
52dedd2a8ffb add some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
50 ['A', 'B', 'C']
36
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
51
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
52 Once you set the value of a node or edge, modifying their data
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
53 structure will not affect the graph results:
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
54
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
55 >>> values = {'a': 'b', 'c': 'easy as 1..2..3..'}
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
56 >>> graph['C'] = values
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
57 >>> graph.node('C') == values
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
58 True
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
59 >>> values['c'] = 'modifying the values'
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
60 >>> values['d'] = 'adding a new key'
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
61 >>> graph['C']['c']
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
62 'easy as 1..2..3..'
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
63 >>> 'd' in graph['C']
5ea58a6ea820 tests for node integrity; TODO: edge integrity
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
64 False
38
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
65
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
66 Delete an edge:
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
67
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
68 >>> graph = MemoryCache()
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
69 >>> graph[('a', 'b')] = {'key': 'value'}
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
70 >>> graph.edges()
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
71 [('a', 'b')]
39
d1e9602145fa rudimentary deletion and notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
72 >>> del graph[('a', 'b')]
d1e9602145fa rudimentary deletion and notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
73 >>> graph.edges()
d1e9602145fa rudimentary deletion and notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
74 []
38
df2a719a9b6e stubbing deletion of nodes + edges
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
75