twisted.test.test_paths.FilePathTests(AbstractFilePathTests) class documentationtwisted.test.test_paths
(View In Hierarchy)
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.chmodmodifies the permissions of the passed file as expected (usingos.statto check). We use some basic modes that should work 
everywhere (even on Windows). | 
| Method | symlink | Create a symbolic link named namepointing attarget. | 
| Method | createLinks | Create several symbolic links to files and directories. | 
| Method | test_realpathSymlink | FilePath.realpathreturns the path of the ultimate target of a symlink. | 
| Method | test_realpathCyclicalSymlink | FilePath.realpathraisesfilepath.LinkErrorif the path is a symbolic link which is part of a cycle. | 
| Method | test_realpathNoSymlink | FilePath.realpathreturns 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 descendpredicate returnsFalse, the 
target is not traversed, as if it was a simple symlink. | 
| Method | test_walkObeysDescend | Verify that when the supplied descendpredicate returnsFalse, the target is not traversed. | 
| Method | test_getAndSet | Undocumented | 
| Method | test_getContentFileClosing | If reading from the underlying file raises an exception, FilePath.getContentraises that exception after closing the 
file. | 
| Method | test_symbolicLink | Verify the behavior of the isLinkmethod 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 linkTofails 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 toFilePath.descendant,InsecurePathis raised. | 
| Method | testSibling | Undocumented | 
| Method | testTemporarySibling | Undocumented | 
| Method | test_temporarySiblingExtension | If FilePath.temporarySiblingis given an extension argument, it will produce path objects with that 
extension appended to their names. | 
| Method | test_removeDirectory | FilePath.removeon aFilePaththat
refers to a directory will recursively delete its contents. | 
| Method | test_removeWithSymlink | For a path which is a symbolic link, FilePath.removejust deletes the link, not the target. | 
| Method | test_copyToDirectory | FilePath.copyTomakes a copy of all the contents of the directory named by thatFilePathif 
it is able to do so. | 
| Method | test_copyToMissingDestFileClosing | If an exception is raised while FilePath.copyTois trying to open source file to read from, the destination file is closed 
and the exception is raised to the caller ofFilePath.copyTo. | 
| Method | test_copyToFileClosing | If an exception is raised while FilePath.copyTois copying bytes between two regular files, the source and destination 
files are closed and the exception propagates to the caller ofFilePath.copyTo. | 
| Method | test_copyToDirectoryItself | FilePath.copyTofails 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.copyToraisesOSError. | 
| Method | test_moveTo | Verify that moving an entire directory results into another directory with the same content. | 
| Method | test_moveToExistsCache | A FilePaththat
has been moved aside withFilePath.moveTono longer registers as existing.  Its previously non-existent target 
exists, though, as it was created by the call tomoveTo. | 
| Method | test_moveToExistsCacheCrossMount | The assertion of test_moveToExistsCache should hold in the case of a cross-mount move. | 
| Method | test_moveToSizeCache | FilePath.moveToclears its destination's status cache, such that calls toFilePath.getsizeafter the call tomoveTowill 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.renamethat will fail witherrno.EXDEVon first call. This is used to simulate a cross-device rename failure. | 
| Method | test_crossMountMoveTo | moveToshould be able to handleEXDEVerror 
raised byos.renamewhen 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.createshould 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.existscorrectly 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.makedirswithignoreExistingDirectoryset toTruehas no effect
if directory does not exist. | 
| Method | test_makedirsThrowsWithExistentDirectory | FilePath.makedirsthrows anOSErrorexception 
when called on a directory that already exists. | 
| Method | test_makedirsAcceptsIgnoreExistingDirectory | FilePath.makedirssucceeds when called on a directory that 
already exists and the c{ignoreExistingDirectory} argument is set toTrue. | 
| Method | test_makedirsIgnoreExistingDirectoryExistAlreadyAFile | When FilePath.makedirsis called withignoreExistingDirectoryset toTrueit throws anOSErrorexceptions if path is a file. | 
| Method | test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory | When FilePath.makedirsis called withignoreExistingDirectoryset toTrueit raises anOSErrorexception if exception errno is not EEXIST. | 
| Method | test_changed | FilePath.changedindicates that theFilePathhas 
changed, but does not re-read the status information from the filesystem 
until it is queried again via another method, such asgetsize. | 
| Method | test_getPermissions_POSIX | Getting permissions for a file returns a Permissionsobject for POSIX platforms (which supports separate user, group, and other 
permissions bits. | 
| Method | test_deprecateStatinfoGetter | Getting twisted.python.filepath.FilePath.statinfois deprecated. | 
| Method | test_deprecateStatinfoSetter | Setting twisted.python.filepath.FilePath.statinfois deprecated. | 
| Method | test_deprecateStatinfoSetterSets | Setting twisted.python.filepath.FilePath.statinfochanges the value of _statinfo such that getting statinfo again returns the
new value. | 
| Method | test_filePathNotDeprecated | While accessing twisted.python.filepath.FilePath.statinfois 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 theFilePathin 
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 sameFilePathas 
is returned byfp.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 | Noneor 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 theTestResultsupports skipping). | 
| Instance Variable | todo | None,
a string or a tuple of(errors, reason)whereerrorsis either an exception class or an iterable of 
exception classes, andreasonis a string. SeeTodoormakeTodofor 
more information. | 
| Instance Variable | suppress | Noneor a list of tuples of(args, kwargs)to be passed towarnings.filterwarnings. Use these to suppress warnings raised
in a test. Useful for testing deprecated code. See alsoutil.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 methodNameargument is passed to the constructor,runwill 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, andtearDown. | 
| 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 conditionevaluates to True. | 
| Method | assertTrue | Fail the test if conditionevaluates to False. | 
| Method | assertRaises | Fail the test unless calling the function fwith the givenargsandkwargsraisesexception. 
The failure will report the traceback and call stack of the unexpected 
exception. | 
| Method | assertEqual | Fail the test if firstandsecondare not 
equal. | 
| Method | assertIs | Fail the test if firstis notsecond.  This is
an obect-identity-equality test, not an object equality (i.e.__eq__) test. | 
| Method | assertIsNot | Fail the test if firstissecond.  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 containeeis not found incontainer. | 
| Method | assertNotIn | Fail the test if containeeis found incontainer. | 
| 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 substringdoes not exist withinastring. | 
| Method | assertNotSubstring | Fail if astringcontainssubstring. | 
| 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 instanceis not an instance of the given class or 
of one of the given classes. | 
| Method | assertNotIsInstance | Fail if instanceis an instance of the given class or of 
one of the given classes. | 
| Method | successResultOf | Return the current success result of deferredor raiseself.failureException. | 
| Method | failureResultOf | Return the current failure result of deferredor raiseself.failureException. | 
| Method | assertNoResult | Assert that deferreddoes not have a result at this 
point. | 
| Method | assertRegex | Fail the test if a regexpsearch oftextfails. | 
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).
Create a symbolic link named name pointing at 
target.
| Raises | SkipTest | raised if symbolic links are not supported on the host platform. | 
FilePath.realpath
returns the path of the ultimate target of a symlink.
FilePath.realpath
raises filepath.LinkError
if the path is a symbolic link which is part of a cycle.
FilePath.realpath
returns the path itself if the path is not a symbolic link.
Verify that walking a path with a cyclical symlink raises an error
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.
Verify that when the supplied descend predicate returns 
False, the target is not traversed.
If reading from the underlying file raises an exception, 
FilePath.getContent raises that exception after closing the 
file.
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.
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.
Verify linkTo fails in the following case:
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.
If ".." is in the sequence passed to 
FilePath.descendant, InsecurePath
is raised.
If FilePath.temporarySibling
is given an extension argument, it will produce path objects with that 
extension appended to their names.
FilePath.remove
on a FilePath that
refers to a directory will recursively delete its contents.
For a path which is a symbolic link, FilePath.remove
just deletes the link, not the target.
FilePath.copyTo
makes a copy of all the contents of the directory named by that FilePath if 
it is able to do so.
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.
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.
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.
Verify that copying with followLinks=True copies symlink targets instead of symlinks
Verify that copying with followLinks=False copies symlinks as symlinks
Verify that moving an entire directory results into another directory with the same content.
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.
The assertion of test_moveToExistsCache should hold in the case of a cross-mount move.
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.
The assertion of test_moveToSizeCache should hold in the case of a cross-mount move.
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.
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 | a list of pair (src, dest) of calls to os.rename(type:listoftuple) | |
moveTo should be able to handle EXDEV error 
raised by os.rename when trying to move a file on a different 
mounted filesystem.
By default, when moving a symlink, it should follow the link and actually copy the content of the linked node.
Verify that moveTo called with followLinks=False actually create another symlink.
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.)
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.
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.
Check that filepath.FilePath.exists correctly restat the 
object if an operation has occurred in the mean time.
C{FilePath.makedirs} creates a directory at C{path}}, including
recursively creating all parent directories leading up to the path.
Calling FilePath.makedirs with 
ignoreExistingDirectory set to True has no effect
if directory does not exist.
FilePath.makedirs throws an OSError exception 
when called on a directory that already exists.
FilePath.makedirs succeeds when called on a directory that 
already exists and the c{ignoreExistingDirectory} argument is set to 
True.
When FilePath.makedirs is called with 
ignoreExistingDirectory set to True it throws an 
OSError exceptions if path is a file.
When FilePath.makedirs is called with 
ignoreExistingDirectory set to True it raises an 
OSError exception if exception errno is not EEXIST.
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.
Getting permissions for a file returns a Permissions
object for POSIX platforms (which supports separate user, group, and other 
permissions bits.
Getting twisted.python.filepath.FilePath.statinfo
is deprecated.
Setting twisted.python.filepath.FilePath.statinfo
is deprecated.
Setting twisted.python.filepath.FilePath.statinfo
changes the value of _statinfo such that getting statinfo again returns the
new value.
While accessing twisted.python.filepath.FilePath.statinfo
is deprecated, the filepath itself is not.
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.
Verify that certain file stats are not available on Windows