#!/usr/bin/env python # # $Id: tests.py,v 1.2 2003/03/16 16:25:05 doughellmann Exp $ # # Copyright 2002 Doug Hellmann. # # # All Rights Reserved # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby # granted, provided that the above copyright notice appear in all # copies and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of Doug # Hellmann not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. # # DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN # NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Tests for HappyDoc. """ __rcs_info__ = { # # Creation Information # 'module_name' : '$RCSfile: tests.py,v $', 'rcs_id' : '$Id: tests.py,v 1.2 2003/03/16 16:25:05 doughellmann Exp $', 'creator' : 'Doug Hellmann ', 'project' : 'UNSPECIFIED', 'created' : 'Sun, 15-Dec-2002 09:39:20 EST', # # Current Information # 'author' : '$Author: doughellmann $', 'version' : '$Revision: 1.2 $', 'date' : '$Date: 2003/03/16 16:25:05 $', } try: __version__ = __rcs_info__['version'].split(' ')[1] except: __version__ = '0.0' # # Import system modules # import os import unittest # # Import Local modules # import happydoclib from happydoclib.scanner import Scanner # # Module # __proctor_ignore_module__ = 1 class HappyDocRunTest(unittest.TestCase): TEST_OUTPUT_DIRECTORY_BASE = 'TestOutput' def getOutputDirectory(self): id = self.id() id_parts = id.split('.') id = os.sep.join(id_parts) output_dir = os.path.join(self.TEST_OUTPUT_DIRECTORY_BASE, id, ) return output_dir def runHappyDoc(self, *args): default_args = ( '-q', '-d', self.getOutputDirectory(), '--title', self.id(), ) #default_args = ( '-d', self.getOutputDirectory(), ) all_args = default_args + args happydoc = happydoclib.HappyDoc(all_args) happydoc.run() return def testAllExpectedFilesCreated(self): # # Run HappyDoc to generate output using our docset. # self.runHappyDoc( '-T', self.TEST_DOCSET, os.path.join('TestCases', 'testScanner') ) # # Scan the output directory to find what files are there. # scanner = Scanner([self.getOutputDirectory()]) # # Build up the list of expected directories, # and make sure they are all present. # root = os.path.join( self.getOutputDirectory(), 'testScanner' ) expected_dirs = [ ('levelOne',), ('levelOne', 'levelTwo'), ] expected_dirs = [ apply(os.path.join, (root,) + ed) for ed in expected_dirs ] for dirname in expected_dirs: self.failUnless(os.path.isdir(dirname), '%s is not a directory' % dirname, ) # # Build up the list of expected files, # and make sure they are all present. # expected_files = [ ('levelOne', 'index.html'), ('levelOne', 'Existing.html'), ('levelOne', 'README.html'), ('levelOne', 'one.html'), ('levelOne', 'levelTwo'), ] expected_files = [ apply(os.path.join, (root,) + ef) for ef in expected_files ] for filename in expected_files: self.failUnless(os.path.exists(filename), '%s does not exist' % filename, ) return def testSelfDoc(self): # # Run HappyDoc against itself. # self.runHappyDoc( '-T', self.TEST_DOCSET, '-i', 'TestCases', '-i', 'TestOutput', '-i', '^tests.py$', '-i', '^test_.*.py$', os.getcwd(), ) # # Create a scanner to find the output files generated. # scanner = Scanner([self.getOutputDirectory()]) root = self.getOutputDirectory() # # Directories to ignore # expected_dirs = [ ('HappyDoc3', 'levelOne',), ('HappyDoc3', 'levelOne', 'levelTwo'), ] expected_dirs = [ apply(os.path.join, (root,) + ed) for ed in expected_dirs ] for dirname in expected_dirs: if os.path.isdir(dirname): self.fail('%s should have been ignored' % dirname) # # Directories to document # expected_dirs = [ ('HappyDoc3', 'happydoclib',), ('HappyDoc3', 'happydoclib', 'docset'), ('HappyDoc3', 'happydoclib', 'docstring'), ('HappyDoc3', 'happydoclib', 'parseinfo'), ] expected_dirs = [ apply(os.path.join, (root,) + ed) for ed in expected_dirs ] for dirname in expected_dirs: if not os.path.isdir(dirname): self.fail('%s should not have been ignored' % dirname) return