Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "xml2db"
version = "0.12.4"
version = "0.12.5"
authors = [
{ name="Commission de régulation de l'énergie", email="opensource@cre.fr" },
]
Expand Down
22 changes: 2 additions & 20 deletions src/xml2db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _build_model(self):
)
self.root_table = root_table.type_name
# compute a text representation of the original data model and store it
self.source_tree = "\n".join(self._repr_tree(root_table))
self.source_tree = str(root_table)
# check user-provided configuration for tables
for tb_config in self.model_config.get("tables", {}):
if tb_config not in self.names_types_map:
Expand All @@ -245,7 +245,7 @@ def _build_model(self):
key: tb for key, tb in self.tables.items() if hasattr(tb, "keep_table")
}
# compute a text representation of the simplified data model and store it
self.target_tree = "\n".join(self._repr_tree(root_table))
self.target_tree = str(root_table)
# add parent table information on each table when it is not reused
# raises an error if a table is not configured as "reused" and have more than 1 parent table
for tb in self.tables.values():
Expand Down Expand Up @@ -572,24 +572,6 @@ def get_occurs(particle):

return parent_table

def _repr_tree(
self,
parent_table: Union[DataModelTableReused, DataModelTableDuplicated],
):
"""Build a text representation of the data model tree

Args:
parent_table: the current data model table object
"""
for field_type, name, field in parent_table.fields:
if field_type == "col":
yield f"{field.name}{field.occurs}: {field.data_type}"
else:
mg = " (choice)" if field.other_table.model_group == "choice" else ""
yield f"{field.name}{field.occurs}{mg}:"
for line in self._repr_tree(field.other_table):
yield f" {line}"

def get_entity_rel_diagram(self, text_context: bool = True) -> str:
"""Build an entity relationship diagram for the data model

Expand Down
13 changes: 13 additions & 0 deletions src/xml2db/table/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ def add_relation_n(self, name, other_table, occurs, ngroup):
self.fields.append(("reln", name, rel))
other_table.parents_n.add(rel)

def __repr__(self):
"""Build a text representation of a table recursively"""
lines = [f"{self.name}:"]
for field_type, name, field in self.fields:
if field_type == "col":
lines.append(f" {field.name}{field.occurs}: {field.data_type}")
else:
mg = " (choice)" if field.other_table.model_group == "choice" else ""
lines.append(f" {field.name}{field.occurs}{mg}:")
for line in str(field.other_table).split("\n")[1:]:
lines.append(f" {line}")
return "\n".join(lines)

def compute_dependencies(self) -> None:
"""Compute the table's dependencies according to foreign keys relationships.

Expand Down
241 changes: 241 additions & 0 deletions tests/sample_models/junit10/junit10_source_tree_version0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
junit10:
error[1, 1]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
failure[1, 1]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
flakyError[1, 1]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
flakyFailure[1, 1]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
properties[1, 1]:
property[0, None]:
name[0, 1]: string
value[0, 1]: string
property[1, 1]:
name[0, 1]: string
value[0, 1]: string
rerunError[1, 1]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
rerunFailure[1, 1]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
skipped[1, 1]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
system-err[1, 1]: string
system-out[1, 1]: string
testcase[1, 1]:
classname[0, 1]: string
name[0, 1]: string
time[0, 1]: string
group[0, 1]: string
skipped[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
error[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
failure[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
rerunFailure[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
rerunError[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
flakyFailure[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
flakyError[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
system-out[0, None]: string
system-err[0, None]: string
testsuite[1, 1] (choice):
name[0, 1]: string
errors[0, 1]: string
failures[0, 1]: string
skipped[0, 1]: string
tests[0, 1]: string
group[0, 1]: string
time[0, 1]: string
timestamp[0, 1]: string
hostname[0, 1]: string
id[0, 1]: string
package[0, 1]: string
file[0, 1]: string
log[0, 1]: string
url[0, 1]: string
version[0, 1]: string
properties[0, None]:
property[0, None]:
name[0, 1]: string
value[0, 1]: string
testcase[0, None]:
classname[0, 1]: string
name[0, 1]: string
time[0, 1]: string
group[0, 1]: string
skipped[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
error[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
failure[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
rerunFailure[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
rerunError[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
flakyFailure[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
flakyError[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
system-out[0, None]: string
system-err[0, None]: string
system-out[0, None]: string
system-err[0, None]: string
testsuites[1, 1]:
name[0, 1]: string
time[0, 1]: string
tests[0, 1]: string
failures[0, 1]: string
errors[0, 1]: string
testsuite[0, None] (choice):
name[0, 1]: string
errors[0, 1]: string
failures[0, 1]: string
skipped[0, 1]: string
tests[0, 1]: string
group[0, 1]: string
time[0, 1]: string
timestamp[0, 1]: string
hostname[0, 1]: string
id[0, 1]: string
package[0, 1]: string
file[0, 1]: string
log[0, 1]: string
url[0, 1]: string
version[0, 1]: string
properties[0, None]:
property[0, None]:
name[0, 1]: string
value[0, 1]: string
testcase[0, None]:
classname[0, 1]: string
name[0, 1]: string
time[0, 1]: string
group[0, 1]: string
skipped[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
error[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
failure[0, None]:
type[0, 1]: string
message[0, 1]: string
value[0, 1]: string
rerunFailure[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
rerunError[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
flakyFailure[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
flakyError[0, None]:
message[0, 1]: string
type[0, 1]: string
stackTrace[0, 1]: string
system-out[0, 1]: string
system-err[0, 1]: string
value[0, 1]: string
system-out[0, None]: string
system-err[0, None]: string
system-out[0, None]: string
system-err[0, None]: string
Loading
Loading