Assertion functions for the filesystem¶
These functions make it easy to check the state of files and directories. When the assertion is not true, they provide informative error messages.
- 
testpath.assert_path_exists(path, msg=None)¶
- Assert that something exists at the given path. 
- 
testpath.assert_not_path_exists(path, msg=None)¶
- Assert that nothing exists at the given path. 
- 
testpath.assert_isfile(path, follow_symlinks=True, msg=None)¶
- Assert that path exists and is a regular file. - With follow_symlinks=True, the default, this will pass if path is a symlink to a regular file. With follow_symlinks=False, it will fail in that case. 
- 
testpath.assert_not_isfile(path, follow_symlinks=True, msg=None)¶
- Assert that path exists but is not a regular file. - With follow_symlinks=True, the default, this will fail if path is a symlink to a regular file. With follow_symlinks=False, it will pass in that case. 
- 
testpath.assert_isdir(path, follow_symlinks=True, msg=None)¶
- Assert that path exists and is a directory. - With follow_symlinks=True, the default, this will pass if path is a symlink to a directory. With follow_symlinks=False, it will fail in that case. 
- 
testpath.assert_not_isdir(path, follow_symlinks=True, msg=None)¶
- Assert that path exists but is not a directory. - With follow_symlinks=True, the default, this will fail if path is a symlink to a directory. With follow_symlinks=False, it will pass in that case. 
- 
testpath.assert_islink(path, to=None, msg=None)¶
- Assert that path exists and is a symlink. - If to is specified, also check that it is the target of the symlink. 
- 
testpath.assert_not_islink(path, msg=None)¶
- Assert that path exists but is not a symlink. 
Unix specific¶
New in version 0.4.
These additional functions test for special Unix filesystem objects: named pipes and Unix domain sockets. The functions can be used on all platforms, but these types of objects do not exist on Windows.
- 
testpath.assert_ispipe(path, follow_symlinks=True, msg=None)¶
- Assert that path exists and is a named pipe (FIFO). - With follow_symlinks=True, the default, this will pass if path is a symlink to a named pipe. With follow_symlinks=False, it will fail in that case. 
- 
testpath.assert_not_ispipe(path, follow_symlinks=True, msg=None)¶
- Assert that path exists but is not a named pipe (FIFO). - With follow_symlinks=True, the default, this will fail if path is a symlink to a named pipe. With follow_symlinks=False, it will pass in that case. 
- 
testpath.assert_issocket(path, follow_symlinks=True, msg=None)¶
- Assert that path exists and is a Unix domain socket. - With follow_symlinks=True, the default, this will pass if path is a symlink to a Unix domain socket. With follow_symlinks=False, it will fail in that case. 
- 
testpath.assert_not_issocket(path, follow_symlinks=True, msg=None)¶
- Assert that path exists but is not a Unix domain socket. - With follow_symlinks=True, the default, this will fail if path is a symlink to a Unix domain socket. With follow_symlinks=False, it will pass in that case.