~ubuntu-branches/ubuntu/trusty/python-networkx/trusty-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-12-10 23:50:27 UTC
  • mfrom: (1.2.4 upstream) (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20101210235027-b2supdwo0ad39d3s
Tags: 1.3-1
* New upstream release
* debian/patches/changeset_r1745.diff
  - dropped, available in upstream release
* debian/patches/10_doc_relocation
  - refreshed patch for new upstream code
* debian/control
  - upstream code is now compatible with 2.6 or later only
  - bump Standards-Version to 3.9.1 (no changes needed)
* debian/{control, rules}
  - run unittests at build time, b-d on python-nose added
* debian/copyright
  - removed reference to /usr/share/common-licenses/BSD
* Create a -doc package ; thanks to Yaroslav Halchenko for the report;
  Closes: #567369
  - (d/control) define a new binary package, and add depends on sphinx (>= 1)
  - (d/rules) build documentation, install it into the new -doc package
  - (d/patches/30_use_local_objects.inv) use local copy of remote objects.inv
* debian/{control, rules}
  - moved to dh7 and "reduced" rules file
* debian/rules
  - refer to built code when building doc
* debian/python-networkx-doc.doc-base
  - added doc-base information
* debian/patches/40_add_networkxcss
  - added as patch, since networkx.css is missing from the tarball, but needed
    to display properly HTML documentation
* debian/patches/50_boundary-test-fix.patch
  - upstream patch to restrict node boundary test cases to valid range
* debian/patches/60_remove_svn_refs.diff
  - upstream patch to remove references to old SVN repository (now Mercurial)
* debian/patches/70_set_matplotlib_ps_backend.patch
  - set matplotlib backend to 'PS', so a DISPLAY it's not required and the
    tests can be run in a "reduced" environment

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
Pajek tests
 
4
"""
 
5
 
 
6
from nose.tools import assert_equal, assert_almost_equal
 
7
from networkx import *
 
8
import os,tempfile
 
9
from io import open
 
10
 
 
11
class TestPajek(object):
 
12
    def setUp(self):
 
13
        self.data="""*network Tralala\n*vertices 4\n   1 "A1"         0.0938 0.0896   ellipse x_fact 1 y_fact 1\n   2 "Bb"         0.8188 0.2458   ellipse x_fact 1 y_fact 1\n   3 "C"          0.3688 0.7792   ellipse x_fact 1\n   4 "D2"         0.9583 0.8563   ellipse x_fact 1\n*arcs\n1 1 1  h2 0 w 3 c Blue s 3 a1 -130 k1 0.6 a2 -130 k2 0.6 ap 0.5 l "Bezier loop" lc BlueViolet fos 20 lr 58 lp 0.3 la 360\n2 1 1  h2 0 a1 120 k1 1.3 a2 -120 k2 0.3 ap 25 l "Bezier arc" lphi 270 la 180 lr 19 lp 0.5\n1 2 1  h2 0 a1 40 k1 2.8 a2 30 k2 0.8 ap 25 l "Bezier arc" lphi 90 la 0 lp 0.65\n4 2 -1  h2 0 w 1 k1 -2 k2 250 ap 25 l "Circular arc" c Red lc OrangeRed\n3 4 1  p Dashed h2 0 w 2 c OliveGreen ap 25 l "Straight arc" lc PineGreen\n1 3 1  p Dashed h2 0 w 5 k1 -1 k2 -20 ap 25 l "Oval arc" c Brown lc Black\n3 3 -1  h1 6 w 1 h2 12 k1 -2 k2 -15 ap 0.5 l "Circular loop" c Red lc OrangeRed lphi 270 la 180"""
 
14
        self.G=nx.MultiDiGraph()
 
15
        self.G.add_nodes_from(['A1', 'Bb', 'C', 'D2'])
 
16
        self.G.add_edges_from([('A1', 'A1'), ('A1', 'Bb'), ('A1', 'C'), 
 
17
                               ('Bb', 'A1'),('C', 'C'), ('C', 'D2'), 
 
18
                               ('D2', 'Bb')])
 
19
 
 
20
        (self.fd,self.fname)=tempfile.mkstemp()
 
21
        fh=open(self.fname,'wb')
 
22
        fh.write(self.data.encode('UTF-8'))
 
23
        fh.close()
 
24
 
 
25
    def tearDown(self):
 
26
        os.close(self.fd)
 
27
        os.unlink(self.fname)
 
28
 
 
29
    def test_parse_pajek_simple(self):
 
30
        # Example without node positions or shape
 
31
        data="""*Vertices 2\n1 "1"\n2 "2"\n*Edges\n1 2\n2 1"""
 
32
        G=parse_pajek(data)
 
33
        assert_equal(sorted(G.nodes()), ['1', '2'])
 
34
        assert_equal(sorted(G.edges()), [('1', '2'), ('1', '2')])
 
35
 
 
36
    def test_parse_pajek(self):
 
37
        G=parse_pajek(self.data)
 
38
        assert_equal(sorted(G.nodes()), ['A1', 'Bb', 'C', 'D2'])
 
39
        assert_equal(sorted(G.edges()),
 
40
                     [('A1', 'A1'), ('A1', 'Bb'), ('A1', 'C'), ('Bb', 'A1'),
 
41
                      ('C', 'C'), ('C', 'D2'), ('D2', 'Bb')])
 
42
 
 
43
    def test_read_pajek(self):
 
44
        G=parse_pajek(self.data)
 
45
        Gin=read_pajek(self.fname)
 
46
        assert_equal(sorted(G.nodes()), sorted(Gin.nodes()))
 
47
        assert_equal(sorted(G.edges()), sorted(Gin.edges()))
 
48
        assert_equal(self.G.graph,Gin.graph)
 
49
        for n in G.node:
 
50
            assert_equal(G.node[n],Gin.node[n])