class FilePathTests(AbstractFilePathTests): (source)
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 | create |
Create several symbolic links to files and directories. |
Method | set |
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 |
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 |
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_copy |
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_copy |
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_copy |
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_copy |
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_copy |
If the source path is missing, FilePath.copyTo raises OSError . |
Method | test_copy |
Verify that copying with followLinks=False copies symlinks as symlinks |
Method | test_copy |
Verify that copying with followLinks=True copies symlink targets instead of symlinks |
Method | test_create |
FilePath.create should always open (and write to) files in binary mode; line-feed octets should be unmodified. |
Method | test_cross |
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_cross |
Verify that moveTo called with followLinks=False actually create another symlink. |
Method | test_cross |
By default, when moving a symlink, it should follow the link and actually copy the content of the linked node. |
Method | test_descendant |
If ".." is in the sequence passed to FilePath.descendant , InsecurePath is raised. |
Method | test_exists |
Check that filepath.FilePath.exists correctly restat the object if an operation has occurred in the mean time. |
Method | test_file |
While accessing twisted.python.filepath.FilePath.statinfo is deprecated, the filepath itself is not. |
Method | test_get |
Undocumented |
Method | test_get |
If reading from the underlying file raises an exception, FilePath.getContent raises that exception after closing the file. |
Method | test_get |
Getting permissions for a file returns a Permissions object for POSIX platforms (which supports separate user, group, and other permissions bits. |
Method | test_get |
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_link |
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_link |
Verify linkTo fails in the following case: |
Method | test_makedirs |
FilePath.makedirs succeeds when called on a directory that already exists and the c{ignoreExistingDirectory} argument is set to True. |
Method | test_makedirs |
When FilePath.makedirs is called with ignoreExistingDirectory set to True it throws an OSError exceptions if path is a file. |
Method | test_makedirs |
No summary |
Method | test_makedirs |
Calling FilePath.makedirs with ignoreExistingDirectory set to True has no effect if directory does not exist. |
Method | test_makedirs |
When FilePath.makedirs is called with ignoreExistingDirectory set to True it raises an OSError exception if exception errno is not EEXIST. |
Method | test_makedirs |
FilePath.makedirs throws an OSError exception when called on a directory that already exists. |
Method | test_move |
Verify that moving an entire directory results into another directory with the same content. |
Method | test_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. |
Method | test_move |
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_move |
The assertion of test_moveToExistsCache should hold in the case of a cross-mount move. |
Method | test_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. |
Method | test_move |
The assertion of test_moveToSizeCache should hold in the case of a cross-mount move. |
Method | test_open |
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_open |
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_realpath |
FilePath.realpath raises filepath.LinkError if the path is a symbolic link which is part of a cycle. |
Method | test_realpath |
FilePath.realpath returns the path itself if the path is not a symbolic link. |
Method | test_realpath |
FilePath.realpath returns the path of the ultimate target of a symlink. |
Method | test_remove |
FilePath.remove on a FilePath that refers to a directory will recursively delete its contents. |
Method | test_remove |
For a path which is a symbolic link, FilePath.remove just deletes the link, not the target. |
Method | test_statinfo |
Verify that file inode/device/nlinks/uid/gid stats are numbers in a POSIX environment |
Method | test_statinfo |
Verify that certain file stats are not available on Windows |
Method | test_statinfo |
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_symbolic |
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_temporary |
If FilePath.temporarySibling is given an extension argument, it will produce path objects with that extension appended to their names. |
Method | test_walk |
Verify that walking a path with a cyclical symlink raises an error |
Method | test_walk |
Verify that when the supplied descend predicate returns False, the target is not traversed. |
Method | test_walk |
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_whether |
Ensure that a file is not a block or socket |
Method | test |
Undocumented |
Method | test |
Undocumented |
Method | test |
Undocumented |
Method | test |
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 | test |
Undocumented |
Method | test |
Undocumented |
Method | test |
Undocumented |
Method | test |
Undocumented |
Method | test |
Undocumented |
Method | test |
Undocumented |
Method | test |
Undocumented |
Inherited from AbstractFilePathTests
:
Method | set |
Undocumented |
Method | subdir |
Undocumented |
Method | subfile |
Undocumented |
Method | test_children |
Verify that children raises the appropriate exception for non-existent directories. |
Method | test_children |
Verify that listdir raises the appropriate exception for attempting to list a file rather than a directory. |
Method | test_dictionary |
Verify that path instances are usable as dictionary keys. |
Method | test_dictionary |
Verify that path instances are usable as dictionary keys which do not clash with their string counterparts. |
Method | test_invalid |
Verify that a subdirectory that doesn't exist is reported as such. |
Method | test_multiple |
fp.descendant([a, b, c]) returns the same FilePath as is returned by fp.child(a).child(b).child(c). |
Method | test_new |
Verify that all times returned from the various new time functions are ints (and hopefully therefore 'high precision'). |
Method | test_old |
Verify that all times returned from the various time functions are integers, for compatibility. |
Method | test |
FilePath.parents() should return an iterator of every ancestor of the FilePath in question. |
Method | test_segments |
Verify that segmentsFrom notices when the ancestor isn't an ancestor. |
Method | test_segments |
Verify that the segments between two paths are correctly identified. |
Method | test_valid |
Make sure that we can read existent non-empty files. |
Method | test_valid |
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_verify |
Instances of the path type being tested provide IFilePath . |
Method | test |
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 | add |
Add the given function to a list of functions to be called after the test has run, but before tearDown. |
Method | call |
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 | flush |
Remove stored errors received from the log. |
Method | flush |
Remove stored warnings from the list of captured warnings and return them. |
Method | get |
Retrieve a module attribute which should have been deprecated, and assert that we saw the appropriate deprecation warning. |
Method | get |
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 | get |
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 | run |
If no methodName argument is passed to the constructor, run will treat this method as the thing with the actual test inside. |
Method | short |
Undocumented |
Instance Variable | failure |
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 | _get |
Return the reason to use for skipping a test method. |
Method | _get |
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 | _install |
Undocumented |
Method | _remove |
Undocumented |
Method | _run |
Run a single method, either a test method or fixture. |
Method | _run |
Synchronously run any cleanups which have been added. |
Method | _run |
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 | _test |
Undocumented |
Instance Variable | _warnings |
Undocumented |
Inherited from _Assertions
(via AbstractFilePathTests
, BytesTestCase
, SynchronousTestCase
):
Method | assert |
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 | assert |
Fail if first - second > tolerance |
Method | assert |
Fail the test if first and second are not equal. |
Method | assert |
Fail the test if condition evaluates to True. |
Method | assert |
Fail the test if containee is not found in container. |
Method | assert |
Fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test. |
Method | assert |
Fail if instance is not an instance of the given class or of one of the given classes. |
Method | assert |
Fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test. |
Method | assert |
Assert that deferred does not have a result at this point. |
Method | assert |
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 | assert |
Fail the test if first == second. |
Method | assert |
Fail the test if containee is found in container. |
Method | assert |
Fail if instance is an instance of the given class or of one of the given classes. |
Method | assert |
Fail if astring contains substring. |
Method | assert |
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 | assert |
Fail if substring does not exist within astring. |
Method | assert |
Fail the test if condition evaluates to False. |
Method | assert |
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 | failure |
Return the current failure result of deferred or raise self.failureException. |
Method | success |
Return the current success result of deferred or raise self.failureException. |
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 tuple | a list of pair (src, dest) of calls to os.rename |
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.
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).
FilePath.copyTo
makes a copy of all the contents of the directory named by that FilePath
if it is able to do so.
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.
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
.
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_copyToWithoutSymlink(self): (source) ¶
Verify that copying with followLinks=False copies symlinks as symlinks
def test_copyToWithSymlink(self): (source) ¶
Verify that copying with followLinks=True copies symlink targets instead of symlinks
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.)
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_crossMountMoveToWithoutSymlink(self): (source) ¶
Verify that moveTo called with followLinks=False actually create another symlink.
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.
Check that filepath.FilePath.exists correctly restat the object if an operation has occurred in the mean time.
While accessing twisted.python.filepath.FilePath.statinfo
is deprecated, the filepath itself is not.
If reading from the underlying file raises an exception, FilePath.getContent
raises that exception after closing the file.
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.
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.
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:
- the target is in a directory that doesn't exist
- the target 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.
Calling FilePath.makedirs with ignoreExistingDirectory set to True has no effect if directory does not exist.
When FilePath.makedirs is called with ignoreExistingDirectory set to True it raises an OSError exception if exception errno is not EEXIST.
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.
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.
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.
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.
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_realpathSymlink(self): (source) ¶
FilePath.realpath
returns the path of the ultimate target of a symlink.
def test_removeWithSymlink(self): (source) ¶
For a path which is a symbolic link, FilePath.remove
just deletes the link, not the target.
def test_statinfoBitsAreNumbers(self): (source) ¶
Verify that file inode/device/nlinks/uid/gid stats are numbers in a POSIX environment
def test_statinfoBitsNotImplementedInWindows(self): (source) ¶
Verify that certain file stats are not available 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)
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.
If FilePath.temporarySibling
is given an extension argument, it will produce path objects with that extension appended to their names.
def test_walkCyclicalSymlink(self): (source) ¶
Verify that walking a path with a cyclical symlink raises an error
def test_walkObeysDescend(self): (source) ¶
Verify that when the supplied descend predicate returns False, the target is not traversed.
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 testInsecureWin32(self): (source) ¶
Undocumented
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.