sphinxcontrib-screenshot 0.2.1__tar.gz → 0.2.2__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.
- {sphinxcontrib_screenshot-0.2.1/sphinxcontrib_screenshot.egg-info → sphinxcontrib_screenshot-0.2.2}/PKG-INFO +1 -1
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/pyproject.toml +1 -1
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/sphinxcontrib/screenshot.py +21 -6
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2/sphinxcontrib_screenshot.egg-info}/PKG-INFO +1 -1
- sphinxcontrib_screenshot-0.2.2/tests/test_root.py +92 -0
- sphinxcontrib_screenshot-0.2.1/tests/test_root.py +0 -74
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/LICENSE +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/README.md +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/setup.cfg +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/sphinxcontrib_screenshot.egg-info/SOURCES.txt +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/sphinxcontrib_screenshot.egg-info/dependency_links.txt +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/sphinxcontrib_screenshot.egg-info/requires.txt +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/sphinxcontrib_screenshot.egg-info/top_level.txt +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_browsers.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_color_scheme.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_contexts.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_full_page.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_headers.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_locale.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_pdf.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_timezone.py +0 -0
- {sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_wsgi_apps.py +0 -0
{sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/sphinxcontrib/screenshot.py
RENAMED
|
@@ -116,6 +116,7 @@ class ScreenshotDirective(SphinxDirective, Figure):
|
|
|
116
116
|
'headers': directives.unchanged,
|
|
117
117
|
'locale': str,
|
|
118
118
|
'timezone': str,
|
|
119
|
+
'device-scale-factor': directives.positive_int,
|
|
119
120
|
}
|
|
120
121
|
pool = ThreadPoolExecutor()
|
|
121
122
|
|
|
@@ -125,7 +126,7 @@ class ScreenshotDirective(SphinxDirective, Figure):
|
|
|
125
126
|
interactions: str, generate_pdf: bool,
|
|
126
127
|
color_scheme: ColorScheme, full_page: bool,
|
|
127
128
|
context_builder: ContextBuilder, headers: dict,
|
|
128
|
-
locale: typing.Optional[str],
|
|
129
|
+
device_scale_factor: int, locale: typing.Optional[str],
|
|
129
130
|
timezone: typing.Optional[str]):
|
|
130
131
|
"""Takes a screenshot with Playwright's Chromium browser.
|
|
131
132
|
|
|
@@ -145,6 +146,8 @@ class ScreenshotDirective(SphinxDirective, Figure):
|
|
|
145
146
|
full_page (bool): Take a full page screenshot.
|
|
146
147
|
context: A method to build the Playwright context.
|
|
147
148
|
headers (dict): Custom request header.
|
|
149
|
+
device_scale_factor (int): The device scale factor for the screenshot.
|
|
150
|
+
This can be thought of as DPR (device pixel ratio).
|
|
148
151
|
locale (str, optional): User locale for the request.
|
|
149
152
|
timezone (str, optional): User timezone for the request.
|
|
150
153
|
"""
|
|
@@ -160,7 +163,10 @@ class ScreenshotDirective(SphinxDirective, Figure):
|
|
|
160
163
|
(url, context_builder.__name__))
|
|
161
164
|
else:
|
|
162
165
|
context = browser.new_context(
|
|
163
|
-
color_scheme=color_scheme,
|
|
166
|
+
color_scheme=color_scheme,
|
|
167
|
+
locale=locale,
|
|
168
|
+
timezone_id=timezone,
|
|
169
|
+
device_scale_factor=device_scale_factor)
|
|
164
170
|
|
|
165
171
|
page = context.new_page()
|
|
166
172
|
page.set_default_timeout(10000)
|
|
@@ -247,7 +253,9 @@ class ScreenshotDirective(SphinxDirective, Figure):
|
|
|
247
253
|
self.env.config.screenshot_default_timezone)
|
|
248
254
|
context = self.options.get('context', '')
|
|
249
255
|
headers = self.options.get('headers', '')
|
|
250
|
-
|
|
256
|
+
device_scale_factor = self.options.get(
|
|
257
|
+
'device-scale-factor',
|
|
258
|
+
self.env.config.screenshot_default_device_scale_factor)
|
|
251
259
|
request_headers = {**self.env.config.screenshot_default_headers}
|
|
252
260
|
if headers:
|
|
253
261
|
for header in headers.strip().split("\n"):
|
|
@@ -259,7 +267,8 @@ class ScreenshotDirective(SphinxDirective, Figure):
|
|
|
259
267
|
raw_path, browser,
|
|
260
268
|
str(viewport_height),
|
|
261
269
|
str(viewport_width), color_scheme, context, interactions,
|
|
262
|
-
str(full_page)
|
|
270
|
+
str(full_page),
|
|
271
|
+
str(device_scale_factor)
|
|
263
272
|
])
|
|
264
273
|
filename = hashlib.md5(hash_input.encode()).hexdigest() + '.png'
|
|
265
274
|
filepath = os.path.join(ss_dirpath, filename)
|
|
@@ -276,8 +285,8 @@ class ScreenshotDirective(SphinxDirective, Figure):
|
|
|
276
285
|
url_or_filepath, browser, viewport_width,
|
|
277
286
|
viewport_height, filepath, screenshot_init_script,
|
|
278
287
|
interactions, pdf, color_scheme, full_page,
|
|
279
|
-
context_builder, request_headers,
|
|
280
|
-
timezone)
|
|
288
|
+
context_builder, request_headers,
|
|
289
|
+
device_scale_factor, locale, timezone)
|
|
281
290
|
fut.result()
|
|
282
291
|
|
|
283
292
|
# Create image and figure nodes
|
|
@@ -359,6 +368,12 @@ def setup(app: Sphinx) -> Meta:
|
|
|
359
368
|
'screenshot_default_headers', {},
|
|
360
369
|
'env',
|
|
361
370
|
description="The default headers to pass in requests")
|
|
371
|
+
app.add_config_value(
|
|
372
|
+
'screenshot_default_device_scale_factor',
|
|
373
|
+
1,
|
|
374
|
+
'env',
|
|
375
|
+
description="The default device scale factor " +
|
|
376
|
+
"a.k.a. DPR (device pixel ratio)")
|
|
362
377
|
app.add_config_value(
|
|
363
378
|
'screenshot_default_locale',
|
|
364
379
|
None,
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Copyright 2023 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from io import StringIO
|
|
16
|
+
|
|
17
|
+
import pytest
|
|
18
|
+
from bs4 import BeautifulSoup
|
|
19
|
+
from PIL import Image
|
|
20
|
+
from sphinx.testing.util import SphinxTestApp
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@pytest.mark.sphinx('html', testroot='root')
|
|
24
|
+
def test_default(app: SphinxTestApp) -> None:
|
|
25
|
+
app.build()
|
|
26
|
+
|
|
27
|
+
def test_index():
|
|
28
|
+
soup = BeautifulSoup((app.outdir / "index.html").read_text(),
|
|
29
|
+
"html.parser")
|
|
30
|
+
|
|
31
|
+
# Every screenshot directive should become an image.
|
|
32
|
+
imgs = soup.find_all('img')
|
|
33
|
+
assert len(list(imgs)) == 4
|
|
34
|
+
|
|
35
|
+
# The image size should be set as specified.
|
|
36
|
+
img_obj = Image.open(app.outdir / imgs[0]['src'])
|
|
37
|
+
width, height = img_obj.size
|
|
38
|
+
assert width == 480
|
|
39
|
+
assert height == 320
|
|
40
|
+
|
|
41
|
+
# The images should be the same if the difference is only the caption.
|
|
42
|
+
img_with_caption_a = imgs[0]
|
|
43
|
+
img_with_caption_b = imgs[1]
|
|
44
|
+
assert img_with_caption_a['src'] == img_with_caption_b['src']
|
|
45
|
+
|
|
46
|
+
# The images should be different after the specified user interaction.
|
|
47
|
+
imgsrc_before_interaction = app.outdir / imgs[1]['src']
|
|
48
|
+
imgsrc_after_interaction = app.outdir / imgs[2]['src']
|
|
49
|
+
assert imgsrc_before_interaction != imgsrc_after_interaction
|
|
50
|
+
assert list(Image.open(imgsrc_before_interaction).getdata()) != list(
|
|
51
|
+
Image.open(imgsrc_after_interaction).getdata())
|
|
52
|
+
|
|
53
|
+
# High reso image should have a larger size.
|
|
54
|
+
imgsrc_standard = app.outdir / imgs[0]['src']
|
|
55
|
+
imgsrc_highreso = app.outdir / imgs[3]['src']
|
|
56
|
+
assert (Image.open(imgsrc_highreso).width ==
|
|
57
|
+
Image.open(imgsrc_standard).width * 2)
|
|
58
|
+
|
|
59
|
+
def test_sections_index():
|
|
60
|
+
soup = BeautifulSoup((app.outdir / "sections" / "index.html").read_text(),
|
|
61
|
+
"html.parser")
|
|
62
|
+
|
|
63
|
+
# Every screenshot directive should become an image.
|
|
64
|
+
imgs = soup.find_all('img')
|
|
65
|
+
assert len(list(imgs)) == 2
|
|
66
|
+
|
|
67
|
+
# The images should be the same.
|
|
68
|
+
imgsrc_relative = app.outdir / "sections" / imgs[0]['src']
|
|
69
|
+
imgsrc_absolute = app.outdir / "sections" / imgs[1]['src']
|
|
70
|
+
assert imgsrc_relative != imgsrc_absolute
|
|
71
|
+
assert list(Image.open(imgsrc_relative).getdata()) == list(
|
|
72
|
+
Image.open(imgsrc_absolute).getdata())
|
|
73
|
+
|
|
74
|
+
test_index()
|
|
75
|
+
test_sections_index()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@pytest.mark.sphinx('html', testroot="default-size")
|
|
79
|
+
def test_default_size(app: SphinxTestApp, status: StringIO, warning: StringIO,
|
|
80
|
+
image_regression) -> None:
|
|
81
|
+
"""Test the 'screenshot_default_viewport_width' and
|
|
82
|
+
'screenshot_default_viewport_height' configuration parameters."""
|
|
83
|
+
app.build()
|
|
84
|
+
out_html = app.outdir / "index.html"
|
|
85
|
+
|
|
86
|
+
soup = BeautifulSoup(out_html.read_text(), "html.parser")
|
|
87
|
+
imgs = soup.find_all('img')
|
|
88
|
+
|
|
89
|
+
img_obj = Image.open(app.outdir / imgs[0]['src'])
|
|
90
|
+
width, height = img_obj.size
|
|
91
|
+
assert width == 1920
|
|
92
|
+
assert height == 1200
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 Google LLC
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from io import StringIO
|
|
16
|
-
|
|
17
|
-
import pytest
|
|
18
|
-
from bs4 import BeautifulSoup
|
|
19
|
-
from PIL import Image
|
|
20
|
-
from sphinx.testing.util import SphinxTestApp
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@pytest.mark.sphinx('html', testroot='root')
|
|
24
|
-
def test_default(app: SphinxTestApp) -> None:
|
|
25
|
-
app.build()
|
|
26
|
-
soup = BeautifulSoup((app.outdir / "index.html").read_text(), "html.parser")
|
|
27
|
-
|
|
28
|
-
# Every screenshot directive should become an image.
|
|
29
|
-
imgs = soup.find_all('img')
|
|
30
|
-
assert len(list(imgs)) == 3
|
|
31
|
-
|
|
32
|
-
# The image size should be set as specified.
|
|
33
|
-
img_obj = Image.open(app.outdir / imgs[0]['src'])
|
|
34
|
-
width, height = img_obj.size
|
|
35
|
-
assert width == 480
|
|
36
|
-
assert height == 320
|
|
37
|
-
|
|
38
|
-
# The images should be different after the specified user interaction.
|
|
39
|
-
imgsrc_before_interaction = app.outdir / imgs[1]['src']
|
|
40
|
-
imgsrc_after_interaction = app.outdir / imgs[2]['src']
|
|
41
|
-
assert imgsrc_before_interaction != imgsrc_after_interaction
|
|
42
|
-
assert list(Image.open(imgsrc_before_interaction).getdata()) != list(
|
|
43
|
-
Image.open(imgsrc_after_interaction).getdata())
|
|
44
|
-
|
|
45
|
-
soup = BeautifulSoup((app.outdir / "sections" / "index.html").read_text(),
|
|
46
|
-
"html.parser")
|
|
47
|
-
|
|
48
|
-
# Every screenshot directive should become an image.
|
|
49
|
-
imgs = soup.find_all('img')
|
|
50
|
-
assert len(list(imgs)) == 2
|
|
51
|
-
|
|
52
|
-
# The images should be the same.
|
|
53
|
-
imgsrc_relative = app.outdir / "sections" / imgs[0]['src']
|
|
54
|
-
imgsrc_absolute = app.outdir / "sections" / imgs[1]['src']
|
|
55
|
-
assert imgsrc_relative != imgsrc_absolute
|
|
56
|
-
assert list(Image.open(imgsrc_relative).getdata()) == list(
|
|
57
|
-
Image.open(imgsrc_absolute).getdata())
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@pytest.mark.sphinx('html', testroot="default-size")
|
|
61
|
-
def test_default_size(app: SphinxTestApp, status: StringIO, warning: StringIO,
|
|
62
|
-
image_regression) -> None:
|
|
63
|
-
"""Test the 'screenshot_default_viewport_width' and
|
|
64
|
-
'screenshot_default_viewport_height' configuration parameters."""
|
|
65
|
-
app.build()
|
|
66
|
-
out_html = app.outdir / "index.html"
|
|
67
|
-
|
|
68
|
-
soup = BeautifulSoup(out_html.read_text(), "html.parser")
|
|
69
|
-
imgs = soup.find_all('img')
|
|
70
|
-
|
|
71
|
-
img_obj = Image.open(app.outdir / imgs[0]['src'])
|
|
72
|
-
width, height = img_obj.size
|
|
73
|
-
assert width == 1920
|
|
74
|
-
assert height == 1200
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sphinxcontrib_screenshot-0.2.1 → sphinxcontrib_screenshot-0.2.2}/tests/test_color_scheme.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|