qadpid / tests / test_dot_writer.py

"""
DOT writer tests

Copyright 2011 John Chandler
This software is distributed under the terms of the GNU General Public License version 3
"""

import unittest
from StringIO import StringIO

from qadpid.writer import DOTWriter


class TestDOTWriter( unittest.TestCase ):
    """ Tests for DOT writer """
    def setUp( self ):
        self.output_file = StringIO()

    def tearDown( self ):
        self.output_file.close()
        
    def test_minimal_file( self ):
        """ Tests output when no hierarchy """
        writer = DOTWriter({})
        writer.write( self.output_file )
        self.output_file.seek(0)  # rewind to the beginning

        self.assertEquals( self.output_file.readline(), "digraph code_hierarchy {\n" )
        self.assertEquals( self.output_file.readline(), "}\n" )

    def test_labels( self ):
        """ Tests output of labels i.e. filenames """
        writer = DOTWriter({ "file1.php": [],
                             "file2.php": []
                           })
        
        writer.write( self.output_file )
        
        self.output_file.seek(0)  # rewind to the beginning

        self.assertEquals( self.output_file.readline(), "digraph code_hierarchy {\n" )
        self.assertEquals( self.output_file.readline(), '  f1 [label="file1.php"];\n' )
        self.assertEquals( self.output_file.readline(), '  f2 [label="file2.php"];\n' )
        self.assertEquals( self.output_file.readline(), "}\n" )

    def test_relationships( self ):
        """ Tests output of relationships """
        writer = DOTWriter({ "file1.php": ["file2.php"],
                             "file2.php": []
                           })
        
        writer.write( self.output_file )
        
        self.output_file.seek(0)  # rewind to the beginning

        self.assertEquals( self.output_file.readline(), "digraph code_hierarchy {\n" )
        self.assertEquals( self.output_file.readline(), '  f1 [label="file1.php"];\n' )
        self.assertEquals( self.output_file.readline(), '  f2 [label="file2.php"];\n' )
        self.assertEquals( self.output_file.readline(), "  f2 -> f1;\n" )
        self.assertEquals( self.output_file.readline(), "}\n" )
        
    

if __name__ == "__main__":
    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.