scenario.debugutils module

Functions and classes for debugging.

class DelayedStr

Bases: ABC

Abstract class that defines a string which computation can be delayed.

The main interest of it is to postpone heavy processing, so that if ever useless, it is not executed at all.

__init__()

Initializes the string computation result cache.

__str

Cached string computation result.

__repr__()

Canonical string representation.

This method may be useless. Whatever, let’s return the canonical representation of the string defined by this object.

__str__()

Triggers the string computation on the first call, and cache it for later calls.

abstract _computestr()

String computation handler.

Returns:

String computed for the object.

Will be cached by __str__().

_abc_impl = <_abc_data object>
class FmtAndArgs

Bases: DelayedStr

Makes it possible to prepare a string format with its corresponding arguments, as usual with the % operator, and have it computed if needed.

__init__(fmt='', *args)

Prepares the string format and arguments, possibly with initial values.

Parameters:
  • fmt – Inital string format.

  • args – Initial string arguments.

fmt

String format.

args

Format arguments.

push(fmt, *args)

Pushes additional format and arguments.

Makes it possible to prepare the string step by step, and/or conditionally.

Parameters:
  • fmt – String format to appens.

  • args – Corresponding arguments.

Returns:

self

_computestr()

String computation handler.

Returns:

String computed for the object.

Will be cached by __str__().

_abc_impl = <_abc_data object>
class SafeRepr

Bases: DelayedStr

Delays the computation of the safe canonical representation of an object.

Same as unittest, safe representation means that the string computed while not exceed a given length, so that it remains human readable.

__init__(obj, max_length=256, focus=None)

Stores the object reference for later safe representation computation.

Parameters:
  • obj – Object to represent.

  • max_length – Maximum length for the resulting string.

  • focus – Data to focus on.

obj

Object to represent.

max_length

Maximum length for the resulting string.

focus

Data to focus on.

_computestr()

String computation handler.

Returns:

String computed for the object.

Will be cached by __str__().

_abc_impl = <_abc_data object>
saferepr(obj, max_length=256, focus=None)

Safe representation of an object.

Parameters:
  • obj – Object to represent.

  • max_length – Maximum length for the resulting string.

  • focus – Data to focus on.

Returns:

SafeRepr delayed computation object.

class JsonDump

Bases: DelayedStr

Delays the dump of JSON data.

__init__(json_data, **kwargs)

Stores the JSON data for later dump.

Parameters:
  • json_data – JSON data to dump.

  • kwargsjson.dumps()-like arguments.

json_data

JSON data to dump.

kwargs

json.dumps()-like arguments.

_computestr()

String computation handler.

Returns:

String computed for the object.

Will be cached by __str__().

_abc_impl = <_abc_data object>
jsondump(json_data, **kwargs)

Dump of JSON data.

Parameters:
  • json_data – JSON data to dump.

  • kwargsjson.dumps()-like arguments.

Returns:

JsonDump delayed computation object.

class CallbackStr

Bases: DelayedStr

String builder callback manager.

__init__(callback, *args, **kwargs)

Stores the callback with its arguments for later execution.

Parameters:
  • callback – String builder callback.

  • args – Callback positional arguments.

  • kwargs – Callback named arguments.

callback

String builder callback.

args

Callback positional arguments.

kwargs

Callback named arguments.

_computestr()

String computation handler.

Returns:

String computed for the object.

Will be cached by __str__().

_abc_impl = <_abc_data object>
callback(callback, *args, **kwargs)

Stores a string builder callback with its arguments for later execution.

Parameters:
  • callback – String builder callback.

  • args – Callback positional arguments.

  • kwargs – Callback named arguments.

Returns:

CallbackStr delayed computation object.