licos-dev-cli 0.4.3__tar.gz → 0.4.5__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,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: licos-dev-cli
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: LICOS Dev CLI - generate files and call model capabilities
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: click>=8.1
7
- Requires-Dist: licos-dev-sdk>=0.4.3
7
+ Requires-Dist: licos-dev-sdk>=0.4.5
@@ -4,11 +4,11 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "licos-dev-cli"
7
- version = "0.4.3"
7
+ version = "0.4.5"
8
8
  description = "LICOS Dev CLI - generate files and call model capabilities"
9
9
  requires-python = ">=3.10"
10
10
  dependencies = [
11
- "licos-dev-sdk>=0.4.3",
11
+ "licos-dev-sdk>=0.4.5",
12
12
  "click>=8.1",
13
13
  ]
14
14
 
@@ -70,6 +70,21 @@ def docx_structure(**arguments):
70
70
  result(read_docx_structure(**arguments))
71
71
 
72
72
 
73
+ @click.command("docx-inspect")
74
+ @click.option("--file", "source", required=True, type=click.Path(exists=True, dir_okay=False))
75
+ @click.option("--scope", type=click.Choice(["all", "fields", "images", "tables"]), default="all", show_default=True)
76
+ @click.option("--offset", type=click.IntRange(min=1), default=1, show_default=True)
77
+ @click.option("--limit", type=click.IntRange(1, 200), default=20, show_default=True)
78
+ @sdk_errors
79
+ def docx_inspect(**arguments):
80
+ """Inspect native TOC fields, embedded/linked images and tables, including headers/footers.
81
+
82
+ Reports field update settings, not rendered pages. Continue each scope with next_offset.
83
+ """
84
+ from licos_dev_sdk import inspect_docx
85
+ result(inspect_docx(**arguments))
86
+
87
+
73
88
  @click.command("docx-target")
74
89
  @click.option("--file", "source", required=True, type=click.Path(exists=True, dir_okay=False))
75
90
  @target_options
@@ -155,7 +170,7 @@ def docx_table_insert_rows(input_path, **arguments):
155
170
  @click.command("docx-verify")
156
171
  @click.option("--file", "source", required=True, type=click.Path(exists=True, dir_okay=False))
157
172
  @click.option("--original", type=click.Path(exists=True, dir_okay=False), help="Compare non-body package parts (headers, footers, styles, images) and section settings with the original.")
158
- @click.option("--input", "input_path", type=click.Path(exists=True, dir_okay=False), help="JSON array of target/text assertions and optional mode (equals, contains, absent).")
173
+ @click.option("--input", "input_path", type=click.Path(exists=True, dir_okay=False), help="JSON array: target, exactly one of text/text_file, optional mode. Relative text_file paths use the JSON file's directory.")
159
174
  @target_options
160
175
  @click.option("--text", default=None, help="Expected text at one target; use this or --text-file instead of --input.")
161
176
  @click.option("--text-file", type=click.Path(exists=True, dir_okay=False), help="UTF-8 expected text; preserves whitespace and line breaks.")
@@ -164,7 +179,7 @@ def docx_table_insert_rows(input_path, **arguments):
164
179
  def docx_verify(source, original, input_path, paragraph, block, table, row, column, text, text_file, mode):
165
180
  """Verify exact positions and optional original parts. No assertions means no content verification.
166
181
 
167
- Example: [{"target":{"table":1,"row":1,"column":1},"text":"Supplier: A"}]
182
+ Example: [{"target":{"block":3},"text_file":"expected.txt","mode":"equals"}]
168
183
 
169
184
  Exits 2 if an assertion or original comparison fails. Does not certify rendered page layout.
170
185
  """
@@ -175,8 +190,14 @@ def docx_verify(source, original, input_path, paragraph, block, table, row, colu
175
190
  raise click.UsageError("use --input or a single target with --text/--text-file, not both")
176
191
  expectations = json.loads(Path(input_path).read_text(encoding="utf-8")) if input_path else None
177
192
  if single:
178
- expectations = [{"target": position, "text": text_input(text, text_file, "text"), "mode": mode or "equals"}]
179
- report = verify_docx(source, original=original, expectations=expectations)
193
+ expectation = {"target": position, "mode": mode or "equals"}
194
+ if text is not None:
195
+ expectation["text"] = text
196
+ if text_file is not None:
197
+ expectation["text_file"] = text_file
198
+ expectations = [expectation]
199
+ report = verify_docx(source, original=original, expectations=expectations,
200
+ base_dir=Path(input_path).resolve().parent if input_path else Path.cwd())
180
201
  result(report)
181
202
  if not report["verified"]:
182
203
  raise click.exceptions.Exit(2)
@@ -184,4 +205,4 @@ def docx_verify(source, original, input_path, paragraph, block, table, row, colu
184
205
 
185
206
  DOCX_COMMANDS = [docx, docx_template, docx_edit, docx_read, docx_structure, docx_target,
186
207
  docx_replace, docx_delete_blocks, docx_edit_structure, docx_table_set,
187
- docx_table_insert_rows, docx_verify]
208
+ docx_table_insert_rows, docx_verify, docx_inspect]
@@ -24,6 +24,22 @@ def invoke(*arguments):
24
24
  return json.loads(result.output)
25
25
 
26
26
 
27
+ def test_inspect_and_file_assertions_use_cli_contract(source, tmp_path, monkeypatch):
28
+ report = invoke("docx-inspect", "--file", source)
29
+ assert report["table_count"] == 1 and report["image_count"] == 0
30
+ folder = tmp_path / "checks"
31
+ folder.mkdir()
32
+ expected = folder / "expected.txt"
33
+ expected.write_text("账号:123", encoding="utf-8")
34
+ checks = folder / "assertions.json"
35
+ checks.write_text(json.dumps([{"target": {"block": 1}, "text_file": "expected.txt"}]), encoding="utf-8")
36
+ monkeypatch.chdir(tmp_path)
37
+ assert invoke("docx-verify", "--file", source, "--input", checks)["verified"]
38
+ assert invoke("docx-verify", "--file", source, "--block", 1, "--text-file", "checks/expected.txt")["verified"]
39
+ invalid = CliRunner().invoke(cli, ["docx-verify", "--file", str(source), "--block", "1", "--text", "x", "--text-file", str(expected)])
40
+ assert invalid.exit_code != 0 and "exactly one" in invalid.output
41
+
42
+
27
43
  def test_focused_commands_complete_read_replace_delete_and_verify(source, tmp_path):
28
44
  read = invoke("docx-structure", "--file", source)
29
45
  output = tmp_path / "filled.docx"
@@ -75,7 +91,7 @@ def test_bad_revision_reports_original_error_and_leaves_output_absent(source, tm
75
91
  def test_command_help_is_focused_and_preserves_constraints():
76
92
  runner = CliRunner()
77
93
  for name in ("docx-structure", "docx-target", "docx-replace", "docx-delete-blocks", "docx-edit-structure",
78
- "docx-table-set", "docx-table-insert-rows", "docx-verify"):
94
+ "docx-table-set", "docx-table-insert-rows", "docx-verify", "docx-inspect"):
79
95
  help_text = runner.invoke(cli, [name, "--help"])
80
96
  assert help_text.exit_code == 0
81
97
  assert len(help_text.output.encode("utf-8")) < 5000
File without changes