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 elements of dict-like and list-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

  • Elements within dict-like`` objects are never tracked if the dict-like object itself is stored under a key that starts with two underscores (__).

  • If an object is list-like, it’s elements are tracked.

The first criteria are owed to the mode of operation of the 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 ranges 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.