Skip to content

Commit d34fe21

Browse files
martinv13cre-os
andauthored
Fix models tree repr (#33)
Add a test for stable source and target tree repr Co-authored-by: cre-os <opensource@cre.fr>
1 parent 76269d4 commit d34fe21

19 files changed

+2446
-31
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "xml2db"
7-
version = "0.12.4"
7+
version = "0.12.5"
88
authors = [
99
{ name="Commission de régulation de l'énergie", email="opensource@cre.fr" },
1010
]

src/xml2db/model.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _build_model(self):
230230
)
231231
self.root_table = root_table.type_name
232232
# compute a text representation of the original data model and store it
233-
self.source_tree = "\n".join(self._repr_tree(root_table))
233+
self.source_tree = str(root_table)
234234
# check user-provided configuration for tables
235235
for tb_config in self.model_config.get("tables", {}):
236236
if tb_config not in self.names_types_map:
@@ -245,7 +245,7 @@ def _build_model(self):
245245
key: tb for key, tb in self.tables.items() if hasattr(tb, "keep_table")
246246
}
247247
# compute a text representation of the simplified data model and store it
248-
self.target_tree = "\n".join(self._repr_tree(root_table))
248+
self.target_tree = str(root_table)
249249
# add parent table information on each table when it is not reused
250250
# raises an error if a table is not configured as "reused" and have more than 1 parent table
251251
for tb in self.tables.values():
@@ -572,24 +572,6 @@ def get_occurs(particle):
572572

573573
return parent_table
574574

575-
def _repr_tree(
576-
self,
577-
parent_table: Union[DataModelTableReused, DataModelTableDuplicated],
578-
):
579-
"""Build a text representation of the data model tree
580-
581-
Args:
582-
parent_table: the current data model table object
583-
"""
584-
for field_type, name, field in parent_table.fields:
585-
if field_type == "col":
586-
yield f"{field.name}{field.occurs}: {field.data_type}"
587-
else:
588-
mg = " (choice)" if field.other_table.model_group == "choice" else ""
589-
yield f"{field.name}{field.occurs}{mg}:"
590-
for line in self._repr_tree(field.other_table):
591-
yield f" {line}"
592-
593575
def get_entity_rel_diagram(self, text_context: bool = True) -> str:
594576
"""Build an entity relationship diagram for the data model
595577

src/xml2db/table/table.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ def add_relation_n(self, name, other_table, occurs, ngroup):
224224
self.fields.append(("reln", name, rel))
225225
other_table.parents_n.add(rel)
226226

227+
def __repr__(self):
228+
"""Build a text representation of a table recursively"""
229+
lines = [f"{self.name}:"]
230+
for field_type, name, field in self.fields:
231+
if field_type == "col":
232+
lines.append(f" {field.name}{field.occurs}: {field.data_type}")
233+
else:
234+
mg = " (choice)" if field.other_table.model_group == "choice" else ""
235+
lines.append(f" {field.name}{field.occurs}{mg}:")
236+
for line in str(field.other_table).split("\n")[1:]:
237+
lines.append(f" {line}")
238+
return "\n".join(lines)
239+
227240
def compute_dependencies(self) -> None:
228241
"""Compute the table's dependencies according to foreign keys relationships.
229242
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
junit10:
2+
error[1, 1]:
3+
type[0, 1]: string
4+
message[0, 1]: string
5+
value[0, 1]: string
6+
failure[1, 1]:
7+
type[0, 1]: string
8+
message[0, 1]: string
9+
value[0, 1]: string
10+
flakyError[1, 1]:
11+
message[0, 1]: string
12+
type[0, 1]: string
13+
stackTrace[0, 1]: string
14+
system-out[0, 1]: string
15+
system-err[0, 1]: string
16+
value[0, 1]: string
17+
flakyFailure[1, 1]:
18+
message[0, 1]: string
19+
type[0, 1]: string
20+
stackTrace[0, 1]: string
21+
system-out[0, 1]: string
22+
system-err[0, 1]: string
23+
value[0, 1]: string
24+
properties[1, 1]:
25+
property[0, None]:
26+
name[0, 1]: string
27+
value[0, 1]: string
28+
property[1, 1]:
29+
name[0, 1]: string
30+
value[0, 1]: string
31+
rerunError[1, 1]:
32+
message[0, 1]: string
33+
type[0, 1]: string
34+
stackTrace[0, 1]: string
35+
system-out[0, 1]: string
36+
system-err[0, 1]: string
37+
value[0, 1]: string
38+
rerunFailure[1, 1]:
39+
message[0, 1]: string
40+
type[0, 1]: string
41+
stackTrace[0, 1]: string
42+
system-out[0, 1]: string
43+
system-err[0, 1]: string
44+
value[0, 1]: string
45+
skipped[1, 1]:
46+
type[0, 1]: string
47+
message[0, 1]: string
48+
value[0, 1]: string
49+
system-err[1, 1]: string
50+
system-out[1, 1]: string
51+
testcase[1, 1]:
52+
classname[0, 1]: string
53+
name[0, 1]: string
54+
time[0, 1]: string
55+
group[0, 1]: string
56+
skipped[0, None]:
57+
type[0, 1]: string
58+
message[0, 1]: string
59+
value[0, 1]: string
60+
error[0, None]:
61+
type[0, 1]: string
62+
message[0, 1]: string
63+
value[0, 1]: string
64+
failure[0, None]:
65+
type[0, 1]: string
66+
message[0, 1]: string
67+
value[0, 1]: string
68+
rerunFailure[0, None]:
69+
message[0, 1]: string
70+
type[0, 1]: string
71+
stackTrace[0, 1]: string
72+
system-out[0, 1]: string
73+
system-err[0, 1]: string
74+
value[0, 1]: string
75+
rerunError[0, None]:
76+
message[0, 1]: string
77+
type[0, 1]: string
78+
stackTrace[0, 1]: string
79+
system-out[0, 1]: string
80+
system-err[0, 1]: string
81+
value[0, 1]: string
82+
flakyFailure[0, None]:
83+
message[0, 1]: string
84+
type[0, 1]: string
85+
stackTrace[0, 1]: string
86+
system-out[0, 1]: string
87+
system-err[0, 1]: string
88+
value[0, 1]: string
89+
flakyError[0, None]:
90+
message[0, 1]: string
91+
type[0, 1]: string
92+
stackTrace[0, 1]: string
93+
system-out[0, 1]: string
94+
system-err[0, 1]: string
95+
value[0, 1]: string
96+
system-out[0, None]: string
97+
system-err[0, None]: string
98+
testsuite[1, 1] (choice):
99+
name[0, 1]: string
100+
errors[0, 1]: string
101+
failures[0, 1]: string
102+
skipped[0, 1]: string
103+
tests[0, 1]: string
104+
group[0, 1]: string
105+
time[0, 1]: string
106+
timestamp[0, 1]: string
107+
hostname[0, 1]: string
108+
id[0, 1]: string
109+
package[0, 1]: string
110+
file[0, 1]: string
111+
log[0, 1]: string
112+
url[0, 1]: string
113+
version[0, 1]: string
114+
properties[0, None]:
115+
property[0, None]:
116+
name[0, 1]: string
117+
value[0, 1]: string
118+
testcase[0, None]:
119+
classname[0, 1]: string
120+
name[0, 1]: string
121+
time[0, 1]: string
122+
group[0, 1]: string
123+
skipped[0, None]:
124+
type[0, 1]: string
125+
message[0, 1]: string
126+
value[0, 1]: string
127+
error[0, None]:
128+
type[0, 1]: string
129+
message[0, 1]: string
130+
value[0, 1]: string
131+
failure[0, None]:
132+
type[0, 1]: string
133+
message[0, 1]: string
134+
value[0, 1]: string
135+
rerunFailure[0, None]:
136+
message[0, 1]: string
137+
type[0, 1]: string
138+
stackTrace[0, 1]: string
139+
system-out[0, 1]: string
140+
system-err[0, 1]: string
141+
value[0, 1]: string
142+
rerunError[0, None]:
143+
message[0, 1]: string
144+
type[0, 1]: string
145+
stackTrace[0, 1]: string
146+
system-out[0, 1]: string
147+
system-err[0, 1]: string
148+
value[0, 1]: string
149+
flakyFailure[0, None]:
150+
message[0, 1]: string
151+
type[0, 1]: string
152+
stackTrace[0, 1]: string
153+
system-out[0, 1]: string
154+
system-err[0, 1]: string
155+
value[0, 1]: string
156+
flakyError[0, None]:
157+
message[0, 1]: string
158+
type[0, 1]: string
159+
stackTrace[0, 1]: string
160+
system-out[0, 1]: string
161+
system-err[0, 1]: string
162+
value[0, 1]: string
163+
system-out[0, None]: string
164+
system-err[0, None]: string
165+
system-out[0, None]: string
166+
system-err[0, None]: string
167+
testsuites[1, 1]:
168+
name[0, 1]: string
169+
time[0, 1]: string
170+
tests[0, 1]: string
171+
failures[0, 1]: string
172+
errors[0, 1]: string
173+
testsuite[0, None] (choice):
174+
name[0, 1]: string
175+
errors[0, 1]: string
176+
failures[0, 1]: string
177+
skipped[0, 1]: string
178+
tests[0, 1]: string
179+
group[0, 1]: string
180+
time[0, 1]: string
181+
timestamp[0, 1]: string
182+
hostname[0, 1]: string
183+
id[0, 1]: string
184+
package[0, 1]: string
185+
file[0, 1]: string
186+
log[0, 1]: string
187+
url[0, 1]: string
188+
version[0, 1]: string
189+
properties[0, None]:
190+
property[0, None]:
191+
name[0, 1]: string
192+
value[0, 1]: string
193+
testcase[0, None]:
194+
classname[0, 1]: string
195+
name[0, 1]: string
196+
time[0, 1]: string
197+
group[0, 1]: string
198+
skipped[0, None]:
199+
type[0, 1]: string
200+
message[0, 1]: string
201+
value[0, 1]: string
202+
error[0, None]:
203+
type[0, 1]: string
204+
message[0, 1]: string
205+
value[0, 1]: string
206+
failure[0, None]:
207+
type[0, 1]: string
208+
message[0, 1]: string
209+
value[0, 1]: string
210+
rerunFailure[0, None]:
211+
message[0, 1]: string
212+
type[0, 1]: string
213+
stackTrace[0, 1]: string
214+
system-out[0, 1]: string
215+
system-err[0, 1]: string
216+
value[0, 1]: string
217+
rerunError[0, None]:
218+
message[0, 1]: string
219+
type[0, 1]: string
220+
stackTrace[0, 1]: string
221+
system-out[0, 1]: string
222+
system-err[0, 1]: string
223+
value[0, 1]: string
224+
flakyFailure[0, None]:
225+
message[0, 1]: string
226+
type[0, 1]: string
227+
stackTrace[0, 1]: string
228+
system-out[0, 1]: string
229+
system-err[0, 1]: string
230+
value[0, 1]: string
231+
flakyError[0, None]:
232+
message[0, 1]: string
233+
type[0, 1]: string
234+
stackTrace[0, 1]: string
235+
system-out[0, 1]: string
236+
system-err[0, 1]: string
237+
value[0, 1]: string
238+
system-out[0, None]: string
239+
system-err[0, None]: string
240+
system-out[0, None]: string
241+
system-err[0, None]: string

0 commit comments

Comments
 (0)