struct2ui 0.5.0__tar.gz → 0.5.1__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.
- {struct2ui-0.5.0/src/struct2ui.egg-info → struct2ui-0.5.1}/PKG-INFO +3 -3
- {struct2ui-0.5.0 → struct2ui-0.5.1}/README.md +2 -2
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/__init__.py +1 -1
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/editor.py +5 -3
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/schema.py +26 -19
- {struct2ui-0.5.0 → struct2ui-0.5.1/src/struct2ui.egg-info}/PKG-INFO +3 -3
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_c_parser.py +1 -1
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_json_format.py +1 -1
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_save.py +258 -258
- {struct2ui-0.5.0 → struct2ui-0.5.1}/LICENSE +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/pyproject.toml +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/setup.cfg +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/exporters/__init__.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/exporters/bin_emitter.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/exporters/bin_reader.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/exporters/c_emitter.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/exporters/c_parser.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/exporters/elf_verifier.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/exporters/json_format.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/c2j.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/elf.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/export_notes_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/flowchart_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/refresh_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/report_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/save_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/save_as_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/settings_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/icons/widgets_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/ui/__init__.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/ui/renderers.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/ui/tables.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui/ui/widgets.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui.egg-info/SOURCES.txt +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui.egg-info/dependency_links.txt +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui.egg-info/requires.txt +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/src/struct2ui.egg-info/top_level.txt +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_bin_emitter.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_bin_reader.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_c_emitter.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_choices.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_container_verify.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_editor.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_elf_verifier.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_float_precision.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_int_checkbox.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_load_report.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_macro_bounds.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_union.py +0 -0
- {struct2ui-0.5.0 → struct2ui-0.5.1}/tests/test_value_readback.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: struct2ui
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin
|
|
5
5
|
Author-email: Jay <huoyj0108@163.com>
|
|
6
6
|
License: MIT License
|
|
@@ -277,7 +277,7 @@ tuning name) whose value is the group body:
|
|
|
277
277
|
```jsonc
|
|
278
278
|
{
|
|
279
279
|
"Speech Tuning": {
|
|
280
|
-
"flow": ["RX NS", "RX DRC", "RX EQ"], // stage order,
|
|
280
|
+
"flow": ["RX NS", "RX DRC", "RX EQ"], // stage order, optional
|
|
281
281
|
"container": "SpeechConfig", // optional, enables layout check
|
|
282
282
|
|
|
283
283
|
"RX NS": { "type": "SpeechNs2FloatConfig", "items": { /* values */ } },
|
|
@@ -291,7 +291,7 @@ tuning name) whose value is the group body:
|
|
|
291
291
|
|
|
292
292
|
| Key | Required | Notes |
|
|
293
293
|
| --- | --- | --- |
|
|
294
|
-
| `flow` |
|
|
294
|
+
| `flow` | no | Ordered list of stage names. The flow buttons and the export order follow it. **Omit it and the stages run in the order they appear in the JSON.** When present, every listed name must have a stage block; defined stages missing from `flow` are a warning. |
|
|
295
295
|
| `container` | no | Name of the SDK struct that holds all modules (see [Container layout check](#container-layout-check)). Omit to disable that check. |
|
|
296
296
|
| *stage name* | — | Any other key is a **stage block**; its name is the label shown on the flow button. |
|
|
297
297
|
|
|
@@ -224,7 +224,7 @@ tuning name) whose value is the group body:
|
|
|
224
224
|
```jsonc
|
|
225
225
|
{
|
|
226
226
|
"Speech Tuning": {
|
|
227
|
-
"flow": ["RX NS", "RX DRC", "RX EQ"], // stage order,
|
|
227
|
+
"flow": ["RX NS", "RX DRC", "RX EQ"], // stage order, optional
|
|
228
228
|
"container": "SpeechConfig", // optional, enables layout check
|
|
229
229
|
|
|
230
230
|
"RX NS": { "type": "SpeechNs2FloatConfig", "items": { /* values */ } },
|
|
@@ -238,7 +238,7 @@ tuning name) whose value is the group body:
|
|
|
238
238
|
|
|
239
239
|
| Key | Required | Notes |
|
|
240
240
|
| --- | --- | --- |
|
|
241
|
-
| `flow` |
|
|
241
|
+
| `flow` | no | Ordered list of stage names. The flow buttons and the export order follow it. **Omit it and the stages run in the order they appear in the JSON.** When present, every listed name must have a stage block; defined stages missing from `flow` are a warning. |
|
|
242
242
|
| `container` | no | Name of the SDK struct that holds all modules (see [Container layout check](#container-layout-check)). Omit to disable that check. |
|
|
243
243
|
| *stage name* | — | Any other key is a **stage block**; its name is the label shown on the flow button. |
|
|
244
244
|
|
|
@@ -18,7 +18,7 @@ from Qt import QtCore, QtGui, QtWidgets
|
|
|
18
18
|
|
|
19
19
|
from .schema import (
|
|
20
20
|
SchemaRegistry, FlowValidator, merge_instance,
|
|
21
|
-
StructField, ArrayField,
|
|
21
|
+
StructField, ArrayField, GROUP_RESERVED,
|
|
22
22
|
)
|
|
23
23
|
from .ui import pick_renderer, collect_view_values
|
|
24
24
|
from .exporters import (
|
|
@@ -375,11 +375,13 @@ class _LoadWorker(QtCore.QRunnable):
|
|
|
375
375
|
group = data.get(group_key, {})
|
|
376
376
|
if not isinstance(group, dict):
|
|
377
377
|
return '', [], {}, {}
|
|
378
|
-
flow = list(group.get('flow', []) or [])
|
|
379
378
|
section_specs = {
|
|
380
379
|
label: spec for label, spec in group.items()
|
|
381
|
-
if label
|
|
380
|
+
if label not in GROUP_RESERVED and isinstance(spec, dict)
|
|
382
381
|
}
|
|
382
|
+
# 'flow' is optional: when absent, stages run in JSON order
|
|
383
|
+
# (json.load preserves insertion order).
|
|
384
|
+
flow = list(group.get('flow', []) or []) or list(section_specs)
|
|
383
385
|
return group_key, flow, section_specs, data
|
|
384
386
|
|
|
385
387
|
def _index_stage_errors(self, registry, group_key, flow):
|
|
@@ -1435,21 +1435,37 @@ class FlowValidator:
|
|
|
1435
1435
|
# otherwise fire for every stage and add noise on top of the real
|
|
1436
1436
|
# error).
|
|
1437
1437
|
flow_val = group.get('flow')
|
|
1438
|
+
|
|
1439
|
+
# A near-miss key (e.g. 'f1low', 'Flow', 'flwo') is only meaningful
|
|
1440
|
+
# when 'flow' itself is absent; report it once and exclude it from
|
|
1441
|
+
# the stage candidates below.
|
|
1442
|
+
misspelled_flow = (self._find_flow_lookalike(group)
|
|
1443
|
+
if flow_val is None else None)
|
|
1444
|
+
|
|
1445
|
+
# Stage candidates: every key that is not a group-reserved key,
|
|
1446
|
+
# in JSON insertion order (json.load preserves it). This order is
|
|
1447
|
+
# also the implicit flow when no 'flow' list is given.
|
|
1448
|
+
stage_keys = [k for k in group.keys()
|
|
1449
|
+
if k not in GROUP_RESERVED and k != misspelled_flow]
|
|
1450
|
+
|
|
1451
|
+
# A2: flow shape. flow_present marks whether we have a trustworthy
|
|
1452
|
+
# flow list to compare stages against; if not, suppress the
|
|
1453
|
+
# "defined but not listed in flow" warning entirely.
|
|
1438
1454
|
flow_list: List[str]
|
|
1439
1455
|
flow_present: bool
|
|
1440
1456
|
if flow_val is None:
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if misspelled is not None:
|
|
1457
|
+
if misspelled_flow is not None:
|
|
1458
|
+
# A typo like 'Flow' must not silently degrade to
|
|
1459
|
+
# insertion order - flag it so the user notices.
|
|
1445
1460
|
self.report.error(
|
|
1446
|
-
self.flow_file, f'{group_key} -> {
|
|
1447
|
-
f"unknown key '{
|
|
1461
|
+
self.flow_file, f'{group_key} -> {misspelled_flow}',
|
|
1462
|
+
f"unknown key '{misspelled_flow}'", "Did you mean 'flow'?")
|
|
1463
|
+
flow_list = []
|
|
1464
|
+
flow_present = False
|
|
1448
1465
|
else:
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
flow_present = False
|
|
1466
|
+
# 'flow' is optional: fall back to JSON order.
|
|
1467
|
+
flow_list = list(stage_keys)
|
|
1468
|
+
flow_present = True
|
|
1453
1469
|
elif not isinstance(flow_val, list):
|
|
1454
1470
|
self.report.error(
|
|
1455
1471
|
self.flow_file, f'{group_key} -> flow',
|
|
@@ -1460,15 +1476,6 @@ class FlowValidator:
|
|
|
1460
1476
|
flow_list = [s for s in flow_val if isinstance(s, str)]
|
|
1461
1477
|
flow_present = True
|
|
1462
1478
|
|
|
1463
|
-
# Stage candidates: every key that is not a group-reserved key,
|
|
1464
|
-
# excluding any 'flow' look-alike already reported above (so it
|
|
1465
|
-
# does not get re-flagged as a malformed stage).
|
|
1466
|
-
misspelled_flow = None
|
|
1467
|
-
if not flow_present and flow_val is None:
|
|
1468
|
-
misspelled_flow = self._find_flow_lookalike(group)
|
|
1469
|
-
stage_keys = [k for k in group.keys()
|
|
1470
|
-
if k not in GROUP_RESERVED and k != misspelled_flow]
|
|
1471
|
-
|
|
1472
1479
|
# L5 - part 1: every stage in flow must be defined.
|
|
1473
1480
|
for stage_name in flow_list:
|
|
1474
1481
|
if stage_name not in stage_keys:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: struct2ui
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin
|
|
5
5
|
Author-email: Jay <huoyj0108@163.com>
|
|
6
6
|
License: MIT License
|
|
@@ -277,7 +277,7 @@ tuning name) whose value is the group body:
|
|
|
277
277
|
```jsonc
|
|
278
278
|
{
|
|
279
279
|
"Speech Tuning": {
|
|
280
|
-
"flow": ["RX NS", "RX DRC", "RX EQ"], // stage order,
|
|
280
|
+
"flow": ["RX NS", "RX DRC", "RX EQ"], // stage order, optional
|
|
281
281
|
"container": "SpeechConfig", // optional, enables layout check
|
|
282
282
|
|
|
283
283
|
"RX NS": { "type": "SpeechNs2FloatConfig", "items": { /* values */ } },
|
|
@@ -291,7 +291,7 @@ tuning name) whose value is the group body:
|
|
|
291
291
|
|
|
292
292
|
| Key | Required | Notes |
|
|
293
293
|
| --- | --- | --- |
|
|
294
|
-
| `flow` |
|
|
294
|
+
| `flow` | no | Ordered list of stage names. The flow buttons and the export order follow it. **Omit it and the stages run in the order they appear in the JSON.** When present, every listed name must have a stage block; defined stages missing from `flow` are a warning. |
|
|
295
295
|
| `container` | no | Name of the SDK struct that holds all modules (see [Container layout check](#container-layout-check)). Omit to disable that check. |
|
|
296
296
|
| *stage name* | — | Any other key is a **stage block**; its name is the label shown on the flow button. |
|
|
297
297
|
|
|
@@ -199,7 +199,7 @@ def test_roundtrip_real_c_files():
|
|
|
199
199
|
"""Parsing the project's own cfg_t/*.c and loading the result must not
|
|
200
200
|
produce schema errors for the structs they define."""
|
|
201
201
|
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
202
|
-
c_path = os.path.join(base, 'examples', '
|
|
202
|
+
c_path = os.path.join(base, 'examples', 'test', 'cfg_t', 'a_cfg_t.c')
|
|
203
203
|
with open(c_path, encoding='utf-8') as f:
|
|
204
204
|
out = build_schema_dict(parse_c_source(f.read()))
|
|
205
205
|
assert 'a_cfg_t' in out
|
|
@@ -33,7 +33,7 @@ def test_empty_containers():
|
|
|
33
33
|
def test_roundtrip_real_flow():
|
|
34
34
|
import os
|
|
35
35
|
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
36
|
-
data = json.load(open(os.path.join(base, 'examples', '
|
|
36
|
+
data = json.load(open(os.path.join(base, 'examples', 'test', 'abc.json'), encoding='utf-8'))
|
|
37
37
|
assert json.loads(dumps_json(data)) == data
|
|
38
38
|
|
|
39
39
|
|
|
@@ -1,258 +1,258 @@
|
|
|
1
|
-
"""Tests for the UI -> JSON save feature.
|
|
2
|
-
|
|
3
|
-
Save reads the live editors of the active section back into the raw flow
|
|
4
|
-
document and writes it out, patching only edited 'items' while leaving the
|
|
5
|
-
rest of the document (group structure, render hints) intact.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import json
|
|
9
|
-
import os
|
|
10
|
-
import shutil
|
|
11
|
-
|
|
12
|
-
import pytest
|
|
13
|
-
|
|
14
|
-
from Qt import QtWidgets
|
|
15
|
-
|
|
16
|
-
from struct2ui.editor import _norm_path
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@pytest.fixture
|
|
20
|
-
def flow_copy(tmp_path):
|
|
21
|
-
"""Copy the real abc.json into a temp file so saves never touch the repo."""
|
|
22
|
-
import os
|
|
23
|
-
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
24
|
-
src = os.path.join(base, 'examples', '
|
|
25
|
-
dst = tmp_path / 'flow.json'
|
|
26
|
-
shutil.copy(src, dst)
|
|
27
|
-
return str(dst)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@pytest.fixture(autouse=True)
|
|
31
|
-
def silence_dialogs(monkeypatch):
|
|
32
|
-
monkeypatch.setattr(QtWidgets.QMessageBox, 'information',
|
|
33
|
-
lambda *a, **k: None)
|
|
34
|
-
monkeypatch.setattr(QtWidgets.QMessageBox, 'critical',
|
|
35
|
-
lambda *a, **k: None)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def _spin(widget, value):
|
|
39
|
-
for w in widget.findChildren(QtWidgets.QSpinBox):
|
|
40
|
-
if w.value() == value:
|
|
41
|
-
return w
|
|
42
|
-
return None
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def test_save_preserves_structure(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
46
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
47
|
-
w._on_button_clicked('A')
|
|
48
|
-
w._on_save_clicked()
|
|
49
|
-
|
|
50
|
-
with open(flow_copy, encoding='utf-8') as f:
|
|
51
|
-
data = json.load(f)
|
|
52
|
-
group = data['ABC Test']
|
|
53
|
-
assert group['flow'] == ['A', 'B', 'C', 'D', 'E']
|
|
54
|
-
assert group['A']['type'] == 'a_cfg_t'
|
|
55
|
-
assert group['A']['items']['level'] == 50
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def test_edit_then_save_persists(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
59
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
60
|
-
w._on_button_clicked('A')
|
|
61
|
-
|
|
62
|
-
spin = _spin(w._content_widget, 50)
|
|
63
|
-
assert spin is not None
|
|
64
|
-
spin.setValue(88)
|
|
65
|
-
|
|
66
|
-
w._on_save_clicked()
|
|
67
|
-
|
|
68
|
-
with open(flow_copy, encoding='utf-8') as f:
|
|
69
|
-
data = json.load(f)
|
|
70
|
-
assert data['ABC Test']['A']['items']['level'] == 88
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def test_edit_survives_section_switch(qapp, make_editor, real_cfg_dir,
|
|
74
|
-
flow_copy):
|
|
75
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
76
|
-
w._on_button_clicked('A')
|
|
77
|
-
spin = _spin(w._content_widget, 50)
|
|
78
|
-
spin.setValue(77)
|
|
79
|
-
|
|
80
|
-
w._on_button_clicked('D')
|
|
81
|
-
w._on_save_clicked()
|
|
82
|
-
|
|
83
|
-
with open(flow_copy, encoding='utf-8') as f:
|
|
84
|
-
data = json.load(f)
|
|
85
|
-
assert data['ABC Test']['A']['items']['level'] == 77
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def test_save_as_redirects_path(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
89
|
-
tmp_path):
|
|
90
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
91
|
-
w._on_button_clicked('A')
|
|
92
|
-
|
|
93
|
-
target = str(tmp_path / 'other.json')
|
|
94
|
-
w._save_to(target)
|
|
95
|
-
|
|
96
|
-
# _save_to normalizes the redirected pipeline path to one OS-native form.
|
|
97
|
-
expected = _norm_path(target)
|
|
98
|
-
assert w.pipeline_path == expected
|
|
99
|
-
w._on_settings_clicked()
|
|
100
|
-
assert w._path_edits['pipeline'].text() == expected
|
|
101
|
-
with open(target, encoding='utf-8') as f:
|
|
102
|
-
data = json.load(f)
|
|
103
|
-
assert data['ABC Test']['A']['items']['level'] == 50
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def test_export_defaults_to_c(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
107
|
-
tmp_path, monkeypatch):
|
|
108
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
109
|
-
target = str(tmp_path / 'out.c')
|
|
110
|
-
monkeypatch.setattr(
|
|
111
|
-
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
112
|
-
lambda *a, **k: (target, w._EXPORT_FILTERS['c']))
|
|
113
|
-
|
|
114
|
-
w._on_export_clicked()
|
|
115
|
-
|
|
116
|
-
assert os.path.exists(target)
|
|
117
|
-
text = open(target, encoding='utf-8').read()
|
|
118
|
-
assert 'a_cfg_t A = {' in text
|
|
119
|
-
assert '.level = 50' in text
|
|
120
|
-
assert '.mode = A_MODE_HIGH' in text
|
|
121
|
-
assert w._last_export_type == 'c'
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def test_export_remembers_bin_type(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
125
|
-
tmp_path, monkeypatch):
|
|
126
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
127
|
-
target = str(tmp_path / 'out.bin')
|
|
128
|
-
monkeypatch.setattr(
|
|
129
|
-
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
130
|
-
lambda *a, **k: (target, w._EXPORT_FILTERS['bin']))
|
|
131
|
-
|
|
132
|
-
w._on_export_clicked()
|
|
133
|
-
|
|
134
|
-
assert os.path.exists(target)
|
|
135
|
-
data = open(target, 'rb').read()
|
|
136
|
-
assert len(data) > 0
|
|
137
|
-
assert w._last_export_type == 'bin'
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def test_export_cancel_does_nothing(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
141
|
-
monkeypatch):
|
|
142
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
143
|
-
monkeypatch.setattr(
|
|
144
|
-
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
145
|
-
lambda *a, **k: ('', ''))
|
|
146
|
-
|
|
147
|
-
w._on_export_clicked()
|
|
148
|
-
|
|
149
|
-
assert w._last_export_type == 'c'
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def test_elf_starts_unselected(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
153
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
154
|
-
assert w.elf_path == ''
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def test_pick_elf_sets_path(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
158
|
-
tmp_path, monkeypatch):
|
|
159
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
160
|
-
elf = str(tmp_path / 'fw.elf')
|
|
161
|
-
open(elf, 'wb').close()
|
|
162
|
-
monkeypatch.setattr(
|
|
163
|
-
QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: (elf, ''))
|
|
164
|
-
|
|
165
|
-
w._pick_elf_file()
|
|
166
|
-
|
|
167
|
-
assert w.elf_path == elf
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def test_disabling_elf_keeps_path_but_deactivates(qapp, make_editor,
|
|
171
|
-
real_cfg_dir, flow_copy,
|
|
172
|
-
tmp_path, monkeypatch):
|
|
173
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
174
|
-
elf = str(tmp_path / 'fw.elf')
|
|
175
|
-
open(elf, 'wb').close()
|
|
176
|
-
monkeypatch.setattr(
|
|
177
|
-
QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: (elf, ''))
|
|
178
|
-
|
|
179
|
-
w._on_settings_clicked()
|
|
180
|
-
w._pick_elf_file()
|
|
181
|
-
w._set_elf_enabled(True)
|
|
182
|
-
assert w.elf_path == elf
|
|
183
|
-
assert w._elf_active() is True
|
|
184
|
-
|
|
185
|
-
w._set_elf_enabled(False)
|
|
186
|
-
assert w.elf_path == elf
|
|
187
|
-
assert w._elf_active() is False
|
|
188
|
-
|
|
189
|
-
w._set_elf_enabled(True)
|
|
190
|
-
assert w.elf_path == elf
|
|
191
|
-
assert w._elf_active() is True
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
def test_pick_elf_cancel_keeps_state(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
195
|
-
monkeypatch):
|
|
196
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
197
|
-
monkeypatch.setattr(
|
|
198
|
-
QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: ('', ''))
|
|
199
|
-
|
|
200
|
-
w._pick_elf_file()
|
|
201
|
-
|
|
202
|
-
assert w.elf_path == ''
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
def test_export_bin_api_writes_file(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
206
|
-
tmp_path):
|
|
207
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
208
|
-
target = str(tmp_path / 'api.bin')
|
|
209
|
-
|
|
210
|
-
result = w.export_bin(target)
|
|
211
|
-
|
|
212
|
-
assert result is True
|
|
213
|
-
assert os.path.exists(target)
|
|
214
|
-
assert len(open(target, 'rb').read()) > 0
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
def test_export_bin_api_raises_on_bad_path(qapp, make_editor, real_cfg_dir,
|
|
218
|
-
flow_copy, tmp_path):
|
|
219
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
220
|
-
bad = str(tmp_path / 'no_such_dir' / 'api.bin')
|
|
221
|
-
|
|
222
|
-
with pytest.raises(Exception):
|
|
223
|
-
w.export_bin(bad)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
def test_export_bin_api_dialog_swallows_error(qapp, make_editor, real_cfg_dir,
|
|
227
|
-
flow_copy, tmp_path, monkeypatch):
|
|
228
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
229
|
-
bad = str(tmp_path / 'no_such_dir' / 'api.bin')
|
|
230
|
-
monkeypatch.setattr(
|
|
231
|
-
QtWidgets.QMessageBox, 'critical', lambda *a, **k: None)
|
|
232
|
-
|
|
233
|
-
assert w.export_bin(bad, show_dialogs=True) is False
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
def test_export_bin_api_dialog_on_success(qapp, make_editor, real_cfg_dir,
|
|
237
|
-
flow_copy, tmp_path, monkeypatch):
|
|
238
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
239
|
-
target = str(tmp_path / 'api.bin')
|
|
240
|
-
shown = []
|
|
241
|
-
monkeypatch.setattr(
|
|
242
|
-
QtWidgets.QMessageBox, 'information',
|
|
243
|
-
lambda *a, **k: shown.append(a))
|
|
244
|
-
|
|
245
|
-
result = w.export_bin(target, show_dialogs=True)
|
|
246
|
-
|
|
247
|
-
assert result is True
|
|
248
|
-
assert os.path.exists(target)
|
|
249
|
-
# Success pops the same information dialog as clicking Export.
|
|
250
|
-
assert len(shown) == 1
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def test_current_paths_api(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
254
|
-
w = make_editor(flow_copy, real_cfg_dir)
|
|
255
|
-
paths = w.current_paths()
|
|
256
|
-
assert paths['modules'] == _norm_path(real_cfg_dir)
|
|
257
|
-
assert paths['pipeline'] == _norm_path(flow_copy)
|
|
258
|
-
assert paths['elf'] == ''
|
|
1
|
+
"""Tests for the UI -> JSON save feature.
|
|
2
|
+
|
|
3
|
+
Save reads the live editors of the active section back into the raw flow
|
|
4
|
+
document and writes it out, patching only edited 'items' while leaving the
|
|
5
|
+
rest of the document (group structure, render hints) intact.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from Qt import QtWidgets
|
|
15
|
+
|
|
16
|
+
from struct2ui.editor import _norm_path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.fixture
|
|
20
|
+
def flow_copy(tmp_path):
|
|
21
|
+
"""Copy the real abc.json into a temp file so saves never touch the repo."""
|
|
22
|
+
import os
|
|
23
|
+
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
24
|
+
src = os.path.join(base, 'examples', 'test', 'abc.json')
|
|
25
|
+
dst = tmp_path / 'flow.json'
|
|
26
|
+
shutil.copy(src, dst)
|
|
27
|
+
return str(dst)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture(autouse=True)
|
|
31
|
+
def silence_dialogs(monkeypatch):
|
|
32
|
+
monkeypatch.setattr(QtWidgets.QMessageBox, 'information',
|
|
33
|
+
lambda *a, **k: None)
|
|
34
|
+
monkeypatch.setattr(QtWidgets.QMessageBox, 'critical',
|
|
35
|
+
lambda *a, **k: None)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _spin(widget, value):
|
|
39
|
+
for w in widget.findChildren(QtWidgets.QSpinBox):
|
|
40
|
+
if w.value() == value:
|
|
41
|
+
return w
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_save_preserves_structure(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
46
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
47
|
+
w._on_button_clicked('A')
|
|
48
|
+
w._on_save_clicked()
|
|
49
|
+
|
|
50
|
+
with open(flow_copy, encoding='utf-8') as f:
|
|
51
|
+
data = json.load(f)
|
|
52
|
+
group = data['ABC Test']
|
|
53
|
+
assert group['flow'] == ['A', 'B', 'C', 'D', 'E']
|
|
54
|
+
assert group['A']['type'] == 'a_cfg_t'
|
|
55
|
+
assert group['A']['items']['level'] == 50
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_edit_then_save_persists(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
59
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
60
|
+
w._on_button_clicked('A')
|
|
61
|
+
|
|
62
|
+
spin = _spin(w._content_widget, 50)
|
|
63
|
+
assert spin is not None
|
|
64
|
+
spin.setValue(88)
|
|
65
|
+
|
|
66
|
+
w._on_save_clicked()
|
|
67
|
+
|
|
68
|
+
with open(flow_copy, encoding='utf-8') as f:
|
|
69
|
+
data = json.load(f)
|
|
70
|
+
assert data['ABC Test']['A']['items']['level'] == 88
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_edit_survives_section_switch(qapp, make_editor, real_cfg_dir,
|
|
74
|
+
flow_copy):
|
|
75
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
76
|
+
w._on_button_clicked('A')
|
|
77
|
+
spin = _spin(w._content_widget, 50)
|
|
78
|
+
spin.setValue(77)
|
|
79
|
+
|
|
80
|
+
w._on_button_clicked('D')
|
|
81
|
+
w._on_save_clicked()
|
|
82
|
+
|
|
83
|
+
with open(flow_copy, encoding='utf-8') as f:
|
|
84
|
+
data = json.load(f)
|
|
85
|
+
assert data['ABC Test']['A']['items']['level'] == 77
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_save_as_redirects_path(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
89
|
+
tmp_path):
|
|
90
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
91
|
+
w._on_button_clicked('A')
|
|
92
|
+
|
|
93
|
+
target = str(tmp_path / 'other.json')
|
|
94
|
+
w._save_to(target)
|
|
95
|
+
|
|
96
|
+
# _save_to normalizes the redirected pipeline path to one OS-native form.
|
|
97
|
+
expected = _norm_path(target)
|
|
98
|
+
assert w.pipeline_path == expected
|
|
99
|
+
w._on_settings_clicked()
|
|
100
|
+
assert w._path_edits['pipeline'].text() == expected
|
|
101
|
+
with open(target, encoding='utf-8') as f:
|
|
102
|
+
data = json.load(f)
|
|
103
|
+
assert data['ABC Test']['A']['items']['level'] == 50
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_export_defaults_to_c(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
107
|
+
tmp_path, monkeypatch):
|
|
108
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
109
|
+
target = str(tmp_path / 'out.c')
|
|
110
|
+
monkeypatch.setattr(
|
|
111
|
+
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
112
|
+
lambda *a, **k: (target, w._EXPORT_FILTERS['c']))
|
|
113
|
+
|
|
114
|
+
w._on_export_clicked()
|
|
115
|
+
|
|
116
|
+
assert os.path.exists(target)
|
|
117
|
+
text = open(target, encoding='utf-8').read()
|
|
118
|
+
assert 'a_cfg_t A = {' in text
|
|
119
|
+
assert '.level = 50' in text
|
|
120
|
+
assert '.mode = A_MODE_HIGH' in text
|
|
121
|
+
assert w._last_export_type == 'c'
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_export_remembers_bin_type(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
125
|
+
tmp_path, monkeypatch):
|
|
126
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
127
|
+
target = str(tmp_path / 'out.bin')
|
|
128
|
+
monkeypatch.setattr(
|
|
129
|
+
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
130
|
+
lambda *a, **k: (target, w._EXPORT_FILTERS['bin']))
|
|
131
|
+
|
|
132
|
+
w._on_export_clicked()
|
|
133
|
+
|
|
134
|
+
assert os.path.exists(target)
|
|
135
|
+
data = open(target, 'rb').read()
|
|
136
|
+
assert len(data) > 0
|
|
137
|
+
assert w._last_export_type == 'bin'
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_export_cancel_does_nothing(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
141
|
+
monkeypatch):
|
|
142
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
143
|
+
monkeypatch.setattr(
|
|
144
|
+
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
145
|
+
lambda *a, **k: ('', ''))
|
|
146
|
+
|
|
147
|
+
w._on_export_clicked()
|
|
148
|
+
|
|
149
|
+
assert w._last_export_type == 'c'
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def test_elf_starts_unselected(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
153
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
154
|
+
assert w.elf_path == ''
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_pick_elf_sets_path(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
158
|
+
tmp_path, monkeypatch):
|
|
159
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
160
|
+
elf = str(tmp_path / 'fw.elf')
|
|
161
|
+
open(elf, 'wb').close()
|
|
162
|
+
monkeypatch.setattr(
|
|
163
|
+
QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: (elf, ''))
|
|
164
|
+
|
|
165
|
+
w._pick_elf_file()
|
|
166
|
+
|
|
167
|
+
assert w.elf_path == elf
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_disabling_elf_keeps_path_but_deactivates(qapp, make_editor,
|
|
171
|
+
real_cfg_dir, flow_copy,
|
|
172
|
+
tmp_path, monkeypatch):
|
|
173
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
174
|
+
elf = str(tmp_path / 'fw.elf')
|
|
175
|
+
open(elf, 'wb').close()
|
|
176
|
+
monkeypatch.setattr(
|
|
177
|
+
QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: (elf, ''))
|
|
178
|
+
|
|
179
|
+
w._on_settings_clicked()
|
|
180
|
+
w._pick_elf_file()
|
|
181
|
+
w._set_elf_enabled(True)
|
|
182
|
+
assert w.elf_path == elf
|
|
183
|
+
assert w._elf_active() is True
|
|
184
|
+
|
|
185
|
+
w._set_elf_enabled(False)
|
|
186
|
+
assert w.elf_path == elf
|
|
187
|
+
assert w._elf_active() is False
|
|
188
|
+
|
|
189
|
+
w._set_elf_enabled(True)
|
|
190
|
+
assert w.elf_path == elf
|
|
191
|
+
assert w._elf_active() is True
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def test_pick_elf_cancel_keeps_state(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
195
|
+
monkeypatch):
|
|
196
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
197
|
+
monkeypatch.setattr(
|
|
198
|
+
QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: ('', ''))
|
|
199
|
+
|
|
200
|
+
w._pick_elf_file()
|
|
201
|
+
|
|
202
|
+
assert w.elf_path == ''
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def test_export_bin_api_writes_file(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
206
|
+
tmp_path):
|
|
207
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
208
|
+
target = str(tmp_path / 'api.bin')
|
|
209
|
+
|
|
210
|
+
result = w.export_bin(target)
|
|
211
|
+
|
|
212
|
+
assert result is True
|
|
213
|
+
assert os.path.exists(target)
|
|
214
|
+
assert len(open(target, 'rb').read()) > 0
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def test_export_bin_api_raises_on_bad_path(qapp, make_editor, real_cfg_dir,
|
|
218
|
+
flow_copy, tmp_path):
|
|
219
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
220
|
+
bad = str(tmp_path / 'no_such_dir' / 'api.bin')
|
|
221
|
+
|
|
222
|
+
with pytest.raises(Exception):
|
|
223
|
+
w.export_bin(bad)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def test_export_bin_api_dialog_swallows_error(qapp, make_editor, real_cfg_dir,
|
|
227
|
+
flow_copy, tmp_path, monkeypatch):
|
|
228
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
229
|
+
bad = str(tmp_path / 'no_such_dir' / 'api.bin')
|
|
230
|
+
monkeypatch.setattr(
|
|
231
|
+
QtWidgets.QMessageBox, 'critical', lambda *a, **k: None)
|
|
232
|
+
|
|
233
|
+
assert w.export_bin(bad, show_dialogs=True) is False
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def test_export_bin_api_dialog_on_success(qapp, make_editor, real_cfg_dir,
|
|
237
|
+
flow_copy, tmp_path, monkeypatch):
|
|
238
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
239
|
+
target = str(tmp_path / 'api.bin')
|
|
240
|
+
shown = []
|
|
241
|
+
monkeypatch.setattr(
|
|
242
|
+
QtWidgets.QMessageBox, 'information',
|
|
243
|
+
lambda *a, **k: shown.append(a))
|
|
244
|
+
|
|
245
|
+
result = w.export_bin(target, show_dialogs=True)
|
|
246
|
+
|
|
247
|
+
assert result is True
|
|
248
|
+
assert os.path.exists(target)
|
|
249
|
+
# Success pops the same information dialog as clicking Export.
|
|
250
|
+
assert len(shown) == 1
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def test_current_paths_api(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
254
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
255
|
+
paths = w.current_paths()
|
|
256
|
+
assert paths['modules'] == _norm_path(real_cfg_dir)
|
|
257
|
+
assert paths['pipeline'] == _norm_path(flow_copy)
|
|
258
|
+
assert paths['elf'] == ''
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|