luigi.mock module

This module provides a class MockTarget, an implementation of Target. MockTarget contains all data in-memory. The main purpose is unit testing workflows without writing to disk.

class luigi.mock.MockFileSystem[source]


MockFileSystem inspects/modifies _data to simulate file system operations.

copy(path, dest, raise_if_exists=False)[source]

Copies the contents of a single file path to dest


Return True if file or directory at path exist, False otherwise

Parameters:path (str) – a path within the FileSystem to check for existence.
remove(path, recursive=True, skip_trash=True)[source]

Removes the given mockfile. skip_trash doesn’t have any meaning.

move(path, dest, raise_if_exists=False)[source]

Moves a single file from path to dest


listdir does a prefix match of self.get_all_data(), but doesn’t yet support globs.


Return True if the location at path is a directory. If not, return False.

Parameters:path (str) – a path within the FileSystem to check as a directory.

Note: This method is optional, not all FileSystem subclasses implements it.

mkdir(path, parents=True, raise_if_exists=False)[source]

mkdir is a noop.

class luigi.mock.MockTarget(fn, is_tmp=None, mirror_on_stderr=False, format=None)[source]


fs = <luigi.mock.MockFileSystem object>

Returns True if the path for this FileSystemTarget exists; False otherwise.

This method is implemented by using fs.

move(path, raise_if_exists=False)[source]

Call MockFileSystem’s move command

rename(*args, **kwargs)[source]

Call move to rename self


Open the FileSystem target.

This method returns a file-like object which can either be read from or written to depending on the specified mode.

Parameters:mode (str) – the mode r opens the FileSystemTarget in read-only mode, whereas w will open the FileSystemTarget in write mode. Subclasses can implement additional options.
class luigi.mock.MockFile(*args, **kwargs)[source]

Bases: luigi.mock.MockTarget