Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
testing.tools.safetynet_image.ImageComparison Class Reference
+ Collaboration diagram for testing.tools.safetynet_image.ImageComparison:

Public Member Functions

 __init__ (self, build_dir, output_path, two_labels, num_workers, threshold_fraction)
 
 Run (self, open_in_browser)
 
 GenerateOneDiff (self, image)
 

Public Attributes

 build_dir = build_dir
 
 output_path = output_path
 
 two_labels = two_labels
 
 num_workers = num_workers
 
int threshold = threshold_fraction * 100
 
 img_diff_bin = finder.ExecutablePath('pdfium_diff')
 
 diff_path = os.path.join(self.output_path, 'diff')
 
 image_locations
 

Protected Member Functions

 _GenerateDiffs (self)
 
 _GetRelativePath (self, absolute_path)
 
 _WriteImageRows (self, f, image, diff)
 
 _WritePageTd (self, f, image_path)
 
 _WritePageCompareTd (self, f, normal_image_path, hover_image_path)
 
 _WriteSmallChanges (self, f, small_changes)
 

Detailed Description

Compares pairs of page images and generates an HTML to look at differences.

The images are all assumed to have the same name and be in two directories:
[output_path]/[two_labels[0]] and [output_path]/[two_labels[1]]. For example,
if output_path is "/tmp/images" and two_labels is ("before", "after"),
images in /tmp/images/before will be compared to /tmp/images/after. The HTML
produced will be in /tmp/images/compare.html and have relative links to these
images, so /tmp/images is self-contained and can be moved around or shared.

Definition at line 23 of file safetynet_image.py.

Constructor & Destructor Documentation

◆ __init__()

testing.tools.safetynet_image.ImageComparison.__init__ ( self,
build_dir,
output_path,
two_labels,
num_workers,
threshold_fraction )
Constructor.

Args:
  build_dir: Path to the build directory.
  output_path: Path with the pngs and where the html will be created.
  two_labels: Tuple of two strings that name the subdirectories in
      output_path containing the images.
  num_workers: Number of worker threads to start.
  threshold_fraction: Minimum percentage (0.0 to 1.0) of pixels below which
      an image is considered to have only small changes. They will not be
      displayed on the HTML, only listed.

Definition at line 34 of file safetynet_image.py.

Member Function Documentation

◆ _GenerateDiffs()

testing.tools.safetynet_image.ImageComparison._GenerateDiffs ( self)
protected
Runs a diff over all pairs of page images, producing diff images.

As a side effect, the diff images will be saved to [output_path]/diff
with the same image name.

Returns:
  A dict mapping image names to percentage of pixels changes.

Definition at line 104 of file safetynet_image.py.

References get(), testing.tools.safetynet_image.ImageComparison.image_locations, and testing.tools.safetynet_image.ImageComparison.num_workers.

+ Here is the call graph for this function:

◆ _GetRelativePath()

testing.tools.safetynet_image.ImageComparison._GetRelativePath ( self,
absolute_path )
protected

Definition at line 175 of file safetynet_image.py.

References testing.tools.safetynet_image.ImageComparison.output_path, and testing.tools.safetynet_image.ImageLocations.output_path.

Referenced by testing.tools.safetynet_image.ImageComparison._WriteImageRows().

+ Here is the caller graph for this function:

◆ _WriteImageRows()

testing.tools.safetynet_image.ImageComparison._WriteImageRows ( self,
f,
image,
diff )
protected
Write table rows for a page image comparing its two versions.

Args:
  f: Open HTML file to write to.
  image: Image file name.
  diff: Percentage of different pixels.

Definition at line 178 of file safetynet_image.py.

References testing.tools.safetynet_image.ImageComparison._GetRelativePath(), testing.tools.safetynet_image.ImageComparison._WritePageCompareTd(), testing.tools.safetynet_image.ImageComparison._WritePageTd(), testing.tools.safetynet_image.ImageComparison.image_locations, Left, and Right.

+ Here is the call graph for this function:

◆ _WritePageCompareTd()

testing.tools.safetynet_image.ImageComparison._WritePageCompareTd ( self,
f,
normal_image_path,
hover_image_path )
protected
Write table column for an image comparing its two versions.

Args:
  f: Open HTML file to write to.
  normal_image_path: Path to image to be used in the "normal" state.
  hover_image_path: Path to image to be used in the "hover" state.

Definition at line 209 of file safetynet_image.py.

Referenced by testing.tools.safetynet_image.ImageComparison._WriteImageRows().

+ Here is the caller graph for this function:

◆ _WritePageTd()

testing.tools.safetynet_image.ImageComparison._WritePageTd ( self,
f,
image_path )
protected
Write table column with a single image.

Args:
  f: Open HTML file to write to.
  image_path: Path to image file.

Definition at line 198 of file safetynet_image.py.

Referenced by testing.tools.safetynet_image.ImageComparison._WriteImageRows().

+ Here is the caller graph for this function:

◆ _WriteSmallChanges()

testing.tools.safetynet_image.ImageComparison._WriteSmallChanges ( self,
f,
small_changes )
protected
Write table rows for all images considered to have only small changes.

Args:
  f: Open HTML file to write to.
  small_changes: List of (image, change) tuples, where image is the page
      image and change is the percentage of pixels changed.

Definition at line 224 of file safetynet_image.py.

◆ GenerateOneDiff()

testing.tools.safetynet_image.ImageComparison.GenerateOneDiff ( self,
image )
Runs a diff over one pair of images, producing a diff image.

As a side effect, the diff image will be saved to [output_path]/diff
with the same image name.

Args:
  image: Page image to compare.

Returns:
  A tuple (image, diff), where image is the parameter and diff is the
  percentage of pixels changed.

Definition at line 138 of file safetynet_image.py.

References testing.tools.safetynet_image.ImageComparison.image_locations, testing.tools.safetynet_image.ImageComparison.img_diff_bin, Left, print(), and Right.

+ Here is the call graph for this function:

◆ Run()

testing.tools.safetynet_image.ImageComparison.Run ( self,
open_in_browser )
Runs the comparison and generates an HTML with the results.

Returns:
    Exit status.

Definition at line 54 of file safetynet_image.py.

References testing.tools.common.DirectoryFinder.build_dir, testing.tools.safetynet_image.ImageComparison.build_dir, print(), testing.tools.safetynet_image.ImageComparison.two_labels, and testing.tools.safetynet_image.ImageLocations.two_labels.

+ Here is the call graph for this function:

Member Data Documentation

◆ build_dir

testing.tools.safetynet_image.ImageComparison.build_dir = build_dir

◆ diff_path

testing.tools.safetynet_image.ImageComparison.diff_path = os.path.join(self.output_path, 'diff')

Definition at line 73 of file safetynet_image.py.

◆ image_locations

testing.tools.safetynet_image.ImageComparison.image_locations

◆ img_diff_bin

testing.tools.safetynet_image.ImageComparison.img_diff_bin = finder.ExecutablePath('pdfium_diff')

◆ num_workers

testing.tools.safetynet_image.ImageComparison.num_workers = num_workers

◆ output_path

testing.tools.safetynet_image.ImageComparison.output_path = output_path

◆ threshold

int testing.tools.safetynet_image.ImageComparison.threshold = threshold_fraction * 100

Definition at line 52 of file safetynet_image.py.

◆ two_labels

testing.tools.safetynet_image.ImageComparison.two_labels = two_labels

The documentation for this class was generated from the following file: