forked from zamtmn/zcad
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_issue1396_acadtable_save_contract.py
More file actions
70 lines (55 loc) · 2.28 KB
/
Copy pathtest_issue1396_acadtable_save_contract.py
File metadata and controls
70 lines (55 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""Контракт сохранения координат и выравнивания AcadTable для issue 1396."""
from pathlib import Path
ROOT = Path(__file__).resolve().parent
MODEL = (
ROOT / "cad_source" / "zcad" / "velec" / "acadtable"
/ "uzeacadtable_model.pas"
)
WRITER = (
ROOT / "cad_source" / "zcad" / "velec" / "acadtable"
/ "uzeacadtable_dxf_write.pas"
)
FPUNIT = ROOT / "cad_source" / "zengine" / "tests" / "uzctacadtable.pas"
def compact(text: str) -> str:
return "".join(text.split()).lower()
def extract_procedure(source: str, marker: str, next_marker: str) -> str:
start = source.index(marker)
end = source.index(next_marker, start + len(marker))
return source[start:end]
def test_writer_uses_current_local_insert_point():
source = MODEL.read_text(encoding="utf-8")
body = compact(
extract_procedure(
source,
"procedure GDBObjAcadTable.FillDXFWritePartFromSelf",
"procedure GDBObjAcadTable.FillDXFWritePartFromContinuation",
)
)
assert "apart.insertpoint:=local.p_insert;" in body
assert "apart.insertpoint:=finsertpoint;" not in body
def test_alignment_uses_autocad_cell_group_order():
source = WRITER.read_text(encoding="utf-8")
body = compact(
extract_procedure(source, "procedure WriteCell", "procedure WriteTableCells")
)
groups = [
"dxfintegerout(aoutstream,176,rowspan);",
"dxfintegerout(aoutstream,91,262145)",
"dxfintegerout(aoutstream,178,0);",
"dxfdoubleout(aoutstream,145,0);",
"dxfintegerout(aoutstream,170,alignment);",
"dxfintegerout(aoutstream,92,0);",
]
positions = [body.index(group) for group in groups]
assert positions == sorted(positions)
def test_fpunit_reproduces_save_round_trip():
source = FPUNIT.read_text(encoding="utf-8")
assert "procedure SavesTransformedInsertPointAndCellAlignmentToDXF;" in source
assert "Table^.transform(MoveMatrix);" in source
assert "'145', '0', '170', '9', '92', '0'" in source
if __name__ == "__main__":
test_writer_uses_current_local_insert_point()
test_alignment_uses_autocad_cell_group_order()
test_fpunit_reproduces_save_round_trip()
print("issue 1396 AcadTable save contract checks passed")