compare_objects()

endf_parserpy.compare_objects(obj1, obj2, atol=1e-08, rtol=1e-06, strlen_only=False, do_rstrip=False, rstrcut=None, fail_on_diff=True, diff_log=None)[source]

Compare recursively two objects.

This function enables the recursive comparison of two objects possible being or containing objects of type dict or iterable array-like objects. For example, this class can be used to confirm or reject the equality of two nested dictionaries resulting from the parsing of ENDF-6 files via the parsefile() method of the endf_parserpy.EndfParser class. The function can print out meaningful information where the discrepancies are present in the objects with a nested structure.

Parameters:
  • obj1 (object) – Any kind of object but usually it will be a nested dict_like structure.

  • obj2 (object) – Any kind of object but usually it will be a nested dict_like structure.

  • atol (float) – The absolute tolerance for the comparison of two float variables.

  • rtol (float) – The relative tolerance for the comparison of two float variables.

  • strlen_only (bool) – If true, only compare the lengths of strings, otherwise also the content of the strings is considered in the comparison.

  • do_rstrip (bool) – If true, strip whitespace characters at the end of the strings before comparison.

  • rstrcut (Union[None, int]) – If an integer is provided, only retain the first rstrcut characters of the strings in the comparison. If None, strings are compared as they are.

  • fail_on_diff (bool) – If true, this function will raise an exception at the first encounter of a difference. Otherwise, the function will fully compare the objects and return true if the two objects are equal and false if they exhibit differences. The second option is mostly useful in combination with diff_log=True.

  • diff_log (Union[None, List]) – A list object can be passed which will be filled with strings that indicate the differences found. This option is only useful in combination with fail_on_diff=false.