|
1 | | -import base64 |
2 | | -import binascii |
3 | 1 | import datetime |
4 | 2 | import json |
5 | 3 | import os |
|
14 | 12 | from jinja2 import FileSystemLoader |
15 | 13 | from jinja2 import select_autoescape |
16 | 14 |
|
17 | | -from . import __version__ |
18 | | -from . import extras |
19 | | -from .util import cleanup_unserializable |
| 15 | +from pytest_html import __version__ |
| 16 | +from pytest_html import extras |
| 17 | +from pytest_html.util import cleanup_unserializable |
20 | 18 |
|
21 | 19 |
|
22 | 20 | try: |
@@ -217,10 +215,7 @@ def _process_extras(self, report, test_id): |
217 | 215 | content, asset_name=asset_name, mime_type=extra["mime_type"] |
218 | 216 | ) |
219 | 217 |
|
220 | | - if ( |
221 | | - extra["format_type"] == extras.FORMAT_IMAGE |
222 | | - or extra["format_type"] == extras.FORMAT_VIDEO |
223 | | - ): |
| 218 | + if extra["format_type"] in [extras.FORMAT_IMAGE, extras.FORMAT_VIDEO]: |
224 | 219 | extra["content"] = self._media_content( |
225 | 220 | content, asset_name=asset_name, mime_type=extra["mime_type"] |
226 | 221 | ) |
@@ -329,69 +324,6 @@ def pytest_runtest_logreport(self, report): |
329 | 324 | self._generate_report() |
330 | 325 |
|
331 | 326 |
|
332 | | -class NextGenReport(BaseReport): |
333 | | - def __init__(self, report_path, config): |
334 | | - super().__init__(report_path, config) |
335 | | - self._assets_path = Path(self._report_path.parent, "assets") |
336 | | - self._assets_path.mkdir(parents=True, exist_ok=True) |
337 | | - self._css_path = Path(self._assets_path, "style.css") |
338 | | - |
339 | | - with self._css_path.open("w", encoding="utf-8") as f: |
340 | | - f.write(self._css) |
341 | | - |
342 | | - @property |
343 | | - def css(self): |
344 | | - return Path(self._assets_path.name, "style.css") |
345 | | - |
346 | | - def _data_content(self, content, asset_name, *args, **kwargs): |
347 | | - content = content.encode("utf-8") |
348 | | - return self._write_content(content, asset_name) |
349 | | - |
350 | | - def _media_content(self, content, asset_name, *args, **kwargs): |
351 | | - try: |
352 | | - media_data = base64.b64decode(content.encode("utf-8"), validate=True) |
353 | | - return self._write_content(media_data, asset_name) |
354 | | - except binascii.Error: |
355 | | - # if not base64 content, just return as it's a file or link |
356 | | - return content |
357 | | - |
358 | | - def _write_content(self, content, asset_name): |
359 | | - content_relative_path = Path(self._assets_path, asset_name) |
360 | | - content_relative_path.write_bytes(content) |
361 | | - return str(content_relative_path.relative_to(self._report_path.parent)) |
362 | | - |
363 | | - |
364 | | -class NextGenSelfContainedReport(BaseReport): |
365 | | - def __init__(self, report_path, config): |
366 | | - super().__init__(report_path, config) |
367 | | - |
368 | | - @property |
369 | | - def css(self): |
370 | | - return self._css |
371 | | - |
372 | | - def _data_content(self, content, mime_type, *args, **kwargs): |
373 | | - charset = "utf-8" |
374 | | - data = base64.b64encode(content.encode(charset)).decode(charset) |
375 | | - return f"data:{mime_type};charset={charset};base64,{data}" |
376 | | - |
377 | | - def _media_content(self, content, mime_type, *args, **kwargs): |
378 | | - try: |
379 | | - # test if content is base64 |
380 | | - base64.b64decode(content.encode("utf-8"), validate=True) |
381 | | - return f"data:{mime_type};base64,{content}" |
382 | | - except binascii.Error: |
383 | | - # if not base64, issue warning and just return as it's a file or link |
384 | | - warnings.warn( |
385 | | - "Self-contained HTML report " |
386 | | - "includes link to external " |
387 | | - f"resource: {content}" |
388 | | - ) |
389 | | - return content |
390 | | - |
391 | | - def _generate_report(self, *args, **kwargs): |
392 | | - super()._generate_report(self_contained=True) |
393 | | - |
394 | | - |
395 | 327 | def _process_css(default_css, extra_css): |
396 | 328 | with open(default_css, encoding="utf-8") as f: |
397 | 329 | css = f.read() |
|
0 commit comments