Commits

John Chandler  committed 95fd657

Added test and code for relationships. Also fixed semi-colon issue with labels

  • Participants
  • Parent commits 16db9b0

Comments (0)

Files changed (2)

File qadpid/writer.py

         """ Write a DOT file to the file object
             Assumes we can start writing at the current location in the file (i.e. append)
         """
+        # Header
         file_object.write( "digraph code_hierarchy {\n" )
 
+        # Labels
         file_id = get_next_file_id()
+        labels  = {}
         for filename in self._code_hierarchy:
-            file_object.write( '  f%s [label="%s"]\n' % ( file_id.next(), filename ) )
-            
+            labels[filename] = "f%s" % file_id.next()
+            file_object.write( '  %s [label="%s"];\n' % ( labels[filename], filename ) )
+
+        # Relationships
+        for filename in self._code_hierarchy:
+            for dependency in self._code_hierarchy[filename]:
+                file_object.write( "  %s -> %s;\n" % ( labels[dependency], labels[filename] ) )
+
+        # Footer
         file_object.write( "}\n" )
 

File tests/test_dot_writer.py

 
     def test_labels( self ):
         """ Tests output of labels i.e. filenames """
-        writer = DOTWriter({ "file1.php": [], "file2.php": [] })
+        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(), '  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__":