view tests/doctest.txt @ 44:6b1d76a8cac6

JS stuff...
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 12 Apr 2013 09:22:08 -0700
parents d1e9602145fa
children
line wrap: on
line source

Test WSGraph
============

The obligatory imports:

    >>> from wsgraph.model import MemoryCache

Make a graph:

    >>> graph = MemoryCache()

The graph starts off empty:

    >>> graph() == {'nodes': {}, 'edges': {}}
    True
    >>> graph.nodes()
    []
    >>> graph.edges()
    []
    >>> graph.node('A') is None
    True
    >>> graph['A'] is None
    True
    >>> graph.edge('A', 'B') is None
    True
    >>> graph[('A', 'B')] is None
    True
    >>> 'A' in graph
    False
    >>> ('A', 'B') in graph
    False

Let's add stuff to it:

    >>> nodeA = {'hello': "is it me you're looking for?"}
    >>> graph['A'] = nodeA
    >>> graph.edge('A', 'B', dict(foo='bar'))
    >>> 'A' in graph
    True
    >>> graph['A'] == nodeA
    True
    >>> ['A', 'B'] in graph
    True
    >>> graph[('A', 'C')] =  {'why': "this will add 'C' to the graph"}
    >>> 'C' in graph
    True
    >>> graph['C']
    {}
    >>> sorted(graph.nodes())
    ['A', 'B', 'C']

Once you set the value of a node or edge, modifying their data
structure will not affect the graph results:

    >>> values = {'a': 'b', 'c': 'easy as 1..2..3..'}
    >>> graph['C'] = values
    >>> graph.node('C') == values
    True
    >>> values['c'] = 'modifying the values'
    >>> values['d'] = 'adding a new key'
    >>> graph['C']['c']
    'easy as 1..2..3..'
    >>> 'd' in graph['C']
    False

Delete an edge:

    >>> graph = MemoryCache()
    >>> graph[('a', 'b')] = {'key': 'value'}
    >>> graph.edges()
    [('a', 'b')]
    >>> del graph[('a', 'b')]
    >>> graph.edges()
    []