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]¶ Bases:
luigi.target.FileSystem
MockFileSystem inspects/modifies _data to simulate file system operations.
-
exists
(path)[source]¶ Return
True
if file or directory atpath
exist,False
otherwiseParameters: 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.
-
listdir
(path)[source]¶ listdir does a prefix match of self.get_all_data(), but doesn’t yet support globs.
-
-
class
luigi.mock.
MockTarget
(fn, is_tmp=None, mirror_on_stderr=False, format=None)[source]¶ Bases:
luigi.target.FileSystemTarget
-
fs
= <luigi.mock.MockFileSystem object>¶
-
exists
()[source]¶ Returns
True
if the path for this FileSystemTarget exists;False
otherwise.This method is implemented by using
fs
.
-
open
(mode='r')[source]¶ 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. Using b is not supported; initialize with format=Nop instead.
-