TrackingDict

class endf_parserpy.utils.debugging_utils.TrackingDict(dict_like)[source]

Class for tracking read access of elements in dict_like objects.

This class implements an interface to dict_like objects for the purpose of tracking keys whose associated elements were retrieved. This tracking is applied recursively, hence also keys of dict_like objects stored within the root dict_like object are potentially tracked. Not all keys are tracked, though. Read access to a key is only tracked if the following two criteria are met:

  • The key is an integer, i.e. of type int

  • Keys within dict_like objects are never tracked if the dict_like object itself is stored under a key that starts with two underscores (__).

These two rules are owed to the mode of operation of the endf_parserpy.endf_parser.EndfParser class. The methods .parsefile() and .writefile() of the EndfParser class will temporarily create auxiliary variables stored under keys starting with two underscores. It is not pertinent to track read access to those ephemeral objects. The purpose of the TrackingDict class— when it comes to writing ENDF-6 formatted data—is to ensure that all elements in arrays (emulated with dict_like objects containing only integer keys) are accessed. Otherwise, it means that some elements have not been written to the ENDF-6 file and this situation indicates an inconsistency between counter variables and the index range of arrays.

Initialize a TrackingDict object.

Parameters:

dict_like (dict) – The dict_like object for which read access should be tracked.

verify_complete_retrieval()[source]

Verify that all array elements have been accessed.

This function will raise an IndexError exception if there are dict_like objects where at least one key of type int has been accessed but more keys exist that have not been accessed.