robotframework-doctestlibrary 0.32.0.dev3__tar.gz → 0.35.0__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 (68) hide show
  1. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/.gitignore +13 -0
  2. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/Ai/__init__.py +5 -5
  3. robotframework_doctestlibrary-0.35.0/DocTest/CapabilityCheck.py +294 -0
  4. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/DocumentRepresentation.py +346 -175
  5. robotframework_doctestlibrary-0.35.0/DocTest/Downloader.py +207 -0
  6. robotframework_doctestlibrary-0.35.0/DocTest/IgnoreAreaManager.py +83 -0
  7. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/Ocr.py +102 -49
  8. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/PdfStructureComparator.py +3 -229
  9. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/PdfStructureModels.py +0 -233
  10. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/PdfTest.py +353 -318
  11. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/PrintJobTests.py +57 -48
  12. robotframework_doctestlibrary-0.35.0/DocTest/ReferencePromotion.py +29 -0
  13. robotframework_doctestlibrary-0.35.0/DocTest/ResultWriter.py +209 -0
  14. robotframework_doctestlibrary-0.35.0/DocTest/TextNormalization.py +54 -0
  15. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/VisualTest.py +626 -165
  16. robotframework_doctestlibrary-0.35.0/DocTest/WebCapture.py +286 -0
  17. robotframework_doctestlibrary-0.35.0/DocTest/WebVisualTest.py +415 -0
  18. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/__init__.py +23 -0
  19. robotframework_doctestlibrary-0.35.0/DocTest/_llm_flags.py +38 -0
  20. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/llm/client.py +52 -13
  21. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/llm/config.py +18 -12
  22. robotframework_doctestlibrary-0.32.0.dev3/README.md → robotframework_doctestlibrary-0.35.0/PKG-INFO +210 -3
  23. robotframework_doctestlibrary-0.32.0.dev3/PKG-INFO → robotframework_doctestlibrary-0.35.0/README.md +142 -39
  24. robotframework_doctestlibrary-0.35.0/doctest_dashboard/__init__.py +12 -0
  25. robotframework_doctestlibrary-0.35.0/doctest_dashboard/cli.py +160 -0
  26. robotframework_doctestlibrary-0.35.0/doctest_dashboard/config.py +51 -0
  27. robotframework_doctestlibrary-0.35.0/doctest_dashboard/db.py +392 -0
  28. robotframework_doctestlibrary-0.35.0/doctest_dashboard/engine.py +272 -0
  29. robotframework_doctestlibrary-0.35.0/doctest_dashboard/ingest.py +277 -0
  30. robotframework_doctestlibrary-0.35.0/doctest_dashboard/masks.py +105 -0
  31. robotframework_doctestlibrary-0.35.0/doctest_dashboard/models/__init__.py +0 -0
  32. robotframework_doctestlibrary-0.35.0/doctest_dashboard/models/sidecar.py +84 -0
  33. robotframework_doctestlibrary-0.35.0/doctest_dashboard/review.py +209 -0
  34. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/__init__.py +0 -0
  35. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/app.py +55 -0
  36. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/features.py +11 -0
  37. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/__init__.py +0 -0
  38. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/assets.py +24 -0
  39. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/browse.py +58 -0
  40. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/engine.py +194 -0
  41. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/masks.py +50 -0
  42. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/review.py +79 -0
  43. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/runs.py +104 -0
  44. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/routers/uploads.py +106 -0
  45. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/schemas.py +64 -0
  46. robotframework_doctestlibrary-0.35.0/doctest_dashboard/server/state.py +31 -0
  47. robotframework_doctestlibrary-0.35.0/doctest_dashboard/static/assets/MaskEditor-CG1klHzJ.js +19 -0
  48. robotframework_doctestlibrary-0.35.0/doctest_dashboard/static/assets/index-CHk_W3no.js +8 -0
  49. robotframework_doctestlibrary-0.35.0/doctest_dashboard/static/assets/index-gNWeXwTa.css +1 -0
  50. robotframework_doctestlibrary-0.35.0/doctest_dashboard/static/index.html +21 -0
  51. robotframework_doctestlibrary-0.35.0/doctest_dashboard/storage.py +50 -0
  52. robotframework_doctestlibrary-0.35.0/pyproject.toml +176 -0
  53. robotframework_doctestlibrary-0.32.0.dev3/DocTest/Downloader.py +0 -47
  54. robotframework_doctestlibrary-0.32.0.dev3/DocTest/HeaderFooterDetector.py +0 -230
  55. robotframework_doctestlibrary-0.32.0.dev3/DocTest/IgnoreAreaManager.py +0 -129
  56. robotframework_doctestlibrary-0.32.0.dev3/DocTest/StructureReportBuilder.py +0 -558
  57. robotframework_doctestlibrary-0.32.0.dev3/DocTest/TextNormalization.py +0 -119
  58. robotframework_doctestlibrary-0.32.0.dev3/pyproject.toml +0 -61
  59. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/Ai/prompts.py +0 -0
  60. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/Ai/renderers.py +0 -0
  61. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/Ai/responses.py +0 -0
  62. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/PrintJob.py +0 -0
  63. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/config.py +0 -0
  64. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/llm/__init__.py +0 -0
  65. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/llm/exceptions.py +0 -0
  66. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/llm/prompts.py +0 -0
  67. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/DocTest/llm/types.py +0 -0
  68. {robotframework_doctestlibrary-0.32.0.dev3 → robotframework_doctestlibrary-0.35.0}/LICENSE +0 -0
@@ -80,3 +80,16 @@ RELEASE*.md
80
80
 
81
81
  # Models and datasets
82
82
  *.pb
83
+
84
+ # Local configuration and research files
85
+ .claude-flow/
86
+ .claude/
87
+ .*cache/
88
+ research/
89
+
90
+ # Frontend build artifacts (dashboard web UI)
91
+ frontend/node_modules/
92
+ doctest_dashboard/static/
93
+
94
+ # Dashboard runtime data
95
+ .doctest_dashboard/
@@ -1,10 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- import re
4
3
  import textwrap
5
- from typing import Dict, Iterable, List, Optional, Sequence
4
+ from typing import Dict, Iterable, List, Optional
6
5
 
7
6
  import cv2
7
+ from robot.api import logger as robot_logger
8
8
  from robot.api.deco import keyword, library
9
9
 
10
10
  from DocTest.DocumentRepresentation import DocumentRepresentation
@@ -209,7 +209,7 @@ class Ai:
209
209
  doc_representation = DocumentRepresentation(doc_path, dpi=self.dpi)
210
210
  page_list = list(doc_representation.pages)
211
211
 
212
- for idx, (page_meta, page_obj) in enumerate(zip(pages, page_list), 1):
212
+ for idx, (page_meta, page_obj) in enumerate(zip(pages, page_list, strict=False), 1):
213
213
  if target_page != "all" and int(target_page) != idx:
214
214
  continue
215
215
  try:
@@ -379,10 +379,10 @@ class Ai:
379
379
  )
380
380
  if found_text:
381
381
  return
382
- print("LLM approved but keyword could not verify the expected content in document text; treating as failure.")
382
+ robot_logger.info("LLM approved but keyword could not verify the expected content in document text; treating as failure.")
383
383
  raise AssertionError(f"Expected object '{expected}' not found in '{document}'.")
384
384
  if decision.reason:
385
- print(f"LLM reason: {decision.reason}")
385
+ robot_logger.info(f"LLM reason: {decision.reason}")
386
386
  raise AssertionError(f"Expected object '{expected}' not found in '{document}'.")
387
387
 
388
388
  @keyword(name="Get Item Count From Image", tags=("ai",))
@@ -0,0 +1,294 @@
1
+ """Preflight capability checker for DocTest library.
2
+
3
+ Detects whether optional external binaries (Tesseract, Ghostscript, GhostPCL,
4
+ ImageMagick) and Python packages (PyMuPDF, pyzbar, openai) are available before
5
+ tests run. This avoids cryptic runtime errors when a dependency is missing.
6
+
7
+ Usage from Robot Framework::
8
+
9
+ Library DocTest.CapabilityCheck
10
+
11
+ *** Test Cases ***
12
+ Verify Environment
13
+ ${caps}= Check DocTest Environment
14
+ Log ${caps}
15
+
16
+ Usage from Python::
17
+
18
+ from DocTest.CapabilityCheck import check_all_capabilities, format_capability_report
19
+ caps = check_all_capabilities()
20
+ print(format_capability_report(caps))
21
+ """
22
+
23
+ import importlib
24
+ import logging
25
+ import os
26
+ import shutil
27
+ import subprocess
28
+ from typing import Dict, List, Optional
29
+
30
+ from robot.api.deco import keyword, library
31
+
32
+ logger = logging.getLogger(__name__)
33
+
34
+ # ---------------------------------------------------------------------------
35
+ # Capability registry
36
+ # ---------------------------------------------------------------------------
37
+
38
+ CAPABILITY_REGISTRY: Dict[str, Dict[str, str]] = {
39
+ "tesseract": {
40
+ "binary": "tesseract",
41
+ "feature": "OCR text extraction",
42
+ "install_hint": "apt install tesseract-ocr (Linux) / brew install tesseract (macOS)",
43
+ },
44
+ "ghostscript": {
45
+ "binary": "gs",
46
+ "fallback_binaries": "gswin64c,gswin32c,ghostscript",
47
+ "feature": "PDF/PostScript rendering",
48
+ "install_hint": "apt install ghostscript (Linux) / brew install ghostscript (macOS)",
49
+ },
50
+ "ghostpcl": {
51
+ "binary": "pcl6",
52
+ "fallback_binaries": "gpcl6win64,gpcl6win32,gpcl6",
53
+ "feature": "PCL document rendering",
54
+ "install_hint": (
55
+ "Install GhostPCL from https://ghostscript.com/releases/gpcldnld.html"
56
+ ),
57
+ },
58
+ "imagemagick": {
59
+ "binary": "magick",
60
+ "fallback_binaries": "convert",
61
+ "feature": "Image format conversion",
62
+ "install_hint": (
63
+ "apt install imagemagick (Linux) / brew install imagemagick (macOS)"
64
+ ),
65
+ },
66
+ }
67
+
68
+ PYTHON_PACKAGE_REGISTRY: Dict[str, Dict[str, str]] = {
69
+ "pymupdf": {
70
+ "import_name": "pymupdf",
71
+ "feature": "PDF rendering and text extraction",
72
+ "install_hint": "pip install PyMuPDF",
73
+ },
74
+ "pyzbar": {
75
+ "import_name": "pyzbar",
76
+ "feature": "Barcode detection and decoding",
77
+ "install_hint": "pip install pyzbar",
78
+ },
79
+ "openai": {
80
+ "import_name": "openai",
81
+ "feature": "LLM-assisted image comparison",
82
+ "install_hint": 'pip install "robotframework-doctestlibrary[ai]"',
83
+ },
84
+ }
85
+
86
+ # ---------------------------------------------------------------------------
87
+ # Helper functions
88
+ # ---------------------------------------------------------------------------
89
+
90
+
91
+ def check_binary(name: str) -> Optional[str]:
92
+ """Return the absolute path of *name* if it is on ``$PATH``, else ``None``.
93
+
94
+ Uses :func:`shutil.which` internally.
95
+ """
96
+ try:
97
+ return shutil.which(name)
98
+ except Exception:
99
+ return None
100
+
101
+
102
+ def _windows_system_dirs() -> List[str]:
103
+ """Normalised Windows system directories (empty on other platforms)."""
104
+ if os.name != "nt":
105
+ return []
106
+ root = os.environ.get("SystemRoot") or os.environ.get("WINDIR") or r"C:\Windows"
107
+ return [os.path.normcase(os.path.join(root, sub)) for sub in ("System32", "SysWOW64")]
108
+
109
+
110
+ def _is_os_utility(path: str) -> bool:
111
+ """True when *path* lives in the Windows system directory.
112
+
113
+ Fallback names such as ``convert`` collide with Windows' own
114
+ ``System32/convert.exe`` (a disk-conversion tool), which must not be
115
+ reported as ImageMagick.
116
+ """
117
+ directory = os.path.normcase(os.path.dirname(os.path.abspath(path)))
118
+ return directory in _windows_system_dirs()
119
+
120
+
121
+ def check_python_package(name: str) -> bool:
122
+ """Return ``True`` if the Python package *name* can be imported."""
123
+ try:
124
+ importlib.import_module(name)
125
+ return True
126
+ except Exception:
127
+ return False
128
+
129
+
130
+ def _get_version(binary_path: str) -> Optional[str]:
131
+ """Try to obtain a version string from *binary_path*.
132
+
133
+ Attempts ``--version`` first, then ``-version``. Returns ``None`` on
134
+ any failure so the caller can proceed without version info.
135
+ """
136
+ for flag in ("--version", "-version"):
137
+ try:
138
+ # errors="replace": tools may print in a localized code page,
139
+ # which fails to decode under Python 3.15's default UTF-8 mode
140
+ result = subprocess.run(
141
+ [binary_path, flag],
142
+ capture_output=True,
143
+ text=True,
144
+ errors="replace",
145
+ timeout=5,
146
+ )
147
+ output = (result.stdout or result.stderr or "").strip()
148
+ if output:
149
+ # Return the first non-empty line.
150
+ return output.splitlines()[0]
151
+ except Exception:
152
+ continue
153
+ return None
154
+
155
+
156
+ def check_all_capabilities() -> Dict[str, Dict]:
157
+ """Check every registered capability and return a structured report.
158
+
159
+ Returns a ``dict`` keyed by capability name. Each value is a ``dict``
160
+ containing at least ``"available"`` (bool) and ``"feature"`` (str).
161
+ """
162
+ results: Dict[str, Dict] = {}
163
+
164
+ # -- Binary capabilities --
165
+ for name, info in CAPABILITY_REGISTRY.items():
166
+ entry: Dict = {
167
+ "available": False,
168
+ "feature": info["feature"],
169
+ "path": None,
170
+ }
171
+
172
+ # Try the primary binary first, then any fallbacks.
173
+ binaries_to_try: List[str] = [info["binary"]]
174
+ fallback_str = info.get("fallback_binaries", "")
175
+ if fallback_str:
176
+ binaries_to_try.extend(
177
+ b.strip() for b in fallback_str.split(",") if b.strip()
178
+ )
179
+
180
+ for idx, binary_name in enumerate(binaries_to_try):
181
+ path = check_binary(binary_name)
182
+ if path is not None and idx > 0 and _is_os_utility(path):
183
+ continue
184
+ if path is not None:
185
+ entry["available"] = True
186
+ entry["path"] = path
187
+ version = _get_version(path)
188
+ if version:
189
+ entry["version"] = version
190
+ if idx > 0:
191
+ entry["note"] = f"Using fallback '{binary_name}' command"
192
+ break
193
+
194
+ if not entry["available"]:
195
+ entry["install_hint"] = info["install_hint"]
196
+
197
+ results[name] = entry
198
+
199
+ # -- Python package capabilities --
200
+ for name, info in PYTHON_PACKAGE_REGISTRY.items():
201
+ import_name = info["import_name"]
202
+ available = check_python_package(import_name)
203
+ entry = {
204
+ "available": available,
205
+ "feature": info["feature"],
206
+ "package": import_name,
207
+ }
208
+ if not available:
209
+ entry["install_hint"] = info["install_hint"]
210
+ results[name] = entry
211
+
212
+ return results
213
+
214
+
215
+ def format_capability_report(capabilities: Dict[str, Dict]) -> str:
216
+ """Format *capabilities* into a human-readable report string."""
217
+ lines: List[str] = []
218
+ lines.append("DocTest Environment Capability Report")
219
+ lines.append("=" * 42)
220
+
221
+ available_items: List[str] = []
222
+ missing_items: List[str] = []
223
+
224
+ for name, info in capabilities.items():
225
+ status = "OK" if info["available"] else "MISSING"
226
+ feature = info.get("feature", "")
227
+ line = f" [{status:>7}] {name:<15} - {feature}"
228
+ if info["available"]:
229
+ path = info.get("path")
230
+ version = info.get("version")
231
+ note = info.get("note")
232
+ details: List[str] = []
233
+ if path:
234
+ details.append(f"path: {path}")
235
+ if version:
236
+ details.append(f"version: {version}")
237
+ if note:
238
+ details.append(note)
239
+ if details:
240
+ line += f" ({', '.join(details)})"
241
+ available_items.append(line)
242
+ else:
243
+ hint = info.get("install_hint", "")
244
+ if hint:
245
+ line += f"\n{'':>28}Install: {hint}"
246
+ missing_items.append(line)
247
+
248
+ if available_items:
249
+ lines.append("")
250
+ lines.append("Available:")
251
+ lines.extend(available_items)
252
+
253
+ if missing_items:
254
+ lines.append("")
255
+ lines.append("Missing:")
256
+ lines.extend(missing_items)
257
+
258
+ lines.append("")
259
+ total = len(capabilities)
260
+ ok_count = sum(1 for v in capabilities.values() if v["available"])
261
+ lines.append(f"Summary: {ok_count}/{total} capabilities available")
262
+ return "\n".join(lines)
263
+
264
+
265
+ # ---------------------------------------------------------------------------
266
+ # Robot Framework library
267
+ # ---------------------------------------------------------------------------
268
+
269
+
270
+ @library(scope="GLOBAL")
271
+ class CapabilityCheck:
272
+ """Preflight capability checker for the DocTest library.
273
+
274
+ Provides a keyword to detect whether optional external binaries and
275
+ Python packages required by various DocTest features are installed.
276
+ """
277
+
278
+ ROBOT_LIBRARY_VERSION = "1.0"
279
+
280
+ @keyword("Check DocTest Environment")
281
+ def check_doctest_environment(self) -> Dict[str, Dict]:
282
+ """Check and report available capabilities for DocTest library.
283
+
284
+ Returns a structured ``dict`` keyed by capability name and logs a
285
+ human-readable report.
286
+
287
+ Example:
288
+ | ${caps}= | Check DocTest Environment |
289
+ | Log | ${caps} |
290
+ """
291
+ capabilities = check_all_capabilities()
292
+ report = format_capability_report(capabilities)
293
+ logger.info(report)
294
+ return capabilities