briefing 0.2.2__tar.gz → 0.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.
Files changed (107) hide show
  1. {briefing-0.2.2 → briefing-0.2.4}/CHANGELOG.md +28 -1
  2. {briefing-0.2.2 → briefing-0.2.4}/PKG-INFO +1 -1
  3. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/__init__.py +1 -1
  4. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/blocks/layout.py +52 -20
  5. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/html.py +3 -3
  6. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/table.py +6 -3
  7. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/static/export.js +9 -9
  8. {briefing-0.2.2 → briefing-0.2.4}/tests/contract.py +1 -1
  9. {briefing-0.2.2 → briefing-0.2.4}/tests/test_blocks/test_layout.py +17 -0
  10. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_export_image.py +2 -2
  11. briefing-0.2.4/tests/test_browser/test_export_menu.py +93 -0
  12. {briefing-0.2.2 → briefing-0.2.4}/tests/test_contract.py +7 -3
  13. {briefing-0.2.2 → briefing-0.2.4}/tests/test_deprecations.py +26 -0
  14. {briefing-0.2.2 → briefing-0.2.4}/tests/test_docs_gallery.py +1 -12
  15. briefing-0.2.4/tests/test_renderers/test_export_menu.py +74 -0
  16. {briefing-0.2.2 → briefing-0.2.4}/tests/test_renderers/test_table.py +12 -0
  17. briefing-0.2.2/tests/test_browser/test_export_menu.py +0 -55
  18. briefing-0.2.2/tests/test_renderers/test_export_menu.py +0 -46
  19. {briefing-0.2.2 → briefing-0.2.4}/.gitignore +0 -0
  20. {briefing-0.2.2 → briefing-0.2.4}/LICENSE +0 -0
  21. {briefing-0.2.2 → briefing-0.2.4}/README.md +0 -0
  22. {briefing-0.2.2 → briefing-0.2.4}/noxfile.py +0 -0
  23. {briefing-0.2.2 → briefing-0.2.4}/pyproject.toml +0 -0
  24. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/__main__.py +0 -0
  25. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/_cli.py +0 -0
  26. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/_error.py +0 -0
  27. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/_frames.py +0 -0
  28. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/_preview.py +0 -0
  29. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/blocks/__init__.py +0 -0
  30. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/blocks/asset.py +0 -0
  31. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/blocks/banner.py +0 -0
  32. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/blocks/base.py +0 -0
  33. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/blocks/text.py +0 -0
  34. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/export/__init__.py +0 -0
  35. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/export/_image.py +0 -0
  36. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/export/_pdf.py +0 -0
  37. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/export/_render.py +0 -0
  38. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/lab/__init__.py +0 -0
  39. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/lab/_blocks.py +0 -0
  40. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/lab/_render_calendar.py +0 -0
  41. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/lab/_render_datadive.py +0 -0
  42. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/lab/_render_profile.py +0 -0
  43. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/lab/static/calendar.js +0 -0
  44. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/lab/static/lab.js +0 -0
  45. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/py.typed +0 -0
  46. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/__init__.py +0 -0
  47. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/formatting.py +0 -0
  48. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/formula.py +0 -0
  49. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/normalize.py +0 -0
  50. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/plot.py +0 -0
  51. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/registry.py +0 -0
  52. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/renderers/script_json.py +0 -0
  53. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/static/export.css +0 -0
  54. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/static/report.css +0 -0
  55. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/static/report.js +0 -0
  56. {briefing-0.2.2 → briefing-0.2.4}/src/briefing/templates/report.html.j2 +0 -0
  57. {briefing-0.2.2 → briefing-0.2.4}/tests/__init__.py +0 -0
  58. {briefing-0.2.2 → briefing-0.2.4}/tests/banner_images.py +0 -0
  59. {briefing-0.2.2 → briefing-0.2.4}/tests/compat_reports.py +0 -0
  60. {briefing-0.2.2 → briefing-0.2.4}/tests/conftest.py +0 -0
  61. {briefing-0.2.2 → briefing-0.2.4}/tests/html_helpers.py +0 -0
  62. {briefing-0.2.2 → briefing-0.2.4}/tests/image_helpers.py +0 -0
  63. {briefing-0.2.2 → briefing-0.2.4}/tests/pdf_reader.py +0 -0
  64. {briefing-0.2.2 → briefing-0.2.4}/tests/snapshots/compat_0_1_2/blocks.body.html +0 -0
  65. {briefing-0.2.2 → briefing-0.2.4}/tests/snapshots/compat_0_1_2/pages.body.html +0 -0
  66. {briefing-0.2.2 → briefing-0.2.4}/tests/test_blocks/__init__.py +0 -0
  67. {briefing-0.2.2 → briefing-0.2.4}/tests/test_blocks/test_banner.py +0 -0
  68. {briefing-0.2.2 → briefing-0.2.4}/tests/test_blocks/test_base.py +0 -0
  69. {briefing-0.2.2 → briefing-0.2.4}/tests/test_blocks/test_text.py +0 -0
  70. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/__init__.py +0 -0
  71. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/conftest.py +0 -0
  72. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_banner.py +0 -0
  73. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_bignumber.py +0 -0
  74. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_calendar.py +0 -0
  75. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_cli_export.py +0 -0
  76. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_code.py +0 -0
  77. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_datadive.py +0 -0
  78. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_datatable.py +0 -0
  79. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_export_pdf.py +0 -0
  80. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_formula.py +0 -0
  81. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_layout.py +0 -0
  82. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_notebook.py +0 -0
  83. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_plots.py +0 -0
  84. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_print.py +0 -0
  85. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_spacing.py +0 -0
  86. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_text.py +0 -0
  87. {briefing-0.2.2 → briefing-0.2.4}/tests/test_browser/test_toggle_theme.py +0 -0
  88. {briefing-0.2.2 → briefing-0.2.4}/tests/test_cli.py +0 -0
  89. {briefing-0.2.2 → briefing-0.2.4}/tests/test_compat.py +0 -0
  90. {briefing-0.2.2 → briefing-0.2.4}/tests/test_docstrings.py +0 -0
  91. {briefing-0.2.2 → briefing-0.2.4}/tests/test_export.py +0 -0
  92. {briefing-0.2.2 → briefing-0.2.4}/tests/test_frames.py +0 -0
  93. {briefing-0.2.2 → briefing-0.2.4}/tests/test_lab/__init__.py +0 -0
  94. {briefing-0.2.2 → briefing-0.2.4}/tests/test_lab/test_calendar.py +0 -0
  95. {briefing-0.2.2 → briefing-0.2.4}/tests/test_lab/test_datadive.py +0 -0
  96. {briefing-0.2.2 → briefing-0.2.4}/tests/test_lab/test_lab_boundary.py +0 -0
  97. {briefing-0.2.2 → briefing-0.2.4}/tests/test_lab/test_profile.py +0 -0
  98. {briefing-0.2.2 → briefing-0.2.4}/tests/test_no_viz_deps.py +0 -0
  99. {briefing-0.2.2 → briefing-0.2.4}/tests/test_pdf_reader.py +0 -0
  100. {briefing-0.2.2 → briefing-0.2.4}/tests/test_preview.py +0 -0
  101. {briefing-0.2.2 → briefing-0.2.4}/tests/test_readme.py +0 -0
  102. {briefing-0.2.2 → briefing-0.2.4}/tests/test_renderers/__init__.py +0 -0
  103. {briefing-0.2.2 → briefing-0.2.4}/tests/test_renderers/test_formula.py +0 -0
  104. {briefing-0.2.2 → briefing-0.2.4}/tests/test_renderers/test_html.py +0 -0
  105. {briefing-0.2.2 → briefing-0.2.4}/tests/test_renderers/test_normalize.py +0 -0
  106. {briefing-0.2.2 → briefing-0.2.4}/tests/test_renderers/test_plot.py +0 -0
  107. {briefing-0.2.2 → briefing-0.2.4}/tests/test_renderers/test_reproducible.py +0 -0
@@ -10,6 +10,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.2.4] - 2026-11-17
14
+
15
+ ### Fixed
16
+
17
+ - The export menu's "Save as PNG" keeps a 32 px margin of page background around the report,
18
+ so content no longer touches the edge of the image (#119).
19
+
20
+ ### Deprecated
21
+
22
+ - `bf.Briefing(..., export="pdf")` no longer adds a "Print" button: it only opened the
23
+ browser's print dialog, which Ctrl+P / ⌘P opens with the same print layout. It still runs,
24
+ with a `DeprecationWarning`; from 0.4.0 it raises an error. Use `export="png"` for the
25
+ "Save as PNG" button, and `bf.save_pdf` for a PDF file (#119).
26
+
27
+ ## [0.2.3] - 2026-11-07
28
+
29
+ ### Fixed
30
+
31
+ - `Group` rejects a `columns` that isn't a whole number of 1 or more, and `widths` that
32
+ aren't positive numbers, with a `BriefingError`. They used to be accepted and wrote invalid
33
+ CSS, so the browser dropped the layout without saying so (#98).
34
+ - `Table` with a pandas `Styler` gives the same bytes on every run: its ids and CSS selectors
35
+ come from the report instead of the random uuid pandas picks. The `Styler` you pass keeps
36
+ its own uuid (#101).
37
+
13
38
  ## [0.2.2] - 2026-11-04
14
39
 
15
40
  ### Added
@@ -240,7 +265,9 @@ First public release.
240
265
  inherits its base's renderer.
241
266
  - Ships inline type hints (`py.typed`). Python 3.11+.
242
267
 
243
- [Unreleased]: https://github.com/jeanmidevacc/briefing/compare/v0.2.2...HEAD
268
+ [Unreleased]: https://github.com/jeanmidevacc/briefing/compare/v0.2.4...HEAD
269
+ [0.2.4]: https://github.com/jeanmidevacc/briefing/compare/v0.2.3...v0.2.4
270
+ [0.2.3]: https://github.com/jeanmidevacc/briefing/compare/v0.2.2...v0.2.3
244
271
  [0.2.2]: https://github.com/jeanmidevacc/briefing/compare/v0.2.1...v0.2.2
245
272
  [0.2.1]: https://github.com/jeanmidevacc/briefing/compare/v0.2.0...v0.2.1
246
273
  [0.2.0]: https://github.com/jeanmidevacc/briefing/compare/v0.1.2...v0.2.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: briefing
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Build beautiful self-contained HTML reports from Python analysis
5
5
  Project-URL: Homepage, https://github.com/jeanmidevacc/briefing
6
6
  Project-URL: Documentation, https://briefing.readthedocs.io
@@ -134,7 +134,7 @@ def stringify(
134
134
  return render_report(wrapped, name=name, formatting=formatting, now=now)
135
135
 
136
136
 
137
- __version__ = "0.2.2"
137
+ __version__ = "0.2.4"
138
138
 
139
139
  __all__: list[str] = [
140
140
  # error
@@ -1,6 +1,8 @@
1
1
  """Layout and container blocks: Group, Select, Toggle, Page, Briefing."""
2
2
  from __future__ import annotations
3
3
 
4
+ import math
5
+ import numbers
4
6
  import typing as t
5
7
  import warnings
6
8
  from collections.abc import Sequence
@@ -37,6 +39,12 @@ class VAlign(StrEnum):
37
39
  BOTTOM = "bottom"
38
40
 
39
41
 
42
+ def _is_positive_number(value: object, *, whole: bool = False) -> bool:
43
+ """Whether *value* is a finite number above zero; ``True`` and ``False`` don't count."""
44
+ kind = numbers.Integral if whole else numbers.Real
45
+ return isinstance(value, kind) and not isinstance(value, bool) and 0 < float(value) < math.inf
46
+
47
+
40
48
  # ── layout blocks ─────────────────────────────────────────────────────────────
41
49
 
42
50
 
@@ -49,8 +57,8 @@ class Group(ContainerBlock):
49
57
  Args:
50
58
  *arg_blocks: The child blocks; strings become ``Text`` and dataframes ``DataTable``.
51
59
  blocks: The children as a list, instead of positional arguments.
52
- columns: Number of grid columns.
53
- widths: Relative column widths, one per column (e.g. ``[2, 1]``).
60
+ columns: Number of grid columns, a whole number of 1 or more.
61
+ widths: Relative column widths, positive numbers, one per column (e.g. ``[2, 1]``).
54
62
  valign: Vertical alignment of the cells: ``"top"``, ``"center"`` or ``"bottom"``.
55
63
  name: Stable block id (letters, digits, ``_`` and ``-``), for referencing the block.
56
64
  label: Tab or dropdown label when the block is inside a ``Select``.
@@ -73,12 +81,18 @@ class Group(ContainerBlock):
73
81
  name: BlockId | None = None,
74
82
  label: str | None = None,
75
83
  ) -> None:
76
- if widths is not None and len(widths) != columns:
77
- raise BriefingError(
78
- f"Group 'widths' length ({len(widths)}) must match 'columns' ({columns})."
79
- )
84
+ if not _is_positive_number(columns, whole=True):
85
+ raise BriefingError(f"Group 'columns' must be a whole number of 1 or more, not {columns!r}.")
86
+ if widths is not None:
87
+ if len(widths) != columns:
88
+ raise BriefingError(
89
+ f"Group 'widths' length ({len(widths)}) must match 'columns' ({columns})."
90
+ )
91
+ for width in widths:
92
+ if not _is_positive_number(width):
93
+ raise BriefingError(f"Group 'widths' must be positive numbers such as [2, 1], not {width!r}.")
80
94
  super().__init__(*arg_blocks, blocks=blocks, name=name, label=label)
81
- self.columns = columns
95
+ self.columns = int(columns)
82
96
  self.widths = widths
83
97
  self.valign = VAlign(valign)
84
98
 
@@ -190,6 +204,14 @@ class Page(ContainerBlock):
190
204
  self.title = title
191
205
 
192
206
 
207
+ EXPORT_PDF_DEPRECATION = (
208
+ "Briefing(export='pdf') is deprecated and no longer adds a 'Print' button: it only opened the browser's "
209
+ "print dialog, which Ctrl+P (Cmd+P on a Mac) opens with the same print layout. For a PDF file, use "
210
+ "bf.save_pdf(report, 'report.pdf'). From 0.4.0, export='pdf' raises an error; pass export='png' for the "
211
+ "'Save as PNG' button, or leave export out."
212
+ )
213
+
214
+
193
215
  class Briefing(ContainerBlock):
194
216
  """Root document container.
195
217
 
@@ -199,19 +221,22 @@ class Briefing(ContainerBlock):
199
221
  *arg_blocks: The report's blocks, in order.
200
222
  blocks: The blocks as a list, instead of positional arguments.
201
223
  export: Opt-in export menu in the report header: ``"png"`` adds "Save as
202
- PNG" (the open page, drawn in the reader's browser at 2×) and ``"pdf"``
203
- adds "Print" (the print dialog, which can save a PDF). Reports without
204
- it contain no export code. "Save as PNG" is best effort: charts
205
- drawn in iframes (Bokeh) and WebGL Plotly traces come out blank, and
206
- fonts are whatever the reader's machine has. For exact, reproducible
207
- files use :func:`~briefing.save_image` / :func:`~briefing.save_pdf`.
224
+ PNG" (the open page with a margin around it, drawn in the reader's
225
+ browser at 2×). Reports without it contain no export code. "Save as
226
+ PNG" is best effort: charts drawn in iframes (Bokeh) and WebGL Plotly
227
+ traces come out blank, and fonts are whatever the reader's machine
228
+ has. For exact, reproducible files use :func:`~briefing.save_image` /
229
+ :func:`~briefing.save_pdf`. To print, use the browser's own print
230
+ (Ctrl+P or ⌘P): it gets the same print layout. *Deprecated:*
231
+ ``"pdf"`` (the "Print" button) raises a ``DeprecationWarning`` and
232
+ adds nothing; it will be rejected from 0.4.0.
208
233
 
209
234
  Example::
210
235
 
211
236
  report = bf.Briefing(
212
237
  bf.Text("# My report"),
213
238
  bf.Plot(fig),
214
- export=("png", "pdf"),
239
+ export="png",
215
240
  )
216
241
  bf.save(report, "report.html")
217
242
  """
@@ -219,7 +244,9 @@ class Briefing(ContainerBlock):
219
244
  min_blocks: t.ClassVar[int] = 1
220
245
 
221
246
  #: The actions export= accepts, in menu order.
222
- EXPORTS: t.ClassVar[tuple[str, ...]] = ("png", "pdf")
247
+ EXPORTS: t.ClassVar[tuple[str, ...]] = ("png",)
248
+ #: Accepted with a DeprecationWarning, and dropped: they add no button.
249
+ DEPRECATED_EXPORTS: t.ClassVar[dict[str, str]] = {"pdf": EXPORT_PDF_DEPRECATION}
223
250
  export: tuple[str, ...]
224
251
 
225
252
  def __init__(
@@ -238,11 +265,16 @@ class Briefing(ContainerBlock):
238
265
  @classmethod
239
266
  def _check_export(cls, export: object) -> tuple[str, ...]:
240
267
  actions = (export,) if isinstance(export, str) else export
241
- if not isinstance(actions, Sequence) or any(a not in cls.EXPORTS for a in actions):
242
- raise BriefingError(
243
- f"export accepts 'png' and/or 'pdf', for example export=('png', 'pdf'); got {export!r}."
244
- )
245
- return tuple(dict.fromkeys(t.cast("Sequence[str]", actions)))
268
+ if not isinstance(actions, Sequence) or any(
269
+ a not in cls.EXPORTS and a not in cls.DEPRECATED_EXPORTS for a in actions
270
+ ):
271
+ raise BriefingError(f"export accepts 'png', for example export='png'; got {export!r}.")
272
+ unique = tuple(dict.fromkeys(t.cast("Sequence[str]", actions)))
273
+ for action in unique:
274
+ if action in cls.DEPRECATED_EXPORTS:
275
+ # stacklevel 3: _check_export <- __init__ <- the caller's bf.Briefing(...)
276
+ warnings.warn(cls.DEPRECATED_EXPORTS[action], DeprecationWarning, stacklevel=3)
277
+ return tuple(a for a in unique if a in cls.EXPORTS)
246
278
 
247
279
  @classmethod
248
280
  def wrap(
@@ -57,7 +57,7 @@ _CSS = _load_static("report.css")
57
57
  _JS = _load_static("report.js")
58
58
  _EXPORT_JS = _load_static("export.js")
59
59
  _EXPORT_CSS = _load_static("export.css")
60
- _EXPORT_LABELS = {"png": "Save as PNG", "pdf": "Print"}
60
+ _EXPORT_LABELS = {"png": "Save as PNG"}
61
61
 
62
62
  _jinja_env = Environment(
63
63
  loader=PackageLoader("briefing", "templates"),
@@ -317,8 +317,8 @@ def _render_plot(block: Plot, idgen: _IdGen) -> str:
317
317
 
318
318
 
319
319
  @renderer_for(Table)
320
- def _render_table(block: Table, _: _IdGen) -> str:
321
- return render_table(block)
320
+ def _render_table(block: Table, idgen: _IdGen) -> str:
321
+ return render_table(block, idgen)
322
322
 
323
323
 
324
324
  @renderer_for(DataTable)
@@ -19,6 +19,7 @@ HTML contains the full data set, so the table works offline forever.
19
19
  """
20
20
  from __future__ import annotations
21
21
 
22
+ import copy
22
23
  import html as _html
23
24
  import math
24
25
  import numbers
@@ -26,6 +27,7 @@ import typing as t
26
27
  from datetime import date, timedelta
27
28
 
28
29
  from briefing._error import BriefingError
30
+ from briefing.renderers.registry import IdGen
29
31
 
30
32
  if t.TYPE_CHECKING:
31
33
  from briefing.blocks.asset import DataTable, Table
@@ -100,7 +102,7 @@ def _use_index(df: t.Any) -> bool:
100
102
  # ── static Table ──────────────────────────────────────────────────────────────
101
103
 
102
104
 
103
- def render_table(block: Table) -> str:
105
+ def render_table(block: Table, idgen: IdGen | None = None) -> str:
104
106
  """Render a :class:`~briefing.Table` block to a static HTML table fragment."""
105
107
  try:
106
108
  from pandas.io.formats.style import Styler
@@ -112,8 +114,9 @@ def render_table(block: Table) -> str:
112
114
  data = block.data
113
115
 
114
116
  if isinstance(data, Styler):
115
- # Styler.to_html() returns a full <style>+<table> fragment; use it as-is.
116
- table_html = data.to_html()
117
+ # A full <style>+<table> fragment, used as it is apart from the id: pandas puts a random
118
+ # uuid in every id and selector. The copy leaves the caller's Styler as it was.
119
+ table_html = copy.copy(data).set_uuid((idgen or IdGen()).next("table")).to_html()
117
120
  else:
118
121
  table_html = data.to_html(
119
122
  classes="bf-table__table",
@@ -39,6 +39,10 @@
39
39
  }
40
40
 
41
41
  // Draw the report as it is on screen (the open page) into a canvas at 2x and download it.
42
+ // The image keeps this much of the page background around the report on every side
43
+ // (CSS px, the page's own top padding), so content never touches the image's edge.
44
+ var MARGIN = 32;
45
+
42
46
  function savePng() {
43
47
  var report = document.querySelector('.bf-report');
44
48
  var rect = report.getBoundingClientRect();
@@ -52,13 +56,13 @@
52
56
  var image = new Image();
53
57
  image.onload = function () {
54
58
  var canvas = document.createElement('canvas');
55
- canvas.width = width * scale;
56
- canvas.height = height * scale;
59
+ canvas.width = (width + 2 * MARGIN) * scale;
60
+ canvas.height = (height + 2 * MARGIN) * scale;
57
61
  var ctx = canvas.getContext('2d');
58
62
  ctx.fillStyle = background;
59
63
  ctx.fillRect(0, 0, canvas.width, canvas.height);
60
64
  ctx.scale(scale, scale);
61
- ctx.drawImage(image, 0, 0);
65
+ ctx.drawImage(image, MARGIN, MARGIN);
62
66
  canvas.toBlob(function (blob) {
63
67
  var link = document.createElement('a');
64
68
  link.href = URL.createObjectURL(blob);
@@ -72,10 +76,6 @@
72
76
  image.src = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
73
77
  }
74
78
 
75
- menu.querySelectorAll('.bf-export__btn').forEach(function (button) {
76
- button.addEventListener('click', function () {
77
- if (button.getAttribute('data-export') === 'png') savePng();
78
- else window.print();
79
- });
80
- });
79
+ var png = menu.querySelector('.bf-export__btn[data-export="png"]');
80
+ if (png) png.addEventListener('click', savePng);
81
81
  })();
@@ -150,7 +150,7 @@ RULES: dict[str, Callable[[Tag], None]] = {
150
150
 
151
151
 
152
152
  def check_deterministic(render: Callable[[], str]) -> None:
153
- """Two renders of the same report are byte-identical (run with ``SOURCE_DATE_EPOCH`` set)."""
153
+ """Two calls to *render* give byte-identical output (run with ``SOURCE_DATE_EPOCH`` set)."""
154
154
  first, second = render(), render()
155
155
  if first != second:
156
156
  pairs = enumerate(zip(first, second, strict=False))
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
 
4
4
  import warnings
5
5
 
6
+ import numpy as np
6
7
  import pytest
7
8
 
8
9
  from briefing._error import BriefingError
@@ -34,6 +35,22 @@ class TestGroup:
34
35
  g = Group(blocks=items, columns=2)
35
36
  assert len(g) == 2
36
37
 
38
+ @pytest.mark.parametrize("columns", [0, -1, 1.5, 2.0, True, "2", None])
39
+ def test_columns_must_be_a_whole_number_of_one_or_more(self, columns):
40
+ with pytest.raises(BriefingError, match="'columns' must be a whole number of 1 or more"):
41
+ Group(*make_texts(2), columns=columns)
42
+
43
+ @pytest.mark.parametrize("width", [0, -1, float("nan"), float("inf"), True, "1", None])
44
+ def test_widths_must_be_positive_numbers(self, width):
45
+ with pytest.raises(BriefingError, match="'widths' must be positive numbers"):
46
+ Group(*make_texts(2), columns=2, widths=[1, width])
47
+
48
+ @pytest.mark.parametrize(("columns", "widths"), [(np.int64(2), [np.int64(2), np.float64(1.5)])])
49
+ def test_numpy_numbers_work_like_python_ones(self, columns, widths):
50
+ g = Group(*make_texts(2), columns=columns, widths=widths)
51
+ assert g.columns == 2
52
+ assert type(g.columns) is int
53
+
37
54
  def test_widths_correct_length(self):
38
55
  g = Group(*make_texts(2), columns=2, widths=[2, 1])
39
56
  assert g.widths == [2, 1]
@@ -144,7 +144,7 @@ def _with_menu(export: tuple[str, ...]) -> bf.Briefing:
144
144
 
145
145
  def test_export_menu_is_hidden_while_exporting() -> None:
146
146
  def check() -> None:
147
- with open_report(_with_menu(("png", "pdf")), width=800, scale=1, name="Q1") as session:
147
+ with open_report(_with_menu(("png",)), width=800, scale=1, name="Q1") as session:
148
148
  assert session.page.locator(".bf-export").count() == 1
149
149
  assert not session.page.locator(".bf-export").is_visible()
150
150
 
@@ -153,6 +153,6 @@ def test_export_menu_is_hidden_while_exporting() -> None:
153
153
 
154
154
  def test_images_leave_the_export_menu_out(tmp_path: Path) -> None:
155
155
  """#100: a report with export= exports the same image as one without it."""
156
- with_menu = bf.save_image(_with_menu(("png", "pdf")), tmp_path / "menu.png", width=800, scale=1, name="Q1")
156
+ with_menu = bf.save_image(_with_menu(("png",)), tmp_path / "menu.png", width=800, scale=1, name="Q1")
157
157
  without = bf.save_image(_with_menu(()), tmp_path / "plain.png", width=800, scale=1, name="Q1")
158
158
  assert with_menu[0].read_bytes() == without[0].read_bytes()
@@ -0,0 +1,93 @@
1
+ """The in-report export menu works in Chromium (#49)."""
2
+ from __future__ import annotations
3
+
4
+ import base64
5
+ from pathlib import Path
6
+
7
+ import pandas as pd
8
+ from playwright.sync_api import Page
9
+
10
+ import briefing as bf
11
+ from tests.image_helpers import png_size
12
+ from tests.pdf_reader import read_pdf
13
+ from tests.test_browser.conftest import Viewer
14
+
15
+ #: The page background kept around the report in a "Save as PNG" image, in CSS px (export.js MARGIN).
16
+ MARGIN = 32
17
+
18
+
19
+ def _report() -> bf.Briefing:
20
+ return bf.Briefing(
21
+ bf.Page(bf.Text("# Summary\n\nShort."), bf.BigNumber("Revenue", "$4.2M"), title="Summary"),
22
+ bf.Page(bf.Text("# Detail"), bf.DataTable(pd.DataFrame({"n": range(30)})), title="Detail"),
23
+ export="png",
24
+ )
25
+
26
+
27
+ def _report_size(page: Page) -> tuple[float, float]:
28
+ box = page.locator(".bf-report").bounding_box()
29
+ assert box is not None
30
+ return box["width"], box["height"]
31
+
32
+
33
+ def test_save_as_png_downloads_the_current_page_at_2x(viewer: Viewer, tmp_path: Path) -> None:
34
+ page = viewer.open(_report(), name="Q1 Report")
35
+ page.get_by_role("tab", name="Detail").click()
36
+ width, height = _report_size(page)
37
+ with page.expect_download() as download:
38
+ page.get_by_role("button", name="Save as PNG").click()
39
+ saved = tmp_path / download.value.suggested_filename
40
+ download.value.save_as(saved)
41
+ assert saved.name == "q1_report_detail.png"
42
+ w, h = png_size(saved)
43
+ assert abs(w - 2 * (width + 2 * MARGIN)) <= 2 and abs(h - 2 * (height + 2 * MARGIN)) <= 2
44
+
45
+
46
+ # Decode a PNG in the page: the colours found in its outer band of `band` pixels, and how
47
+ # many pixels just inside that band differ from the page background.
48
+ _EDGES_JS = """async ([src, band]) => {
49
+ const img = new Image(); img.src = src; await img.decode();
50
+ const canvas = document.createElement('canvas');
51
+ canvas.width = img.naturalWidth; canvas.height = img.naturalHeight;
52
+ const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0);
53
+ const px = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
54
+ const at = (x, y) => Array.from(px.slice((y * canvas.width + x) * 4, (y * canvas.width + x) * 4 + 3)).join(',');
55
+ const probe = document.createElement('canvas').getContext('2d');
56
+ probe.fillStyle = getComputedStyle(document.body).backgroundColor; probe.fillRect(0, 0, 1, 1);
57
+ const background = Array.from(probe.getImageData(0, 0, 1, 1).data.slice(0, 3)).join(',');
58
+ const edge = new Set(); let inside = 0;
59
+ for (let y = 0; y < canvas.height; y++) for (let x = 0; x < canvas.width; x++) {
60
+ const inBand = x < band || y < band || x >= canvas.width - band || y >= canvas.height - band;
61
+ if (inBand) edge.add(at(x, y));
62
+ else if (at(x, y) !== background) inside++;
63
+ }
64
+ return {edge: Array.from(edge), background, inside};
65
+ }"""
66
+
67
+
68
+ def test_save_as_png_keeps_a_margin_of_page_background(viewer: Viewer, tmp_path: Path) -> None:
69
+ """Content never touches the image's edge: a MARGIN-wide band of page background frames it."""
70
+ page = viewer.open(_report(), name="Q1 Report")
71
+ with page.expect_download() as download:
72
+ page.get_by_role("button", name="Save as PNG").click()
73
+ saved = tmp_path / "q1.png"
74
+ download.value.save_as(saved)
75
+ src = "data:image/png;base64," + base64.b64encode(saved.read_bytes()).decode("ascii")
76
+ found = page.evaluate(_EDGES_JS, [src, 2 * MARGIN]) # the image is drawn at 2x
77
+ assert found["edge"] == [found["background"]]
78
+ assert found["inside"] > 0, "the report itself should be drawn inside the margin"
79
+
80
+
81
+ def test_there_is_no_print_button(viewer: Viewer) -> None:
82
+ """The browser's own print (Ctrl+P) does what the old "Print" button did."""
83
+ page = viewer.open(_report(), name="Q1 Report")
84
+ assert page.locator(".bf-export__btn").all_inner_texts() == ["Save as PNG"]
85
+
86
+
87
+ def test_the_menu_does_not_print(viewer: Viewer) -> None:
88
+ page = viewer.open(_report(), name="Q1 Report")
89
+ text = "\n".join(read_pdf(page.pdf(format="A4")).pages)
90
+ assert "Save as PNG" not in text and "Print" not in text
91
+ page.emulate_media(media="print")
92
+ page.evaluate("window.dispatchEvent(new Event('beforeprint'))")
93
+ assert page.locator(".bf-export").evaluate("e => getComputedStyle(e).display") == "none"
@@ -130,6 +130,9 @@ SCENARIOS: dict[str, Build] = {
130
130
  bf.Plot(_matplotlib_figure("line")), bf.Plot(_matplotlib_figure("bar"))
131
131
  ),
132
132
  "table-styler": lambda df: bf.Briefing(bf.Table(df("df_constant").style.highlight_max(), caption="Styled")),
133
+ "two-table-stylers": lambda df: bf.Briefing(
134
+ bf.Table(df("df_constant").style.highlight_max()), bf.Table(df("df_constant").style.highlight_max())
135
+ ),
133
136
  **{
134
137
  f"{kind}-{fixture}": _over_frame(make, fixture)
135
138
  for kind, make in FRAME_BLOCKS.items()
@@ -147,7 +150,7 @@ SCENARIOS: dict[str, Build] = {
147
150
  bf.Banner("## Left", image=RED_SVG, side="left", text_position=40, focus=(20, 80), alt="A red field"),
148
151
  ),
149
152
  "export-menu": lambda _: bf.Briefing(
150
- bf.Page(bf.Text("# One"), title="One"), bf.Page(bf.Text("# Two"), title="Two"), export=("png", "pdf")
153
+ bf.Page(bf.Text("# One"), title="One"), bf.Page(bf.Text("# Two"), title="Two"), export="png"
151
154
  ),
152
155
  "everything": lambda df: bf.Briefing(
153
156
  bf.Text("# Everything"),
@@ -208,8 +211,9 @@ def test_report_is_deterministic(
208
211
  rule: str, scenario: str, frames: Frames, monkeypatch: pytest.MonkeyPatch
209
212
  ) -> None:
210
213
  monkeypatch.setenv("SOURCE_DATE_EPOCH", "1700000000")
211
- report = SCENARIOS[scenario](frames)
212
- check_deterministic(lambda: bf.stringify(report, name=REPORT_NAME))
214
+ # Rebuild the report for each render: the promise is same input, same bytes. Rendering one
215
+ # object twice would miss randomness picked when a block or its data is created (#101).
216
+ check_deterministic(lambda: bf.stringify(SCENARIOS[scenario](frames), name=REPORT_NAME))
213
217
 
214
218
 
215
219
  def _all_block_types() -> set[type]:
@@ -92,3 +92,29 @@ def test_the_day_calendar_alone_does_not_warn(df_pipeline_log: t.Any) -> None:
92
92
  warnings.simplefilter("error")
93
93
  bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at")
94
94
  bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=("days",))
95
+
96
+
97
+ # ── Briefing(export="pdf"): the "Print" button ────────────────────────────────
98
+
99
+
100
+ @pytest.mark.parametrize("export", ["pdf", ("png", "pdf"), ["pdf", "png", "pdf"]])
101
+ def test_export_pdf_warns_once_and_adds_no_button(export: t.Any) -> None:
102
+ expected = r"export='pdf'.*deprecated.*Ctrl\+P.*bf\.save_pdf.*0\.4\.0"
103
+ with pytest.warns(DeprecationWarning, match=expected) as caught:
104
+ report = bf.Briefing(bf.Text("x"), export=export)
105
+ assert len(caught) == 1
106
+ assert caught[0].filename == __file__ # points at the caller's line (stacklevel=3)
107
+ assert "pdf" not in report.export
108
+
109
+
110
+ def test_export_png_alone_does_not_warn() -> None:
111
+ with warnings.catch_warnings():
112
+ warnings.simplefilter("error")
113
+ bf.Briefing(bf.Text("x"), export="png")
114
+
115
+
116
+ def test_export_pdf_is_rejected_from_0_4() -> None:
117
+ # Fails from 0.4 on until "pdf" leaves Briefing.DEPRECATED_EXPORTS and raises BriefingError.
118
+ version = tuple(int(part) for part in bf.__version__.split(".")[:2])
119
+ if version >= (0, 4):
120
+ assert "pdf" not in bf.Briefing.DEPRECATED_EXPORTS
@@ -36,8 +36,6 @@ BY_ID = {example.id: example for example in EXAMPLES}
36
36
 
37
37
  #: Rules every report fails today, as in tests/test_contract.py.
38
38
  KNOWN_FAILURES = {"generator_meta": "#23: no generator meta tag yet"}
39
- #: Examples whose output changes between runs today, by their ``:title:``.
40
- NOT_DETERMINISTIC = {"A styled Table": "#101: a pandas Styler gets a random uuid"}
41
39
 
42
40
  _reports: dict[str, str] = {}
43
41
 
@@ -67,16 +65,7 @@ def test_example_follows_rule(rule: str, example_id: str, tmp_path_factory: pyte
67
65
  RULES[rule](parse_report(_report(example_id, tmp_path_factory)))
68
66
 
69
67
 
70
- def _deterministic_cases() -> list[t.Any]:
71
- cases = []
72
- for ex in EXAMPLES:
73
- reason = NOT_DETERMINISTIC.get(ex.options.get("title", ""))
74
- marks = [pytest.mark.xfail(reason=reason, strict=True)] if reason else []
75
- cases.append(pytest.param(ex.id, marks=marks, id=ex.id))
76
- return cases
77
-
78
-
79
- @pytest.mark.parametrize("example_id", _deterministic_cases())
68
+ @pytest.mark.parametrize("example_id", [ex.id for ex in EXAMPLES])
80
69
  def test_example_is_deterministic(example_id: str, tmp_path_factory: pytest.TempPathFactory) -> None:
81
70
  again = gallery.run_example(BY_ID[example_id].code, tmp_path_factory.mktemp("again"), where=example_id)
82
71
  assert again.read_text(encoding="utf-8") == _report(example_id, tmp_path_factory)
@@ -0,0 +1,74 @@
1
+ """The opt-in export menu: bf.Briefing(..., export="png") (#49, #119)."""
2
+ from __future__ import annotations
3
+
4
+ import warnings
5
+
6
+ import pytest
7
+
8
+ import briefing as bf
9
+ from tests.html_helpers import attr, find_one, parse
10
+
11
+ EXPORT_JS_MARKER = "briefing export menu"
12
+
13
+
14
+ def test_menu_lists_the_requested_actions_in_the_header() -> None:
15
+ html = bf.stringify(bf.Briefing(bf.Text("x"), export=("png",)), name="Q1")
16
+ menu = find_one(parse(html), ".bf-report__header .bf-export")
17
+ buttons = menu.select("button.bf-export__btn")
18
+ assert [attr(b, "data-export") for b in buttons] == ["png"]
19
+ assert [b.get_text() for b in buttons] == ["Save as PNG"]
20
+ assert EXPORT_JS_MARKER in html
21
+
22
+
23
+ def test_a_single_string_works() -> None:
24
+ soup = parse(bf.stringify(bf.Briefing(bf.Text("x"), export="png"), name="Q1"))
25
+ assert [attr(b, "data-export") for b in soup.select(".bf-export button")] == ["png"]
26
+
27
+
28
+ def test_reports_without_export_contain_no_export_code() -> None:
29
+ for report in (bf.Briefing(bf.Text("x")), bf.Briefing(bf.Text("x"), export=())):
30
+ html = bf.stringify(report, name="Q1")
31
+ assert "bf-export" not in html and EXPORT_JS_MARKER not in html
32
+
33
+
34
+ def test_menu_gets_a_header_even_with_the_default_name() -> None:
35
+ soup = parse(bf.stringify(bf.Briefing(bf.Text("x"), export=("png",))))
36
+ assert find_one(soup, ".bf-report__header .bf-export")
37
+
38
+
39
+ @pytest.mark.parametrize("bad", [("png", "gif"), ("svg",), "print", 3])
40
+ def test_unknown_actions_raise(bad: object) -> None:
41
+ with pytest.raises(bf.BriefingError, match="export accepts 'png'"):
42
+ bf.Briefing(bf.Text("x"), export=bad) # type: ignore[arg-type]
43
+
44
+
45
+ def test_export_is_kept_when_a_briefing_is_rewrapped() -> None:
46
+ inner = bf.Briefing(bf.Text("x"), export=("png",))
47
+ assert bf.Briefing(inner).export == ("png",)
48
+ assert bf.Briefing.wrap(inner).export == ("png",)
49
+
50
+
51
+ # ── export="pdf": the "Print" button is gone (deprecated) ────────────────────
52
+
53
+
54
+ def test_pdf_adds_no_print_button() -> None:
55
+ with pytest.warns(DeprecationWarning):
56
+ report = bf.Briefing(bf.Text("x"), export=("png", "pdf"))
57
+ assert report.export == ("png",)
58
+ soup = parse(bf.stringify(report, name="Q1"))
59
+ assert [b.get_text() for b in soup.select(".bf-export button")] == ["Save as PNG"]
60
+
61
+
62
+ def test_pdf_alone_leaves_no_menu_and_no_export_code() -> None:
63
+ with pytest.warns(DeprecationWarning):
64
+ report = bf.Briefing(bf.Text("x"), export="pdf")
65
+ html = bf.stringify(report, name="Q1")
66
+ assert "bf-export" not in html and EXPORT_JS_MARKER not in html
67
+
68
+
69
+ def test_rewrapping_a_briefing_does_not_warn_twice() -> None:
70
+ with pytest.warns(DeprecationWarning):
71
+ inner = bf.Briefing(bf.Text("x"), export=("png", "pdf"))
72
+ with warnings.catch_warnings():
73
+ warnings.simplefilter("error")
74
+ assert bf.Briefing(inner).export == ("png",)
@@ -79,6 +79,18 @@ class TestRenderTable:
79
79
  html = render_table(Table(styler))
80
80
  assert "<table" in html
81
81
 
82
+ def test_equal_stylers_render_the_same_bytes(self, simple_df):
83
+ first, second = (render_table(Table(simple_df.style.highlight_max())) for _ in range(2))
84
+ assert first == second
85
+
86
+ def test_rendering_leaves_the_stylers_uuid_alone(self, simple_df):
87
+ styler = simple_df.style.highlight_max()
88
+ own_uuid = styler.uuid
89
+ html = render_table(Table(styler))
90
+ assert styler.uuid == own_uuid
91
+ assert own_uuid not in html
92
+ assert f"T_{own_uuid}" in styler.to_html()
93
+
82
94
  def test_rangeindex_hidden_by_default(self, simple_df):
83
95
  # Default RangeIndex should not appear as a column
84
96
  html = render_table(Table(simple_df))
@@ -1,55 +0,0 @@
1
- """The in-report export menu works in Chromium (#49)."""
2
- from __future__ import annotations
3
-
4
- from pathlib import Path
5
-
6
- import pandas as pd
7
- from playwright.sync_api import Page
8
-
9
- import briefing as bf
10
- from tests.image_helpers import png_size
11
- from tests.pdf_reader import read_pdf
12
- from tests.test_browser.conftest import Viewer
13
-
14
-
15
- def _report() -> bf.Briefing:
16
- return bf.Briefing(
17
- bf.Page(bf.Text("# Summary\n\nShort."), bf.BigNumber("Revenue", "$4.2M"), title="Summary"),
18
- bf.Page(bf.Text("# Detail"), bf.DataTable(pd.DataFrame({"n": range(30)})), title="Detail"),
19
- export=("png", "pdf"),
20
- )
21
-
22
-
23
- def _report_size(page: Page) -> tuple[float, float]:
24
- box = page.locator(".bf-report").bounding_box()
25
- assert box is not None
26
- return box["width"], box["height"]
27
-
28
-
29
- def test_save_as_png_downloads_the_current_page_at_2x(viewer: Viewer, tmp_path: Path) -> None:
30
- page = viewer.open(_report(), name="Q1 Report")
31
- page.get_by_role("tab", name="Detail").click()
32
- width, height = _report_size(page)
33
- with page.expect_download() as download:
34
- page.get_by_role("button", name="Save as PNG").click()
35
- saved = tmp_path / download.value.suggested_filename
36
- download.value.save_as(saved)
37
- assert saved.name == "q1_report_detail.png"
38
- w, h = png_size(saved)
39
- assert abs(w - 2 * width) <= 2 and abs(h - 2 * height) <= 2
40
-
41
-
42
- def test_print_opens_the_print_dialog(viewer: Viewer) -> None:
43
- page = viewer.open(_report(), name="Q1 Report")
44
- page.evaluate("() => { window.__printed = 0; window.print = () => { window.__printed += 1; }; }")
45
- page.get_by_role("button", name="Print").click()
46
- assert page.evaluate("() => window.__printed") == 1
47
-
48
-
49
- def test_the_menu_does_not_print(viewer: Viewer) -> None:
50
- page = viewer.open(_report(), name="Q1 Report")
51
- text = "\n".join(read_pdf(page.pdf(format="A4")).pages)
52
- assert "Save as PNG" not in text and "Print" not in text
53
- page.emulate_media(media="print")
54
- page.evaluate("window.dispatchEvent(new Event('beforeprint'))")
55
- assert page.locator(".bf-export").evaluate("e => getComputedStyle(e).display") == "none"
@@ -1,46 +0,0 @@
1
- """The opt-in export menu: bf.Briefing(..., export=("png", "pdf")) (#49)."""
2
- from __future__ import annotations
3
-
4
- import pytest
5
-
6
- import briefing as bf
7
- from tests.html_helpers import attr, find_one, parse
8
-
9
- EXPORT_JS_MARKER = "briefing export menu"
10
-
11
-
12
- def test_menu_lists_the_requested_actions_in_the_header() -> None:
13
- html = bf.stringify(bf.Briefing(bf.Text("x"), export=("png", "pdf")), name="Q1")
14
- menu = find_one(parse(html), ".bf-report__header .bf-export")
15
- buttons = menu.select("button.bf-export__btn")
16
- assert [attr(b, "data-export") for b in buttons] == ["png", "pdf"]
17
- assert [b.get_text() for b in buttons] == ["Save as PNG", "Print"]
18
- assert EXPORT_JS_MARKER in html
19
-
20
-
21
- def test_one_action_and_a_single_string() -> None:
22
- soup = parse(bf.stringify(bf.Briefing(bf.Text("x"), export="pdf"), name="Q1"))
23
- assert [attr(b, "data-export") for b in soup.select(".bf-export button")] == ["pdf"]
24
-
25
-
26
- def test_reports_without_export_contain_no_export_code() -> None:
27
- for report in (bf.Briefing(bf.Text("x")), bf.Briefing(bf.Text("x"), export=())):
28
- html = bf.stringify(report, name="Q1")
29
- assert "bf-export" not in html and EXPORT_JS_MARKER not in html
30
-
31
-
32
- def test_menu_gets_a_header_even_with_the_default_name() -> None:
33
- soup = parse(bf.stringify(bf.Briefing(bf.Text("x"), export=("png",))))
34
- assert find_one(soup, ".bf-report__header .bf-export")
35
-
36
-
37
- @pytest.mark.parametrize("bad", [("png", "gif"), ("svg",), 3])
38
- def test_unknown_actions_raise(bad: object) -> None:
39
- with pytest.raises(bf.BriefingError, match="png.*pdf"):
40
- bf.Briefing(bf.Text("x"), export=bad) # type: ignore[arg-type]
41
-
42
-
43
- def test_export_is_kept_when_a_briefing_is_rewrapped() -> None:
44
- inner = bf.Briefing(bf.Text("x"), export=("pdf",))
45
- assert bf.Briefing(inner).export == ("pdf",)
46
- assert bf.Briefing.wrap(inner).export == ("pdf",)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes