votesim.utilities.recorder

Decorator and storage class used to record object method calls and re-call them when desired.

Class Summary

RecordActionCache()

RecordActionCache records two kinds of method actions

Function Summary

flatten_record_actions(a)

Flatten the records list generated from record_actions

record_actions([name, replace])

Decord used to record method actions in object created in parent object.

run_dict(d, obj)

Take RecordActionCache.dict and convert it to RecordActionCache data

Module Classes

RecordActionCache

class votesim.utilities.recorder.RecordActionCache

RecordActionCache records two kinds of method actions

  • Method calls that are recorded sequentially

  • Method calls that replace the input of previous calls

dict

Dictionary containing all recorded method actions and arguments.

Type

dict

Method/Attribute Summary

RecordActionCache.replace_record(funcname, …)

Modify records that replace the previous method record

RecordActionCache.append_record(funcname, kwargs)

Modify records that append to previous records

RecordActionCache.reset()

Clear all records

RecordActionCache.dict

dict of records.

RecordActionCache.repeat(obj)

Repeat the recorded method calls on the input object.

RecordActionCache.run_dict(d, obj)

RecordActionCache.replace_record(funcname, kwargs)

Modify records that replace the previous method record

RecordActionCache.append_record(funcname, kwargs)

Modify records that append to previous records

RecordActionCache.reset()

Clear all records

RecordActionCache.dict()

dict of records.

For appended, ordered method calls:

  • keys = callnum.funcname.kwarg

  • values = keyword argument values

For replaced method calls:

  • keys = funcname.kwarg

  • value = keyword argument values

RecordActionCache.repeat(obj)

Repeat the recorded method calls on the input object.

Parameters

obj (object) – Parent object of stored methods

static RecordActionCache.run_dict(d, obj)

Module Functions

flatten_record_actions

votesim.utilities.recorder.flatten_record_actions(a)

Flatten the records list generated from record_actions

Parameters

a (list) – Attribute created by decorator record_actions

Returns

out – Dictionary of record, hopefully easier to read.

key is now ‘number.funcname.argument’

Return type

dict

record_actions

votesim.utilities.recorder.record_actions(name='_method_records', replace=False)

Decord used to record method actions in object created in parent object.

Parameters
  • name (str (default '_method_records')) – Name of RecordActionCache used to record method actions. This shall be created in the parent object.

  • replace (bool (default = False)) –

    • If False, append to the previously recorded arguments for the method

    • If True, replace the previous recorded arguments for the method.

Returns

  • out (decorator) – Function used to decorate class methods

  • Reset Record

  • ————-

  • Reset the record for object a using

  • >>> del a._method_records

run_dict

votesim.utilities.recorder.run_dict(d, obj)

Take RecordActionCache.dict and convert it to RecordActionCache data

Parameters
  • d (dict) – RecordActionCache.dict

  • obj (object) – Parent object to re-run method calls.