niprov.diff module

class niprov.diff.Diff(file1, file2)

Bases: object

Difference between two files.

This represents differences in provenance between two files.

See niprov.comparing

Parameters:
  • file1 (BaseFile) – One of two niprov BaseFile objects to compare.
  • file2 (BaseFile) – As file1
NCHARSCOL = 20
areEqual(ignore=None, select=None)

Whether there are any differences between the files.

Parameters:
  • ignore (list) – Optional. List of fields not to evaluate when determining differences.
  • select (list) – Optional. List of fields that should be specifically evaluated. All other fields will be ignored.
Returns:

True if no differences, False otherwise.

Return type:

bool

areEqualProtocol()

Whether there are any differences for protocol fields.

Each BaseFile subtype has a getProtocolFields() method that is used here to selectively see if any of these are different.

Returns:True if no differences, False otherwise.
Return type:bool
assertEqual(ignore=None, select=None)

Raises exception if there are differences.

Parameters:
  • ignore (list) – Optional. List of fields not to evaluate when determining differences.
  • select (list) – Optional. List of fields that should be specifically evaluated. All other fields will be ignored.
Raises:

AssertionError – Message with differences in a table.

assertEqualProtocol()

Raises exception if there are differences in protocol fields.

Each BaseFile subtype has a getProtocolFields() method that is used here to selectively see if any of these are different.

Raises:AssertionError – Message with protocol differences in a table.
defaultIgnore = ['_id']
getDifferenceString(ignore=None, select=None)

Get table of differences as string.

Parameters:
  • ignore (list) – Optional. List of fields not to evaluate when determining differences.
  • select (list) – Optional. List of fields that should be specifically evaluated. All other fields will be ignored.
Returns:

A three-columns table listing provenance fields and their respective values for the two files.

Return type:

str

getDifferences(ignore=None, select=None)

Get dictionary with fields that differ and how they differ.

Parameters:
  • ignore (list) – Optional. List of fields not to evaluate when determining differences.
  • select (list) – Optional. List of fields that should be specifically evaluated. All other fields will be ignored.
Returns:

A dictionary with provenance fields as keys and strings indicating how they differ.

Return type:

dict

getSame()

Get dictionary with fields that have equal values.

Returns:A dictionary with provenance fields as keys the string ‘same’ as value.
Return type:dict
getSameString()

Get table of values that are the same for the compared files.

Returns:A three-columns table listing provenance fields and their respective values for the two files.
Return type:str