forked from zamtmn/zcad
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_issue1399_acadtable_default_alignment.py
More file actions
105 lines (88 loc) · 3.03 KB
/
Copy pathtest_issue1399_acadtable_default_alignment.py
File metadata and controls
105 lines (88 loc) · 3.03 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
"""Контракт сохранения стандартного выравнивания AcadTable для issue 1399."""
from pathlib import Path
ROOT = Path(__file__).resolve().parent
FIXTURES = ROOT / "experiments" / "issue1399"
DIMENSIONS = (
ROOT
/ "cad_source"
/ "zcad"
/ "velec"
/ "uzvspreadsheet"
/ "uzvspreadsheet_dimensions.pas"
)
WRITER = (
ROOT
/ "cad_source"
/ "zcad"
/ "velec"
/ "acadtable"
/ "uzeacadtable_dxf_write.pas"
)
def compact(text: str) -> str:
return "".join(text.split()).lower()
def extract(source: str, start_marker: str, end_marker: str) -> str:
start = source.index(start_marker)
end = source.index(end_marker, start + len(start_marker))
return source[start:end]
def acad_table_cell_properties(path: Path) -> list[tuple[str, str]]:
lines = path.read_text(encoding="utf-8").splitlines()
pairs = [
(lines[index].strip(), lines[index + 1].strip())
for index in range(0, len(lines) - 1, 2)
]
table_start = max(
index
for index, pair in enumerate(pairs)
if pair == ("0", "ACAD_TABLE")
)
table_end = next(
index
for index in range(table_start + 1, len(pairs))
if pairs[index][0] == "0"
)
table = pairs[table_start:table_end]
result = []
for index, pair in enumerate(table):
if pair == ("301", "CELL_VALUE"):
properties = dict(table[max(0, index - 12):index])
result.append((properties["91"], properties["170"]))
return result
def test_autocad_fixture_marks_alignment_as_cell_override():
zcad = acad_table_cell_properties(FIXTURES / "zcadtablevyrav.txt")
autocad = acad_table_cell_properties(FIXTURES / "acadtablevyrav.txt")
assert len(zcad) == len(autocad) == 12
assert set(zcad) == {("262144", "1")}
assert set(autocad) == {("262145", "1")}
def test_default_alignment_is_serialized_as_top_left():
source = DIMENSIONS.read_text(encoding="utf-8")
body = compact(
extract(
source,
"function CollectCellAlignments",
"\nend;\n\nend.",
)
)
default_call = (
"worksheetalignmenttoacad("
"fpstypes.hadefault,fpstypes.vadefault)"
)
assert default_call in body
assert "result[rowidx*acolcount+colidx]:=0;" not in body
def test_writer_emits_every_nonzero_alignment():
source = WRITER.read_text(encoding="utf-8")
body = compact(
extract(source, "procedure WriteCell", "procedure WriteTableCells")
)
assert "ifalignment<>0then" in body
assert (
"ifalignment<>0then"
"dxfintegerout(aoutstream,91,262145)"
"elsedxfintegerout(aoutstream,91,262144);"
) in body
assert "dxfintegerout(aoutstream,170,alignment);" in body
if __name__ == "__main__":
test_autocad_fixture_marks_alignment_as_cell_override()
test_default_alignment_is_serialized_as_top_left()
test_writer_emits_every_nonzero_alignment()
print("issue 1399 AcadTable default alignment checks passed")