~ubuntu-branches/ubuntu/precise/python-networkx/precise

« back to all changes in this revision

Viewing changes to networkx/readwrite/tests/test_yaml.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-02-26 00:20:57 UTC
  • mfrom: (1.3.1 upstream) (5.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20100226002057-c4s3jshtx2o36wtx
Tags: 1.0.1-1
* New upstream release; thanks to Yaroslav Halchenko for the report;
  Closes: #565319
* debian/control
  - take maintainership back under DPMT umbrella; thanks to Cyril Brulebois
    for his work
  - adjust Vcs-{Svn, Browser} to point to DPMT location
  - bump Standards-Version to 3.8.4
    + added debian/README.source
  - replace b-d-i on python-all-dev with python only
  - use HTTP (and not HTTPS) for Homepage field
  - rephrased short description; thanks to Rogério Brito for the report;
    Closes: #557895
* debian/pyversions
  - minimum version set to 2.5
* debian/copyright
  - updated upstream copyright authors and license information
  - update copyright notice for packaging
* debian/watch
  - updated to report numerical (with dots) releases
* debian/patches/20_fix_broken_svn_keyboards
  - removed, fixed upstream
* debian/patches/20_example_dirs_remove
  - don't created empty dirs for examples no more present

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
    Unit tests for yaml.
 
3
"""
 
4
 
 
5
import os,tempfile
 
6
from nose import SkipTest
 
7
from nose.tools import assert_true
 
8
 
 
9
import networkx as nx
 
10
 
 
11
class TestYaml(object):
 
12
    @classmethod
 
13
    def setupClass(cls):
 
14
        global yaml
 
15
        try:
 
16
            import yaml
 
17
        except ImportError:
 
18
            raise SkipTest('yaml not available.')
 
19
 
 
20
    def setUp(self):
 
21
        self.build_graphs()
 
22
 
 
23
    def build_graphs(self):
 
24
        self.G = nx.Graph(name="test")
 
25
        e = [('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
 
26
        self.G.add_edges_from(e)
 
27
        self.G.add_node('g')    
 
28
 
 
29
        self.DG = nx.DiGraph(self.G)
 
30
 
 
31
        self.MG = nx.MultiGraph()
 
32
        self.MG.add_weighted_edges_from([(1,2,5),(1,2,5),(1,2,1),(3,3,42)])
 
33
 
 
34
    def assert_equal(self, G, data=False):
 
35
        (fd, fname) = tempfile.mkstemp()
 
36
        nx.write_yaml(G, fname)
 
37
        Gin = nx.read_yaml(fname);
 
38
 
 
39
        assert_true( sorted(G.nodes())==sorted(Gin.nodes()) )
 
40
        assert_true( sorted(G.edges(data=data))==sorted(Gin.edges(data=data)) )
 
41
 
 
42
        os.close(fd)
 
43
        os.unlink(fname)
 
44
   
 
45
    def testUndirected(self):
 
46
        self.assert_equal(self.G, False)
 
47
 
 
48
    def testDirected(self):
 
49
        self.assert_equal(self.DG, False)
 
50
 
 
51
    def testMultiGraph(self):
 
52
        self.assert_equal(self.MG, True)
 
53