htmlcmp 1.2.2__tar.gz → 1.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htmlcmp
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Compare HTML files by rendered output
5
5
  Author: Andreas Stefl
6
6
  Maintainer-email: Andreas Stefl <stefl.andreas@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "htmlcmp"
3
- version = "1.2.2"
3
+ version = "1.2.4"
4
4
  description = "Compare HTML files by rendered output"
5
5
  classifiers = []
6
6
  authors = [
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- import shutil
5
4
  import sys
6
5
  import argparse
7
6
  import io
@@ -36,8 +35,13 @@ def screenshot(browser: webdriver.Remote, url: str) -> Image.Image:
36
35
 
37
36
  target_find_by = By.TAG_NAME
38
37
  target = "body"
38
+ loaded_page_settling_time = 0
39
39
 
40
- web_driver_wait = WebDriverWait(browser, 5)
40
+ # TODO for pdf2htmlex the second screenshot sometimes fades in from white... not sure why, but a sleep solves it
41
+ if "poppler" in url:
42
+ loaded_page_settling_time = 0.3
43
+
44
+ web_driver_wait = WebDriverWait(browser, 10)
41
45
  web_driver_wait.until(
42
46
  expected_conditions.presence_of_element_located((target_find_by, target))
43
47
  )
@@ -45,6 +49,8 @@ def screenshot(browser: webdriver.Remote, url: str) -> Image.Image:
45
49
  lambda driver: driver.execute_script("return document.readyState") == "complete"
46
50
  )
47
51
 
52
+ time.sleep(loaded_page_settling_time)
53
+
48
54
  png = browser.get_screenshot_as_png()
49
55
  return Image.open(io.BytesIO(png))
50
56
 
@@ -74,15 +80,22 @@ def get_browser(
74
80
 
75
81
 
76
82
  def html_render_diff(
77
- a: str | Path, b: str | Path, browser: webdriver.Remote
83
+ a: str | Path,
84
+ b: str | Path,
85
+ browser: webdriver.Remote,
86
+ browser_b: webdriver.Remote = None,
78
87
  ) -> tuple[Image.Image, tuple[Image.Image, Image.Image]]:
79
88
  if not isinstance(a, (str, Path)) or not isinstance(b, (str, Path)):
80
89
  raise TypeError("Both a and b must be str or Path instances")
81
90
  if not isinstance(browser, webdriver.Remote):
82
91
  raise TypeError(f"Expected webdriver.Remote, got {type(browser)}")
92
+ if browser_b is None:
93
+ browser_b = browser
94
+ elif not isinstance(browser_b, webdriver.Remote):
95
+ raise TypeError(f"Expected webdriver.Remote, got {type(browser_b)}")
83
96
 
84
97
  image_a = screenshot(browser, to_url(a))
85
- image_b = screenshot(browser, to_url(b))
98
+ image_b = screenshot(browser_b, to_url(b))
86
99
 
87
100
  image_a = image_a.convert("RGB")
88
101
  image_b = image_b.convert("RGB")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htmlcmp
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Compare HTML files by rendered output
5
5
  Author: Andreas Stefl
6
6
  Maintainer-email: Andreas Stefl <stefl.andreas@gmail.com>
File without changes
File without changes
File without changes
File without changes