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 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 symlink Create a symbolic link named name pointing at target.
Method createLinks Create several symbolic links to files and directories.
Method test_realpathSymlink FilePath.realpath returns the path of the ultimate target of a symlink.
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_walkCyclicalSymlink Verify that walking a path with a cyclical symlink raises an error
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_walkObeysDescend Verify that when the supplied descend predicate returns False, the target is not traversed.
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_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_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: - the target is in a directory that doesn't exist - the target already exists
Method testMultiExt Undocumented
Method testPreauthChild Undocumented
Method testStatCache Undocumented
Method testPersist Undocumented
Method testInsecureUNIX Undocumented
Method testInsecureWin32 Undocumented
Method testInsecureWin32Whacky No summary
Method testComparison Undocumented
Method test_descendantOnly If ".." is in the sequence passed to FilePath.descendant, InsecurePath is raised.
Method testSibling Undocumented
Method testTemporarySibling Undocumented
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_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_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_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_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_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_copyToWithSymlink Verify that copying with followLinks=True copies symlink targets instead of symlinks
Method test_copyToWithoutSymlink Verify that copying with followLinks=False copies symlinks as symlinks
Method test_copyToMissingSource If the source path is missing, FilePath.copyTo raises OSError.
Method test_moveTo Verify that moving an entire directory results into another directory with the same content.
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_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 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_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_crossMountMoveToWithSymlink By default, when moving a symlink, it should follow the link and actually copy the content of the linked node.
Method test_crossMountMoveToWithoutSymlink Verify that moveTo called with followLinks=False actually create another symlink.
Method test_createBinaryMode FilePath.create should always open (and write to) files in binary mode; line-feed octets should be unmodified.
Method testOpen Undocumented
Method test_openWithExplicitBinaryMode No summary
Method test_openWithRedundantExplicitBinaryModes No summary
Method test_existsCache Check that filepath.FilePath.exists correctly restat the object if an operation has occurred in the mean time.
Method test_makedirsMakesDirectoriesRecursively C{FilePath.makedirs} creates a directory at C{path}}, including recursively creating all parent directories leading up to the path.
Method test_makedirsMakesDirectoriesWithIgnoreExistingDirectory Calling FilePath.makedirs with ignoreExistingDirectory set to True has no effect if directory does not exist.
Method test_makedirsThrowsWithExistentDirectory FilePath.makedirs throws an OSError exception when called on a directory that already exists.
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_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory When FilePath.makedirs is called with ignoreExistingDirectory set to True it raises an OSError exception if exception errno is not EEXIST.
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_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_deprecateStatinfoGetter Getting twisted.python.filepath.FilePath.statinfo is deprecated.
Method test_deprecateStatinfoSetter Setting twisted.python.filepath.FilePath.statinfo is deprecated.
Method test_deprecateStatinfoSetterSets Setting twisted.python.filepath.FilePath.statinfo changes the value of _statinfo such that getting statinfo again returns the new value.
Method test_filePathNotDeprecated While accessing twisted.python.filepath.FilePath.statinfo is deprecated, the filepath itself is not.
Method test_getPermissions_Windows No summary
Method test_whetherBlockOrSocket Ensure that a file is not a block or socket
Method test_statinfoBitsNotImplementedInWindows Verify that certain file stats are not available on Windows
Method test_statinfoBitsAreNumbers Verify that file inode/device/nlinks/uid/gid stats are numbers in a POSIX environment
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)

Inherited from AbstractFilePathTests:

Method subdir Undocumented
Method subfile Undocumented
Method setUp Undocumented
Method test_verifyObject Instances of the path type being tested provide IFilePath.
Method test_segmentsFromPositive Verify that the segments between two paths are correctly identified.
Method test_segmentsFromNegative Verify that segmentsFrom notices when the ancestor isn't an ancestor.
Method test_walk Verify that walking the path gives the same result as the known file hierarchy.
Method test_parents FilePath.parents() should return an iterator of every ancestor of the FilePath in question.
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_invalidSubdir Verify that a subdirectory that doesn't exist is reported as such.
Method test_validFiles Make sure that we can read existent non-empty files.
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_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_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_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 _mkpath Undocumented

Inherited from BytesTestCase (via AbstractFilePathTests):

Method mktemp Return a temporary path, encoded as bytes.

Inherited from SynchronousTestCase (via AbstractFilePathTests, BytesTestCase):

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 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.
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.
Method __init__ Undocumented
Method __eq__ No summary
Method __ne__ Undocumented
Method __hash__ Undocumented
Method shortDescription Undocumented
Method getSkip No summary
Method getTodo No summary
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 run Run the test case, storing the results in result.
Method addCleanup Add the given function to a list of functions to be called after the test has run, but before tearDown.
Method patch Monkey patch an object for the duration of the test.
Method flushLoggedErrors Remove stored errors received from the log.
Method flushWarnings Remove stored warnings from the list of captured warnings and return them.
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 _getSuppress No summary
Method _getSkipReason Return the reason to use for skipping a test method.
Method _run Run a single method, either a test method or fixture.
Method _runFixturesAndTest Run setUp, a test method, test cleanups, and tearDown.
Method _runCleanups Synchronously run any cleanups which have been added.
Method _installObserver Undocumented
Method _removeObserver Undocumented

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

Method fail Absolutely fail the test. Do not pass go, do not collect $200.
Method assertFalse Fail the test if condition evaluates to True.
Method assertTrue Fail the test if condition evaluates to False.
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 assertEqual Fail the test if first and second are not equal.
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 assertIsNot Fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.
Method assertNotEqual Fail the test if first == second.
Method assertIn Fail the test if containee is not found in container.
Method assertNotIn Fail the test if containee is found in container.
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 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 assertSubstring Fail if substring does not exist within astring.
Method assertNotSubstring Fail if astring contains substring.
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 assertIsInstance Fail if instance is not an instance of the given class or of one of the given classes.
Method assertNotIsInstance Fail if instance is an instance of the given class or of one of the given classes.
Method successResultOf Return the current success result of deferred or raise self.failureException.
Method failureResultOf Return the current failure result of deferred or raise self.failureException.
Method assertNoResult Assert that deferred does not have a result at this point.
Method assertRegex Fail the test if a regexp search of text fails.
def test_chmod(self):

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 symlink(self, target, name):

Create a symbolic link named name pointing at target.

RaisesSkipTestraised if symbolic links are not supported on the host platform.
def createLinks(self):

Create several symbolic links to files and directories.

def test_realpathSymlink(self):

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

def test_realpathCyclicalSymlink(self):

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

def test_realpathNoSymlink(self):

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

def test_walkCyclicalSymlink(self):

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

def test_walkObeysDescendWithCyclicalSymlinks(self):

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_walkObeysDescend(self):

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

def test_getAndSet(self):
Undocumented
def test_getContentFileClosing(self):

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

def test_symbolicLink(self):

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_linkTo(self):

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.

def test_linkToErrors(self):

Verify linkTo fails in the following case:

  • the target is in a directory that doesn't exist
  • the target already exists
def testMultiExt(self):
Undocumented
def testPreauthChild(self):
Undocumented
def testStatCache(self):
Undocumented
def testPersist(self):
Undocumented
def testInsecureUNIX(self):
Undocumented
def testInsecureWin32(self):
Undocumented
def testInsecureWin32Whacky(self):

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 testComparison(self):
Undocumented
def test_descendantOnly(self):

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

def testSibling(self):
Undocumented
def testTemporarySibling(self):
Undocumented
def test_temporarySiblingExtension(self):

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

def test_removeDirectory(self):

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

def test_removeWithSymlink(self):

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

def test_copyToDirectory(self):

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_copyToMissingDestFileClosing(self):

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_copyToFileClosing(self):

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_copyToDirectoryItself(self):

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_copyToWithSymlink(self):

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

def test_copyToWithoutSymlink(self):

Verify that copying with followLinks=False copies symlinks as symlinks

def test_copyToMissingSource(self):

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

def test_moveTo(self):

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

def test_moveToExistsCache(self):

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):

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

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

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):

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

def test_moveToError(self):

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 setUpFaultyRename(self):

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

Returnsa list of pair (src, dest) of calls to os.rename (type: list of tuple)
def test_crossMountMoveTo(self):

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

def test_crossMountMoveToWithSymlink(self):

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

def test_crossMountMoveToWithoutSymlink(self):

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

def test_createBinaryMode(self):

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 testOpen(self):
Undocumented
def test_openWithExplicitBinaryMode(self):

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):

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.

def test_existsCache(self):

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

def test_makedirsMakesDirectoriesRecursively(self):
C{FilePath.makedirs} creates a directory at C{path}}, including
recursively creating all parent directories leading up to the path.
def test_makedirsMakesDirectoriesWithIgnoreExistingDirectory(self):

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

def test_makedirsThrowsWithExistentDirectory(self):

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

def test_makedirsAcceptsIgnoreExistingDirectory(self):

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

def test_makedirsIgnoreExistingDirectoryExistAlreadyAFile(self):

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

def test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory(self):

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

def test_changed(self):

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_getPermissions_POSIX(self):

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

def test_deprecateStatinfoGetter(self):
def test_deprecateStatinfoSetter(self):
def test_deprecateStatinfoSetterSets(self):

Setting twisted.python.filepath.FilePath.statinfo changes the value of _statinfo such that getting statinfo again returns the new value.

def test_filePathNotDeprecated(self):

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

def test_getPermissions_Windows(self):

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.

def test_whetherBlockOrSocket(self):

Ensure that a file is not a block or socket

def test_statinfoBitsNotImplementedInWindows(self):

Verify that certain file stats are not available on Windows

def test_statinfoBitsAreNumbers(self):

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

def test_statinfoNumbersAreValid(self):

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

API Documentation for twisted, generated by pydoctor at 2020-03-25 17:34:30.