mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
IfcTester can now output reports in plain text
This commit is contained in:
@@ -49,6 +49,8 @@ start = time.time()
|
|||||||
|
|
||||||
if args.reporter == "Console":
|
if args.reporter == "Console":
|
||||||
engine = reporter.Console(specs, use_colour=not args.no_color)
|
engine = reporter.Console(specs, use_colour=not args.no_color)
|
||||||
|
elif args.reporter == "Txt":
|
||||||
|
engine = reporter.Txt(specs)
|
||||||
elif args.reporter == "Json":
|
elif args.reporter == "Json":
|
||||||
engine = reporter.Json(specs)
|
engine = reporter.Json(specs)
|
||||||
elif args.reporter == "Html":
|
elif args.reporter == "Html":
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import datetime
|
|||||||
|
|
||||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
class Reporter:
|
class Reporter:
|
||||||
def __init__(self, ids):
|
def __init__(self, ids):
|
||||||
self.ids = ids
|
self.ids = ids
|
||||||
@@ -57,7 +58,7 @@ class Console(Reporter):
|
|||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
self.set_style("bold", "blue")
|
self.set_style("bold", "blue")
|
||||||
print(self.ids.info.get("title", "Untitled IDS"))
|
self.print(self.ids.info.get("title", "Untitled IDS"))
|
||||||
for specification in self.ids.specifications:
|
for specification in self.ids.specifications:
|
||||||
self.report_specification(specification)
|
self.report_specification(specification)
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
@@ -65,48 +66,48 @@ class Console(Reporter):
|
|||||||
def report_specification(self, specification):
|
def report_specification(self, specification):
|
||||||
if specification.status is True:
|
if specification.status is True:
|
||||||
self.set_style("bold", "green")
|
self.set_style("bold", "green")
|
||||||
print("[PASS] ", end="")
|
self.print("[PASS] ", end="")
|
||||||
elif specification.status is False:
|
elif specification.status is False:
|
||||||
self.set_style("bold", "red")
|
self.set_style("bold", "red")
|
||||||
print("[FAIL] ", end="")
|
self.print("[FAIL] ", end="")
|
||||||
elif specification.status is None:
|
elif specification.status is None:
|
||||||
self.set_style("bold", "yellow")
|
self.set_style("bold", "yellow")
|
||||||
print("[UNTESTED] ", end="")
|
self.print("[UNTESTED] ", end="")
|
||||||
|
|
||||||
self.set_style("bold")
|
self.set_style("bold")
|
||||||
total = len(specification.applicable_entities)
|
total = len(specification.applicable_entities)
|
||||||
total_successes = total - len(specification.failed_entities)
|
total_successes = total - len(specification.failed_entities)
|
||||||
print(f"({total_successes}/{total}) ", end="")
|
self.print(f"({total_successes}/{total}) ", end="")
|
||||||
|
|
||||||
if specification.minOccurs != 0:
|
if specification.minOccurs != 0:
|
||||||
print(f"*", end="")
|
self.print(f"*", end="")
|
||||||
|
|
||||||
print(specification.name)
|
self.print(specification.name)
|
||||||
|
|
||||||
self.set_style("cyan")
|
self.set_style("cyan")
|
||||||
print(" " * 4 + "Applies to:")
|
self.print(" " * 4 + "Applies to:")
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
|
|
||||||
for applicability in specification.applicability:
|
for applicability in specification.applicability:
|
||||||
print(" " * 8 + applicability.to_string("applicability"))
|
self.print(" " * 8 + applicability.to_string("applicability"))
|
||||||
|
|
||||||
if not total and specification.status is False:
|
if not total and specification.status is False:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.set_style("cyan")
|
self.set_style("cyan")
|
||||||
print(" " * 4 + "Requirements:")
|
self.print(" " * 4 + "Requirements:")
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
|
|
||||||
for requirement in specification.requirements:
|
for requirement in specification.requirements:
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
self.set_style("red") if requirement.failed_entities else self.set_style("green")
|
self.set_style("red") if requirement.failed_entities else self.set_style("green")
|
||||||
print(" " * 8 + requirement.to_string("requirement"))
|
self.print(" " * 8 + requirement.to_string("requirement"))
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
for i, element in enumerate(requirement.failed_entities[0:10]):
|
for i, element in enumerate(requirement.failed_entities[0:10]):
|
||||||
print(" " * 12, end="")
|
self.print(" " * 12, end="")
|
||||||
self.report_reason(requirement.failed_reasons[i], element)
|
self.report_reason(requirement.failed_reasons[i], element)
|
||||||
if len(requirement.failed_entities) > 10:
|
if len(requirement.failed_entities) > 10:
|
||||||
print(" " * 12 + f"... {len(requirement.failed_entities)} in total ...")
|
self.print(" " * 12 + f"... {len(requirement.failed_entities)} in total ...")
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
|
|
||||||
def report_reason(self, reason, element):
|
def report_reason(self, reason, element):
|
||||||
@@ -116,16 +117,38 @@ class Console(Reporter):
|
|||||||
self.set_style("purple")
|
self.set_style("purple")
|
||||||
else:
|
else:
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
print(substring, end="")
|
self.print(substring, end="")
|
||||||
is_bold = not is_bold
|
is_bold = not is_bold
|
||||||
self.set_style("grey")
|
self.set_style("grey")
|
||||||
print(" - " + str(element))
|
self.print(" - " + str(element))
|
||||||
self.set_style("reset")
|
self.set_style("reset")
|
||||||
|
|
||||||
def set_style(self, *colours):
|
def set_style(self, *colours):
|
||||||
if self.use_colour:
|
if self.use_colour:
|
||||||
sys.stdout.write("".join([self.colours[c] for c in colours]))
|
sys.stdout.write("".join([self.colours[c] for c in colours]))
|
||||||
|
|
||||||
|
def print(self, txt, end=None):
|
||||||
|
if end is not None:
|
||||||
|
print(txt, end=end)
|
||||||
|
else:
|
||||||
|
print(txt)
|
||||||
|
|
||||||
|
|
||||||
|
class Txt(Console):
|
||||||
|
def __init__(self, ids):
|
||||||
|
super().__init__(ids, use_colour=False)
|
||||||
|
self.text = ""
|
||||||
|
|
||||||
|
def print(self, txt, end=None):
|
||||||
|
self.text += txt + "\n" if end is None else txt
|
||||||
|
|
||||||
|
def to_string(self):
|
||||||
|
print(self.text)
|
||||||
|
|
||||||
|
def to_file(self, filepath):
|
||||||
|
with open(filepath, "w") as outfile:
|
||||||
|
return outfile.write(self.text)
|
||||||
|
|
||||||
|
|
||||||
class Json(Reporter):
|
class Json(Reporter):
|
||||||
def __init__(self, ids):
|
def __init__(self, ids):
|
||||||
|
|||||||
Reference in New Issue
Block a user