Package pysys :: Package utils :: Module filediff
[hide private]
[frames] | no frames]

Module filediff

source code

Functions [hide private]
list
trimContents(contents, expressions, exclude=True)
Reduce a list of strings based by including/excluding lines which match any of a set of regular expressions, returning the processed list.
source code
list
replace(list, replacementList)
Replace all occurrences of keyword values in a list of strings with a set value, returning the processed list.
source code
 
logContents(message, list)
Log a list of strings, prepending the line number to each line in the log output.
source code
boolean
filediff(file1, file2, ignore=[], sort=True, replacementList=[], include=[], unifiedDiffOutput=None)
Perform a file comparison between two (preprocessed) input files, returning true if the files are equivalent.
source code
Variables [hide private]
  __package__ = 'pysys.utils'
Function Details [hide private]

trimContents(contents, expressions, exclude=True)

source code 

Reduce a list of strings based by including/excluding lines which match any of a set of regular expressions, returning the processed list.

The method reduces an input list of strings based on whether each string matches or does not match a list of regular expressions.

Parameters:
  • contents - The input list of strings to trim based on matches to regular expressions
  • expressions - The input list of regular expressions
  • exclude - If true matches to the regular expressions exclude the line, if false matches include the line
Returns: list
The processed list

replace(list, replacementList)

source code 

Replace all occurrences of keyword values in a list of strings with a set value, returning the processed list.

The replacementList parameter should contain a list of tuples to use in the replacement, e.g. [('foo', 'bar'), ('swim', 'swam')].

Parameters:
  • list - The input list of strings to performed the replacement on
  • replacementList - A list of tuples (key, value) where matches to key are replaced with value
Returns: list
The processed list

logContents(message, list)

source code 

Log a list of strings, prepending the line number to each line in the log output.

Parameters:
  • list - The list of strings to log

filediff(file1, file2, ignore=[], sort=True, replacementList=[], include=[], unifiedDiffOutput=None)

source code 

Perform a file comparison between two (preprocessed) input files, returning true if the files are equivalent.

The method reads in the files and loads the contents of each as a list of strings. The two files are said to be equal if the two lists are equal. The method allows for preprocessing of the string lists to trim down their contents prior to the comparison being performed. Preprocessing is either to remove entries from the lists which match any entry in a set of regular expressions, include only lines which match any entry in a set of regular expressions, replace certain keywords in the string values of each list with a set value (e.g. to replace time stamps etc), or to sort the lists before the comparison (e.g. where determinism may not exist). Verbose logging of the method occurs at DEBUG level showing the contents of the processed lists prior to the comparison being performed.

Parameters:
  • file1 - The full path to the first file to use in the comparison
  • file2 - The full path to the second file to use in the comparison, typically a reference file
  • ignore - A list of regular expressions which remove entries in the input file contents before making the comparison
  • sort - Boolean to sort the input file contents before making the comparison
  • replacementList - A list of tuples (key, value) where matches to key are replaced with value in the input file contents before making the comparison
  • include - A list of regular expressions used to select lines from the input file contents to use in the comparison
  • unifiedDiffOutput - If specified, indicates the full path of a file to which unified diff output will be written, if the diff fails.
Returns: boolean
success (True / False)
Raises: