![]() |
This util wraps mock for the tf.io.gfile
API.
tfds.testing.MockFs()
Usage:
fs = MockFs()
with fs.mock():
fs.add_file('/path/to/file1', 'Content of file 1')
assert tf.io.gfile.exists('/path/to/file1')
with tf.io.gfile.GFile('/path/to/file2', 'w') as f:
f.write('Content of file 2')
tf.io.gfile.rename('/path/to/file1', '/path/to/file1_moved')
assert fs.files == {
'/path/to/file2': 'Content of file 2',
'/path/to/file1_moved': 'Content of file 1',
}
Attributes | |
---|---|
files
|
Dict[str, str], mapping existing files -> file content |
Methods
add_file
add_file(
path, content=None
) -> None
contextmanager
@contextlib.contextmanager
contextmanager() -> Iterator['MockFs']
Open the file.
mock
mock()
__enter__
__enter__()
__exit__
__exit__(
exc_type, exc_value, traceback
)