pyantz.jobs.testing package#

Submodules#

pyantz.jobs.testing.nop module#

Job that does nothing, mostly for debugging and testing.

do_nothing(*_: Any, **__: Any)[source]#

Do nothing and return success.

Unlike most jobs this function is not registered with add_parameters(), so it accepts any parameters and ignores them.

Parameters:
  • *_ (Any) – ignored positional arguments (a job is given its parameters and a submit function).

  • **__ (Any) – ignored keyword arguments.

Job parameters:

any – every parameter is accepted and ignored.

Returns:

always True.

Return type:

bool

Raises:

None – this job never fails.

Example

from pyantz.jobs.testing.nop import do_nothing

assert do_nothing({"hello": "there"}, lambda job: None)
did nothing :)

pyantz.jobs.testing.touch_file module#

Touch/create a file.

class TouchFileParameters(*, path: Path, exist_ok: bool = True)[source]#

Bases: BaseModel

Touch a file (create it).

Parameters:
  • path (Path)

  • exist_ok (bool)

_abc_impl = <_abc._abc_data object>#
exist_ok: bool#

If False, the job fails when the file already exists (see pathlib.Path.touch()).

path: Path#

Path to the file to create.

touch_file(params: TouchFileParameters)[source]#

Touch a file (create it with no values).

Mostly used for testing. An existing file keeps its contents and only has its modification time updated.

Parameters:

params (TouchFileParameters) – the job’s parameters, validated as TouchFileParameters.

Job parameters:
  • path (Path) – path to the file to create.

  • exist_ok (bool) – if False, the job fails when the file already exists. Defaults to True.

Returns:

True if the file was touched, False if it already existed and exist_ok is False.

Return type:

bool

Raises:

OSError – if the file can’t be created, e.g., its directory doesn’t exist.

Example

from pyantz.jobs.testing.touch_file import touch_file

# a registered job is called with its parameters and a submit function
def submit(job):
    pass

print(touch_file({"path": "touched.txt"}, submit))
print(touch_file({"path": "touched.txt", "exist_ok": False}, submit))
True
False

Module contents#

Basic jobs for testing.