class documentation

Test various FilePath path manipulations.

In particular, note that tests defined on this class instead of on the base class are only run against twisted.python.filepath.

Method createLinks Create several symbolic links to files and directories.
Method setUpFaultyRename Set up a os.rename that will fail with errno.EXDEV on first call. This is used to simulate a cross-device rename failure.
Method test_changed FilePath.changed indicates that the FilePath has changed, but does not re-read the status information from the filesystem until it is queried again via another method, such as getsize.
Method test_chmod FilePath.chmod modifies the permissions of the passed file as expected (using os.stat to check). We use some basic modes that should work everywhere (even on Windows).
Method test_copyToDirectory FilePath.copyTo makes a copy of all the contents of the directory named by that FilePath if it is able to do so.
Method test_copyToDirectoryItself FilePath.copyTo fails with an OSError or IOError (depending on platform, as it propagates errors from open() and write()) when attempting to copy a directory to a child of itself.
Method test_copyToFileClosing If an exception is raised while FilePath.copyTo is copying bytes between two regular files, the source and destination files are closed and the exception propagates to the caller of FilePath.copyTo.
Method test_copyToMissingDestFileClosing If an exception is raised while FilePath.copyTo is trying to open source file to read from, the destination file is closed and the exception is raised to the caller of FilePath.copyTo.
Method test_copyToMissingSource If the source path is missing, FilePath.copyTo raises OSError.
Method test_copyToWithoutSymlink Verify that copying with followLinks=False copies symlinks as symlinks
Method test_copyToWithSymlink Verify that copying with followLinks=True copies symlink targets instead of symlinks
Method test_createBinaryMode FilePath.create should always open (and write to) files in binary mode; line-feed octets should be unmodified.
Method test_crossMountMoveTo moveTo should be able to handle EXDEV error raised by os.rename when trying to move a file on a different mounted filesystem.
Method test_crossMountMoveToWithoutSymlink Verify that moveTo called with followLinks=False actually create another symlink.
Method test_crossMountMoveToWithSymlink By default, when moving a symlink, it should follow the link and actually copy the content of the linked node.
Method test_descendantOnly If ".." is in the sequence passed to FilePath.descendant, InsecurePath is raised.
Method test_existsCache Check that filepath.FilePath.exists correctly restat the object if an operation has occurred in the mean time.
Method test_filePathNotDeprecated While accessing twisted.python.filepath.FilePath.statinfo is deprecated, the filepath itself is not.
Method test_getAndSet Undocumented
Method test_getContentFileClosing If reading from the underlying file raises an exception, FilePath.getContent raises that exception after closing the file.
Method test_getPermissions_POSIX Getting permissions for a file returns a Permissions object for POSIX platforms (which supports separate user, group, and other permissions bits.
Method test_getPermissions_Windows Getting permissions for a file returns a Permissions object in Windows. Windows requires a different test, because user permissions = group permissions = other permissions. Also, chmod may not be able to set the execute bit, so we are skipping tests that set the execute bit.
Method test_linkTo Verify that symlink creates a valid symlink that is both a link and a file if its target is a file, or a directory if its target is a directory.
Method test_linkToErrors Verify linkTo fails in the following case:
Method test_makedirsAcceptsIgnoreExistingDirectory FilePath.makedirs succeeds when called on a directory that already exists and the c{ignoreExistingDirectory} argument is set to True.
Method test_makedirsIgnoreExistingDirectoryExistAlreadyAFile When FilePath.makedirs is called with ignoreExistingDirectory set to True it throws an OSError exceptions if path is a file.
Method test_makedirsMakesDirectoriesRecursively No summary
Method test_makedirsMakesDirectoriesWithIgnoreExistingDirectory Calling FilePath.makedirs with ignoreExistingDirectory set to True has no effect if directory does not exist.
Method test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory When FilePath.makedirs is called with ignoreExistingDirectory set to True it raises an OSError exception if exception errno is not EEXIST.
Method test_makedirsThrowsWithExistentDirectory FilePath.makedirs throws an OSError exception when called on a directory that already exists.
Method test_moveTo Verify that moving an entire directory results into another directory with the same content.
Method test_moveToError Verify error behavior of moveTo: it should raises one of OSError or IOError if you want to move a path into one of its child. It's simply the error raised by the underlying rename system call.
Method test_moveToExistsCache A FilePath that has been moved aside with FilePath.moveTo no longer registers as existing. Its previously non-existent target exists, though, as it was created by the call to moveTo.
Method test_moveToExistsCacheCrossMount The assertion of test_moveToExistsCache should hold in the case of a cross-mount move.
Method test_moveToSizeCache FilePath.moveTo clears its destination's status cache, such that calls to FilePath.getsize after the call to moveTo will report the new size, not the old one.
Method test_moveToSizeCacheCrossMount The assertion of test_moveToSizeCache should hold in the case of a cross-mount move.
Method test_openWithExplicitBinaryMode Due to a bug in Python 2.7 on Windows including multiple 'b' characters in the mode passed to the built-in open() will cause an error. FilePath.open() ensures that only a single 'b' character is included in the mode passed to the built-in open().
Method test_openWithRedundantExplicitBinaryModes Due to a bug in Python 2.7 on Windows including multiple 'b' characters in the mode passed to the built-in open() will cause an error. No matter how many 'b' modes are specified, FilePath.open() ensures that only a single 'b' character is included in the mode passed to the built-in open().
Method test_realpathCyclicalSymlink FilePath.realpath raises filepath.LinkError if the path is a symbolic link which is part of a cycle.
Method test_realpathNoSymlink FilePath.realpath returns the path itself if the path is not a symbolic link.
Method test_realpathSymlink FilePath.realpath returns the path of the ultimate target of a symlink.
Method test_removeDirectory FilePath.remove on a FilePath that refers to a directory will recursively delete its contents.
Method test_removeWithSymlink For a path which is a symbolic link, FilePath.remove just deletes the link, not the target.
Method test_statinfoBitsAreNumbers Verify that file inode/device/nlinks/uid/gid stats are numbers in a POSIX environment
Method test_statinfoBitsNotImplementedInWindows Verify that certain file stats are not available on Windows
Method test_statinfoNumbersAreValid Verify that the right numbers come back from the right accessor methods for file inode/device/nlinks/uid/gid (in a POSIX environment)
Method test_symbolicLink Verify the behavior of the isLink method against links and non-links. Also check that the symbolic link shares the directory property with its target.
Method test_temporarySiblingExtension If FilePath.temporarySibling is given an extension argument, it will produce path objects with that extension appended to their names.
Method test_walkCyclicalSymlink Verify that walking a path with a cyclical symlink raises an error
Method test_walkObeysDescend Verify that when the supplied descend predicate returns False, the target is not traversed.
Method test_walkObeysDescendWithCyclicalSymlinks Verify that, after making a path with cyclical symlinks, when the supplied descend predicate returns False, the target is not traversed, as if it was a simple symlink.
Method test_whetherBlockOrSocket Ensure that a file is not a block or socket
Method testComparison Undocumented
Method testInsecureUNIX Undocumented
Method testInsecureWin32 Undocumented
Method testInsecureWin32Whacky Windows has 'special' filenames like NUL and CON and COM1 and LPR and PRN and ... god knows what else. They can be located anywhere in the filesystem. For obvious reasons, we do not wish to normally permit access to these.
Method testMultiExt Undocumented
Method testOpen Undocumented
Method testPersist Undocumented
Method testPreauthChild Undocumented
Method testSibling Undocumented
Method testStatCache Undocumented
Method testTemporarySibling Undocumented

Inherited from AbstractFilePathTests:

Method setUp Undocumented
Method subdir Undocumented
Method subfile Undocumented
Method test_childrenNonexistentError Verify that children raises the appropriate exception for non-existent directories.
Method test_childrenNotDirectoryError Verify that listdir raises the appropriate exception for attempting to list a file rather than a directory.
Method test_dictionaryKeys Verify that path instances are usable as dictionary keys.
Method test_dictionaryKeyWithString Verify that path instances are usable as dictionary keys which do not clash with their string counterparts.
Method test_invalidSubdir Verify that a subdirectory that doesn't exist is reported as such.
Method test_multipleChildSegments fp.descendant([a, b, c]) returns the same FilePath as is returned by fp.child(a).child(b).child(c).
Method test_newTimesAreFloats Verify that all times returned from the various new time functions are ints (and hopefully therefore 'high precision').
Method test_oldTimesAreInts Verify that all times returned from the various time functions are integers, for compatibility.
Method test_parents FilePath.parents() should return an iterator of every ancestor of the FilePath in question.
Method test_segmentsFromNegative Verify that segmentsFrom notices when the ancestor isn't an ancestor.
Method test_segmentsFromPositive Verify that the segments between two paths are correctly identified.
Method test_validFiles Make sure that we can read existent non-empty files.
Method test_validSubdir Verify that a valid subdirectory will show up as a directory, but not as a file, not as a symlink, and be listable.
Method test_verifyObject Instances of the path type being tested provide IFilePath.
Method test_walk Verify that walking the path gives the same result as the known file hierarchy.
Class Variable f1content Undocumented
Class Variable f2content Undocumented
Instance Variable all Undocumented
Instance Variable cmn Undocumented
Instance Variable now Undocumented
Instance Variable path Undocumented
Instance Variable root Undocumented
Method _mkpath Undocumented

Inherited from BytesTestCase (via AbstractFilePathTests):

Method mktemp Return a temporary path, encoded as bytes.

Inherited from SynchronousTestCase (via AbstractFilePathTests, BytesTestCase):

Method __eq__ Override the comparison defined by the base TestCase which considers instances of the same class with the same _testMethodName to be equal. Since trial puts TestCase instances into a set, that definition of comparison makes it impossible to run the same test method twice...
Method __hash__ Undocumented
Method __init__ Undocumented
Method addCleanup Add the given function to a list of functions to be called after the test has run, but before tearDown.
Method callDeprecated Call a function that should have been deprecated at a specific version and in favor of a specific alternative, and assert that it was thusly deprecated.
Method flushLoggedErrors Remove stored errors received from the log.
Method flushWarnings Remove stored warnings from the list of captured warnings and return them.
Method getDeprecatedModuleAttribute Retrieve a module attribute which should have been deprecated, and assert that we saw the appropriate deprecation warning.
Method getSkip Return the skip reason set on this test, if any is set. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a skip attribute, returns that in a tuple (...
Method getTodo Return a Todo object if the test is marked todo. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a todo attribute, returns that. Returns ...
Method patch Monkey patch an object for the duration of the test.
Method run Run the test case, storing the results in result.
Method runTest If no methodName argument is passed to the constructor, run will treat this method as the thing with the actual test inside.
Method shortDescription Undocumented
Instance Variable failureException An exception class, defaulting to FailTest. If the test method raises this exception, it will be reported as a failure, rather than an exception. All of the assertion methods raise this if the assertion fails.
Instance Variable skip None or a string explaining why this test is to be skipped. If defined, the test will not be run. Instead, it will be reported to the result object as 'skipped' (if the TestResult supports skipping).
Instance Variable suppress None or a list of tuples of (args, kwargs) to be passed to warnings.filterwarnings. Use these to suppress warnings raised in a test. Useful for testing deprecated code. See also util.suppress.
Instance Variable todo None, a string or a tuple of (errors, reason) where errors is either an exception class or an iterable of exception classes, and reason is a string. See Todo or makeTodo for more information.
Method _getSkipReason Return the reason to use for skipping a test method.
Method _getSuppress Returns any warning suppressions set for this test. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a suppress attribute, returns that. ...
Method _installObserver Undocumented
Method _removeObserver Undocumented
Method _run Run a single method, either a test method or fixture.
Method _runCleanups Synchronously run any cleanups which have been added.
Method _runFixturesAndTest Run setUp, a test method, test cleanups, and tearDown.
Instance Variable _cleanups Undocumented
Instance Variable _observer Undocumented
Instance Variable _parents Undocumented
Instance Variable _passed Undocumented
Instance Variable _testMethodName Undocumented
Instance Variable _warnings Undocumented

Inherited from _Assertions (via AbstractFilePathTests, BytesTestCase, SynchronousTestCase):

Method assertAlmostEqual Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.
Method assertApproximates Fail if first - second > tolerance
Method assertEqual Fail the test if first and second are not equal.
Method assertFalse Fail the test if condition evaluates to True.
Method assertIn Fail the test if containee is not found in container.
Method assertIs Fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.
Method assertIsInstance Fail if instance is not an instance of the given class or of one of the given classes.
Method assertIsNot Fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.
Method assertNoResult Assert that deferred does not have a result at this point.
Method assertNotAlmostEqual Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.
Method assertNotEqual Fail the test if first == second.
Method assertNotIn Fail the test if containee is found in container.
Method assertNotIsInstance Fail if instance is an instance of the given class or of one of the given classes.
Method assertNotSubstring Fail if astring contains substring.
Method assertRaises Fail the test unless calling the function f with the given args and kwargs raises exception. The failure will report the traceback and call stack of the unexpected exception.
Method assertSubstring Fail if substring does not exist within astring.
Method assertTrue Fail the test if condition evaluates to False.
Method assertWarns Fail if the given function doesn't generate the specified warning when called. It calls the function, checks the warning, and forwards the result of the function if everything is fine.
Method fail Absolutely fail the test. Do not pass go, do not collect $200.
Method failureResultOf Return the current failure result of deferred or raise self.failureException.
Method successResultOf Return the current success result of deferred or raise self.failureException.
def createLinks(self): (source)

Create several symbolic links to files and directories.

def setUpFaultyRename(self): (source)

Set up a os.rename that will fail with errno.EXDEV on first call. This is used to simulate a cross-device rename failure.

Returns
list of tuplea list of pair (src, dest) of calls to os.rename
def test_changed(self): (source)

FilePath.changed indicates that the FilePath has changed, but does not re-read the status information from the filesystem until it is queried again via another method, such as getsize.

def test_chmod(self): (source)

FilePath.chmod modifies the permissions of the passed file as expected (using os.stat to check). We use some basic modes that should work everywhere (even on Windows).

def test_copyToDirectory(self): (source)

FilePath.copyTo makes a copy of all the contents of the directory named by that FilePath if it is able to do so.

def test_copyToDirectoryItself(self): (source)

FilePath.copyTo fails with an OSError or IOError (depending on platform, as it propagates errors from open() and write()) when attempting to copy a directory to a child of itself.

def test_copyToFileClosing(self): (source)

If an exception is raised while FilePath.copyTo is copying bytes between two regular files, the source and destination files are closed and the exception propagates to the caller of FilePath.copyTo.

def test_copyToMissingDestFileClosing(self): (source)

If an exception is raised while FilePath.copyTo is trying to open source file to read from, the destination file is closed and the exception is raised to the caller of FilePath.copyTo.

def test_copyToMissingSource(self): (source)

If the source path is missing, FilePath.copyTo raises OSError.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_copyToWithoutSymlink(self): (source)

Verify that copying with followLinks=False copies symlinks as symlinks

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_copyToWithSymlink(self): (source)

Verify that copying with followLinks=True copies symlink targets instead of symlinks

def test_createBinaryMode(self): (source)

FilePath.create should always open (and write to) files in binary mode; line-feed octets should be unmodified.

(While this test should pass on all platforms, it is only really interesting on platforms which have the concept of binary mode, i.e. Windows platforms.)

def test_crossMountMoveTo(self): (source)

moveTo should be able to handle EXDEV error raised by os.rename when trying to move a file on a different mounted filesystem.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_crossMountMoveToWithoutSymlink(self): (source)

Verify that moveTo called with followLinks=False actually create another symlink.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_crossMountMoveToWithSymlink(self): (source)

By default, when moving a symlink, it should follow the link and actually copy the content of the linked node.

def test_descendantOnly(self): (source)

If ".." is in the sequence passed to FilePath.descendant, InsecurePath is raised.

def test_existsCache(self): (source)

Check that filepath.FilePath.exists correctly restat the object if an operation has occurred in the mean time.

def test_filePathNotDeprecated(self): (source)

While accessing twisted.python.filepath.FilePath.statinfo is deprecated, the filepath itself is not.

def test_getAndSet(self): (source)

Undocumented

def test_getContentFileClosing(self): (source)

If reading from the underlying file raises an exception, FilePath.getContent raises that exception after closing the file.

@skipIf(platform.isWindows(), 'Test does not run on Windows')
def test_getPermissions_POSIX(self): (source)

Getting permissions for a file returns a Permissions object for POSIX platforms (which supports separate user, group, and other permissions bits.

@skipIf(not platform.isWindows(), 'Test will run only on Windows')
def test_getPermissions_Windows(self): (source)

Getting permissions for a file returns a Permissions object in Windows. Windows requires a different test, because user permissions = group permissions = other permissions. Also, chmod may not be able to set the execute bit, so we are skipping tests that set the execute bit.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_linkTo(self): (source)

Verify that symlink creates a valid symlink that is both a link and a file if its target is a file, or a directory if its target is a directory.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_linkToErrors(self): (source)

Verify linkTo fails in the following case:

  • the target is in a directory that doesn't exist
  • the target already exists
def test_makedirsAcceptsIgnoreExistingDirectory(self): (source)

FilePath.makedirs succeeds when called on a directory that already exists and the c{ignoreExistingDirectory} argument is set to True.

def test_makedirsIgnoreExistingDirectoryExistAlreadyAFile(self): (source)

When FilePath.makedirs is called with ignoreExistingDirectory set to True it throws an OSError exceptions if path is a file.

def test_makedirsMakesDirectoriesRecursively(self): (source)
def test_makedirsMakesDirectoriesWithIgnoreExistingDirectory(self): (source)

Calling FilePath.makedirs with ignoreExistingDirectory set to True has no effect if directory does not exist.

def test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory(self): (source)

When FilePath.makedirs is called with ignoreExistingDirectory set to True it raises an OSError exception if exception errno is not EEXIST.

def test_makedirsThrowsWithExistentDirectory(self): (source)

FilePath.makedirs throws an OSError exception when called on a directory that already exists.

def test_moveTo(self): (source)

Verify that moving an entire directory results into another directory with the same content.

def test_moveToError(self): (source)

Verify error behavior of moveTo: it should raises one of OSError or IOError if you want to move a path into one of its child. It's simply the error raised by the underlying rename system call.

def test_moveToExistsCache(self): (source)

A FilePath that has been moved aside with FilePath.moveTo no longer registers as existing. Its previously non-existent target exists, though, as it was created by the call to moveTo.

def test_moveToExistsCacheCrossMount(self): (source)

The assertion of test_moveToExistsCache should hold in the case of a cross-mount move.

def test_moveToSizeCache(self, hook=(lambda : None)): (source)

FilePath.moveTo clears its destination's status cache, such that calls to FilePath.getsize after the call to moveTo will report the new size, not the old one.

This is a separate test from test_moveToExistsCache because it is intended to cover the fact that the destination's cache is dropped; test_moveToExistsCache doesn't cover this case because (currently) a file that doesn't exist yet does not cache the fact of its non- existence.

def test_moveToSizeCacheCrossMount(self): (source)

The assertion of test_moveToSizeCache should hold in the case of a cross-mount move.

def test_openWithExplicitBinaryMode(self): (source)

Due to a bug in Python 2.7 on Windows including multiple 'b' characters in the mode passed to the built-in open() will cause an error. FilePath.open() ensures that only a single 'b' character is included in the mode passed to the built-in open().

See http://bugs.python.org/issue7686 for details about the bug.

def test_openWithRedundantExplicitBinaryModes(self): (source)

Due to a bug in Python 2.7 on Windows including multiple 'b' characters in the mode passed to the built-in open() will cause an error. No matter how many 'b' modes are specified, FilePath.open() ensures that only a single 'b' character is included in the mode passed to the built-in open().

See http://bugs.python.org/issue7686 for details about the bug.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_realpathCyclicalSymlink(self): (source)

FilePath.realpath raises filepath.LinkError if the path is a symbolic link which is part of a cycle.

def test_realpathNoSymlink(self): (source)

FilePath.realpath returns the path itself if the path is not a symbolic link.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_realpathSymlink(self): (source)

FilePath.realpath returns the path of the ultimate target of a symlink.

def test_removeDirectory(self): (source)

FilePath.remove on a FilePath that refers to a directory will recursively delete its contents.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_removeWithSymlink(self): (source)

For a path which is a symbolic link, FilePath.remove just deletes the link, not the target.

@skipIf(platform.isWindows(), 'Test does not run on Windows')
def test_statinfoBitsAreNumbers(self): (source)

Verify that file inode/device/nlinks/uid/gid stats are numbers in a POSIX environment

@skipIf(not platform.isWindows(), 'Test will run only on Windows')
def test_statinfoBitsNotImplementedInWindows(self): (source)

Verify that certain file stats are not available on Windows

@skipIf(platform.isWindows(), 'Test does not run on Windows')
def test_statinfoNumbersAreValid(self): (source)

Verify that the right numbers come back from the right accessor methods for file inode/device/nlinks/uid/gid (in a POSIX environment)

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_symbolicLink(self): (source)

Verify the behavior of the isLink method against links and non-links. Also check that the symbolic link shares the directory property with its target.

def test_temporarySiblingExtension(self): (source)

If FilePath.temporarySibling is given an extension argument, it will produce path objects with that extension appended to their names.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_walkCyclicalSymlink(self): (source)

Verify that walking a path with a cyclical symlink raises an error

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_walkObeysDescend(self): (source)

Verify that when the supplied descend predicate returns False, the target is not traversed.

@skipIf(symlinkSkip, 'Platform does not support symlinks')
def test_walkObeysDescendWithCyclicalSymlinks(self): (source)

Verify that, after making a path with cyclical symlinks, when the supplied descend predicate returns False, the target is not traversed, as if it was a simple symlink.

def test_whetherBlockOrSocket(self): (source)

Ensure that a file is not a block or socket

def testComparison(self): (source)

Undocumented

def testInsecureUNIX(self): (source)

Undocumented

@skipIf((platform.getType() != 'win32'), 'Test will run only on Windows.')
def testInsecureWin32(self): (source)

Undocumented

@skipIf((platform.getType() != 'win32'), 'Test will run only on Windows.')
def testInsecureWin32Whacky(self): (source)

Windows has 'special' filenames like NUL and CON and COM1 and LPR and PRN and ... god knows what else. They can be located anywhere in the filesystem. For obvious reasons, we do not wish to normally permit access to these.

def testMultiExt(self): (source)

Undocumented

def testOpen(self): (source)

Undocumented

def testPersist(self): (source)

Undocumented

def testPreauthChild(self): (source)

Undocumented

def testSibling(self): (source)

Undocumented

def testStatCache(self): (source)

Undocumented

def testTemporarySibling(self): (source)

Undocumented