tfds.testing.MockFs

This util wraps mock for the tf.io.gfile API.

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',
  }

files Dict[str, str], mapping existing files -> file content

Methods

add_file

View source

contextmanager

View source

Open the file.

mock

View source

__enter__

View source

__exit__

View source