Mercurial > hg > WSGraph
annotate tests/doctest.txt @ 50:d837f2031715
notes
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 03 May 2013 09:25:49 -0700 |
parents | d1e9602145fa |
children |
rev | line source |
---|---|
0 | 1 Test WSGraph |
26 | 2 ============ |
0 | 3 |
4 The obligatory imports: | |
5 | |
29 | 6 >>> from wsgraph.model import MemoryCache |
0 | 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 | 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 | 40 >>> graph['A'] == nodeA |
41 True | |
34 | 42 >>> ['A', 'B'] in graph |
43 True | |
44 >>> graph[('A', 'C')] = {'why': "this will add 'C' to the graph"} | |
45 >>> 'C' in graph | |
46 True | |
47 >>> graph['C'] | |
48 {} | |
35 | 49 >>> sorted(graph.nodes()) |
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 |