From: Doug H. <dou...@us...> - 2002-08-24 19:51:05
|
Update of /cvsroot/happydoc/HappyDoc/happydoclib/formatter In directory usw-pr-cvs1:/tmp/cvs-serv18918/happydoclib/formatter Modified Files: fileformatterbase.py Log Message: Improved fix for -d bug (#513850). Index: fileformatterbase.py =================================================================== RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/formatter/fileformatterbase.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** fileformatterbase.py 4 Aug 2002 12:06:06 -0000 1.9 --- fileformatterbase.py 24 Aug 2002 19:51:02 -0000 1.10 *************** *** 119,126 **** --- 119,129 ---- the output path to create a full path. """ + happydoclib.TRACE.into('FileBasedFormatter', 'fixUpOutputFilename', + filename=filename) # # Remove preceding slashes to make name relative # filename = happydoclib.path.removeRelativePrefix(filename) + happydoclib.TRACE.writeVar(filename_after_remove_relative_prefix=filename) # # Apply the path prefix, if required *************** *** 129,132 **** --- 132,137 ---- filename = happydoclib.path.applyPrefixToPath( filename, self.getFilenamePrefix()) + happydoclib.TRACE.writeVar(filename_after_apply_prefix=filename) + happydoclib.TRACE.outof(filename) return filename *************** *** 142,149 **** --- 147,156 ---- filename=filename) filename = self.fixUpOutputFilename(filename) + happydoclib.TRACE.writeVar(filename=filename) # # Set the correct extension for the output file # extension = self.getFilenameExtension() + happydoclib.TRACE.writeVar(extension=extension) # # Build the name *************** *** 163,179 **** happydoclib.TRACE.into('FileBasedFormatter', 'getOutputNameForObject', infoObject=infoObject) if type(infoObject) == types.StringType: ! happydoclib.TRACE.write('string') name = infoObject elif type(infoObject) == types.FileType: ! happydoclib.TRACE.write('file') name = infoObject.name elif infoObject is not None: ! happydoclib.TRACE.write('infoObject') ! name = self.getOutputNameForFile(infoObject.getFullyQualifiedName()) happydoclib.TRACE.write('file for %s' % infoObject.getName()) happydoclib.TRACE.write('is %s' % name) else: ! name = self.getRootNodeName() happydoclib.TRACE.outof(name) return name --- 170,199 ---- happydoclib.TRACE.into('FileBasedFormatter', 'getOutputNameForObject', infoObject=infoObject) + if type(infoObject) == types.StringType: ! happydoclib.TRACE.write('object is a string') name = infoObject + elif type(infoObject) == types.FileType: ! happydoclib.TRACE.write('object is a file') name = infoObject.name + elif infoObject is not None: ! happydoclib.TRACE.write('object is an infoObject') ! #name = self.getOutputNameForFile(infoObject.getFullyQualifiedName()) ! name = apply(happydoclib.path.join, infoObject.getPath() ) ! name = '%s.%s' % (name, self.getFilenameExtension()) happydoclib.TRACE.write('file for %s' % infoObject.getName()) happydoclib.TRACE.write('is %s' % name) + else: ! happydoclib.TRACE.write('object is a root node') ! docset_path = self._docset.getPath() ! if docset_path: ! name = apply(happydoclib.path.join, docset_path ) ! name = happydoclib.path.join(name, self.getRootNodeName()) ! else: ! name = self.getRootNodeName() ! happydoclib.TRACE.outof(name) return name *************** *** 196,200 **** return name - def getFullOutputNameForObject(self, infoObject): """Get the full name, including path, to the object being output. --- 216,219 ---- *************** *** 206,213 **** happydoclib.TRACE.into('FileBasedFormatter', 'getFullOutputNameForObject', infoObject=infoObject) ! obj_output_name = self.getOutputNameForObject(infoObject) ! docset_base_directory = self._docset.getDocsetBaseDirectory() output_base = self._docset.getOutputBaseDirectory() happydoclib.TRACE.writeVar(obj_output_name=obj_output_name) --- 225,241 ---- happydoclib.TRACE.into('FileBasedFormatter', 'getFullOutputNameForObject', infoObject=infoObject) ! ! # ! # Get the basic output name for the object ! # obj_output_name = self.getOutputNameForObject(infoObject) ! # ! # Get the root output directory ! # output_base = self._docset.getOutputBaseDirectory() + # + # Get the base input directory for the docset + # + docset_base_directory = self._docset.getDocsetBaseDirectory() happydoclib.TRACE.writeVar(obj_output_name=obj_output_name) *************** *** 216,267 **** if (not infoObject) and docset_base_directory: - happydoclib.TRACE.write('root node for docset') # ! # Root node for docset # ! output_subdir = happydoclib.path.removePrefix(docset_base_directory, output_base) ! happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! if ( (os.name != 'nt') ! and ! (output_subdir[0] not in (os.sep, ! os.curdir, ! ) ! ) ! ): ! happydoclib.TRACE.write('adding prefix for os %s' % os.name) ! output_subdir = '%s%s' % (os.sep, output_subdir) ! happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! if output_subdir != output_base: ! happydoclib.TRACE.write('output_subdir and output_base do not match') ! if output_subdir[0] == os.sep: ! output_subdir=output_subdir[1:] ! happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! obj_output_sub_path = happydoclib.path.join(output_subdir, obj_output_name) ! happydoclib.TRACE.writeVar(obj_output_sub_path=obj_output_sub_path) ! obj_output_sub_path = self.fixUpOutputFilename(obj_output_sub_path) ! happydoclib.TRACE.writeVar(obj_output_sub_path=obj_output_sub_path) ! name = happydoclib.path.join(output_base, obj_output_sub_path) else: ! happydoclib.TRACE.write('output_subdir and output_base do match') ! name = happydoclib.path.join(output_base, obj_output_name) elif docset_base_directory: - happydoclib.TRACE.write('subnode of docset') # ! # Subnode of docset # ! #file_name = self.getOutputNameForObject(infoObject) ! file_name = obj_output_name ! happydoclib.TRACE.writeVar(file_name=file_name) ! name = happydoclib.path.join(output_base, file_name) ! #name = happydoclib.path.joinWithCommonMiddle( ! # output_base, ! # docset_base_directory, ! # file_name, ! # ) else: ! happydoclib.TRACE.write('other') # # How can we get here? --- 244,345 ---- if (not infoObject) and docset_base_directory: # ! # For a docset root node, just tack the object ! # output name onto the output base directory. # ! happydoclib.TRACE.write('ROOT NODE FOR CURRENT DOCSET') ! # ! # Now reduce docset_base_minux_prefix by the ! # path of the docset itself, so we don't end ! # up with duplicate subdirectory names. ! # ! docset_path = self._docset.getPath() ! if docset_path: ! happydoclib.TRACE.write('removing docset_path') ! docset_path = apply(os.path.join, docset_path) ! len_docset_path = len(docset_path) ! docset_base_minus_prefix = docset_base_directory[:-len_docset_path] ! base = docset_base_minus_prefix else: ! happydoclib.TRACE.write('do not need to remove prefix') ! #base = os.path.join(output_base, docset_base_minus_prefix) ! base = docset_base_directory + happydoclib.TRACE.writeVar( + base=base, + ) + + #name = happydoclib.path.join(output_base, obj_output_name) + name = happydoclib.path.join(base, obj_output_name) + elif docset_base_directory: # ! # Here we have a real HappyDOM based object. # ! happydoclib.TRACE.write('SUBNODE OF DOCSET') ! #obj_parent_path = infoObject.getParent().getPath() ! #obj_parent_path = infoObject.getPath() ! #obj_parent_file_path = apply(os.path.join, obj_parent_path) ! #output_dir = happydoclib.path.join(output_base, obj_parent_file_path) ! ! if type(infoObject) == types.StringType: ! # ! # What we have is a name for an external documentation ! # file, and that file name should include the full ! # path from the docset root down to the file, so ! # just stick the output base on the front and we're ! # done. ! # ! happydoclib.TRACE.write('FILENAME') ! name = os.path.join(output_base, ! infoObject) ! ! else: ! happydoclib.TRACE.write('OBJECT') ! ! # ! # Determine if there is any path component between the ! # docset base and the output base. ! # ! prefix = happydoclib.path.commonPrefix(docset_base_directory, ! output_base, ! ) ! docset_base_minus_prefix = happydoclib.path.removePrefix( ! docset_base_directory, ! prefix, ! ) ! happydoclib.TRACE.writeVar( ! prefix=prefix, ! docset_base_minus_prefix=docset_base_minus_prefix, ! ) ! ! # ! # Now reduce docset_base_minux_prefix by the ! # path of the docset itself, so we don't end ! # up with duplicate subdirectory names. ! # ! docset_path = self._docset.getPath() ! if docset_path: ! happydoclib.TRACE.write('removing docset_path') ! docset_path = apply(os.path.join, docset_path) ! len_docset_path = len(docset_path) ! docset_base_minus_prefix = docset_base_minus_prefix[:-len_docset_path] ! ! happydoclib.TRACE.writeVar( ! prefix=prefix, ! docset_base_minus_prefix=docset_base_minus_prefix, ! docset_path=docset_path, ! ) ! ! name = os.path.join(output_base, ! docset_base_minus_prefix, ! obj_output_name, ! ) ! #name = happydoclib.path.join(output_base, obj_output_name) ! #name = happydoclib.path.join(docset_base_directory, obj_output_name) else: ! happydoclib.TRACE.write('OTHER') # # How can we get here? *************** *** 269,272 **** --- 347,352 ---- name = self.getOutputNameForObject(infoObject) + #name = os.path.normpath(name) + happydoclib.TRACE.outof(name) return name *************** *** 281,284 **** --- 361,367 ---- else: name = self.getOutputNameForFile(filename) + + name = os.path.normpath(name) + return name *************** *** 296,308 **** output_base_dir = os.sep + os.path.join('tmp', 'fakedocset', 'output') def setUp(self): class FakeDocset: def getOutputBaseDirectory(self): return FileFormatterBaseTest.output_base_dir def getDocsetBaseDirectory(self): ! return os.sep + os.path.join('docset', 'base', 'directory') class TestFormatter(FileBasedFormatter): --- 379,405 ---- output_base_dir = os.sep + os.path.join('tmp', 'fakedocset', 'output') + if os.name == 'nt': + output_base_dir_win32 = 'c:\\%s' % output_base_dir[1:] def setUp(self): class FakeDocset: + + def getPath(self): + return [ ] + def getOutputBaseDirectory(self): return FileFormatterBaseTest.output_base_dir def getDocsetBaseDirectory(self): ! return os.path.join(self.getOutputBaseDirectory(), ! 'docset', 'base', 'directory') ! ! class FakeDocsetWin32: ! def getOutputBaseDirectory(self): ! return FileFormatterBaseTest.output_base_dir_win32 ! ! def getDocsetBaseDirectory(self): ! return 'c:\\' + os.path.join('docset', 'base', 'directory') class TestFormatter(FileBasedFormatter): *************** *** 313,316 **** --- 410,414 ---- self.formatter = TestFormatter(FakeDocset()) + self.formatter_win32 = TestFormatter(FakeDocsetWin32()) return *************** *** 324,327 **** --- 422,435 ---- return + if os.name == 'nt': + def testFixUpOutputFilenameFromRootWin32(self): + expected = 'c:\\' + os.path.join('fix', 'up', 'filename') + actual = self.formatter.fixUpOutputFilename( + 'c:\\' + os.path.join('fix', 'up', 'filename') + ) + assert expected == actual, \ + 'Fixed filenames do not match ("%s" vs. "%s").' % (expected, actual) + return + def testFixUpOutputFilenameParentDir(self): expected = os.path.join('fix', 'up', 'filename') *************** *** 349,352 **** --- 457,487 ---- 'Filenames do not match ("%s" vs. "%s").' % (expected, actual) return + + def testGetOutputNameForFile(self): + filename = 'TestCases/test_package_summaries/FromReadme/README.txt' + expected = '%s.%s' % (filename, 'test') + actual = self.formatter.getOutputNameForFile(filename) + assert expected == actual, \ + 'Filenames do not match ("%s" vs. "%s").' % (expected, actual) + return + + def testGetFullOutputNameForFileName(self): + filename = 'TestCases/test_package_summaries/FromReadme/README.txt' + expected = os.path.join(self.output_base_dir, '%s.%s' % (filename, 'test')) + actual = self.formatter.getFullOutputNameForFile(filename) + assert expected == actual, \ + 'Filenames do not match ("%s" vs. "%s").' % (expected, actual) + return + + ## def testGetFullOutputNameForFileObject(self): + ## filename = 'TestCases/test_package_summaries/FromReadme/README.txt' + ## expected = os.path.join(self.output_base_dir, 'docset', 'base', 'directory', filename) + ## actual = self.formatter.getFullOutputNameForObject(filename) + ## assert expected == actual, \ + ## ('Filenames do not match\n' + ## 'Expected: "%s"\n' + ## 'Got: "%s"' % (expected, actual) + ## ) + ## return def testGetOutputNameForObjectNone(self): *************** *** 382,389 **** pass info_obj = FakeInfoObj('myfake', None, 'filename.py', []) ! expected = 'filename.py.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return --- 517,524 ---- pass info_obj = FakeInfoObj('myfake', None, 'filename.py', []) ! expected = 'myfake.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match (\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 395,402 **** parent_obj = FakeInfoObj('myfakeparent', None, 'parent', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) ! expected = 'parent_myfake.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return --- 530,568 ---- parent_obj = FakeInfoObj('myfakeparent', None, 'parent', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) ! expected = 'myfakeparent/myfake.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match (\n"%s"\nvs\n"%s")' % \ ! (expected, actual) ! return ! ! def testGetOutputNameForObjectFullyQualifiedNameMultipleParents(self): ! import happydoclib.happydom ! class FakeInfoObj(happydoclib.happydom.HappyDOM): ! pass ! one = FakeInfoObj('one', None, 'parent', []) ! two = FakeInfoObj('two', one, 'parent', []) ! three = FakeInfoObj('three', two, 'parent', []) ! info_obj = FakeInfoObj('myfake', three, 'filename.py', []) ! expected = os.path.join('one', 'two', 'three', 'myfake.test') ! actual = self.formatter.getOutputNameForObject(info_obj) ! assert expected == actual, \ ! 'Output name for object does not match (\n"%s"\nvs\n"%s")' % \ ! (expected, actual) ! return ! ! def testGetFullOutputNameForObjectFullyQualifiedNameMultipleParents(self): ! import happydoclib.happydom ! class FakeInfoObj(happydoclib.happydom.HappyDOM): ! pass ! one = FakeInfoObj('one', None, 'parent', []) ! two = FakeInfoObj('two', one, 'parent', []) ! three = FakeInfoObj('three', two, 'parent', []) ! info_obj = FakeInfoObj('myfake', three, 'filename.py', []) ! expected = os.path.join(self.output_base_dir, ! 'docset', 'base', 'directory', 'one', 'two', 'three', 'myfake.test') ! actual = self.formatter.getFullOutputNameForObject(info_obj) ! assert expected == actual, \ ! 'Output name for object does not match (\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 431,459 **** class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! info_obj = FakeInfoObj('myfake', None, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'filename.py.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return def testGetFullOutputNameForObjectNone(self): info_obj = None ! expected = os.sep + os.path.join('tmp', ! 'fakedocset', ! 'output', ! 'docset', ! 'base', ! 'directory', ! 'index.test' ! ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ ! (expected, actual) return def testGetFullOutputNameForObjectFullyQualifiedNameOneParent(self): --- 597,662 ---- class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! info_obj = FakeInfoObj('filename', None, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'docset', 'base', 'directory', ! 'filename.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return + if os.name == 'nt': + def testGetFullOutputNameForObjectFullyQualifiedNameRootWin32(self): + import happydoclib + import happydoclib.happydom + happydoclib.TRACE.verboseLevel = 1 + class FakeInfoObj(happydoclib.happydom.HappyDOM): + pass + info_obj = FakeInfoObj('myfake', None, 'filename.py', []) + expected = happydoclib.path.join( + 'c:\\', + os.path.join('tmp', 'fakedocset', 'output', 'filename.py.test') + ) + actual = self.formatter_win32.getFullOutputNameForObject(info_obj) + assert expected == actual, \ + 'Output name for object does not match (expect "%s", got "%s")' % \ + (expected, actual) + return + def testGetFullOutputNameForObjectNone(self): info_obj = None ! expected = os.path.join( ! self.output_base_dir, ! 'docset', 'base', 'directory', ! 'index.test' ! ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! ('Output name for object does not match\n' ! 'Expected: "%s"\n' ! 'Actual: "%s"' % \ ! (expected, actual) ! ) return + + if os.name == 'nt': + def testGetFullOutputNameForObjectNoneWin32(self): + info_obj = None + expected = os.path.join('c:\\', + 'tmp', + 'fakedocset', + 'output', + 'docset', + 'base', + 'directory', + 'index.test' + ) + actual = self.formatter_win32.getFullOutputNameForObject(info_obj) + assert expected == actual, \ + 'Output name for object does not match (expected "%s", got "%s")' % \ + (expected, actual) + return def testGetFullOutputNameForObjectFullyQualifiedNameOneParent(self): *************** *** 461,472 **** class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! parent_obj = FakeInfoObj('myfakeparent', None, 'parent', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'parent_myfake.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return --- 664,676 ---- class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! parent_obj = FakeInfoObj('myfakeparentname', None, 'myfakeparentfilename', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'docset', 'base', 'directory', ! 'myfakeparentname', 'myfake.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 479,483 **** actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match ("%s" vs "%s")' % \ (expected, actual) return --- 683,687 ---- actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 491,497 **** actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match ("%s" vs "%s")' % \ (expected, actual) return ! --- 695,701 ---- actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return ! |