pylint improvements on report_test
This commit is contained in:
@@ -36,6 +36,7 @@ example = os.path.join(DATA_DIR, "tests", "data.gramps")
|
|||||||
|
|
||||||
TREE_NAME = "Test_reporttest"
|
TREE_NAME = "Test_reporttest"
|
||||||
|
|
||||||
|
|
||||||
class ReportControl:
|
class ReportControl:
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
out, err = self.call("-y", "--remove", TREE_NAME)
|
out, err = self.call("-y", "--remove", TREE_NAME)
|
||||||
@@ -75,28 +76,32 @@ class ReportControl:
|
|||||||
report_name,
|
report_name,
|
||||||
test_function,
|
test_function,
|
||||||
files,
|
files,
|
||||||
*args))
|
*args, **options))
|
||||||
|
|
||||||
|
|
||||||
def dynamic_report_method(report_name, test_function,
|
def dynamic_report_method(report_name, test_function,
|
||||||
files, *args, **options):
|
files, *args, **options):
|
||||||
args = list(args)
|
args = list(args)
|
||||||
args[-1] += "," + (",".join(["%s=%s" % (k, v) for (k,v) in options.items()]))
|
args[-1] += "," + (",".join(["%s=%s" % (k, v)
|
||||||
|
for (k, v) in options.items()]))
|
||||||
options["files"] = files
|
options["files"] = files
|
||||||
# This needs to have "test" in name:
|
|
||||||
def test_method(self):
|
def test_method(self): # This needs to have "test" in name
|
||||||
out, err = self.call(*args)
|
out, err = self.call(*args)
|
||||||
self.assertTrue(test_function(out, err, report_name, **options))
|
self.assertTrue(test_function(out, err, report_name, **options))
|
||||||
return test_method
|
return test_method
|
||||||
|
|
||||||
|
|
||||||
def dynamic_cli_method(report_name, test_function,
|
def dynamic_cli_method(report_name, test_function,
|
||||||
files, *args, **options):
|
files, *args, **options):
|
||||||
options["files"] = files
|
options["files"] = files
|
||||||
# This needs to have "test" in name:
|
|
||||||
def test_method(self):
|
def test_method(self): # This needs to have "test" in name
|
||||||
out, err = self.call(*args)
|
out, err = self.call(*args)
|
||||||
self.assertTrue(test_function(out, err, report_name, **options))
|
self.assertTrue(test_function(out, err, report_name, **options))
|
||||||
return test_method
|
return test_method
|
||||||
|
|
||||||
|
|
||||||
class TestDynamic(unittest.TestCase):
|
class TestDynamic(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -120,6 +125,7 @@ class TestDynamic(unittest.TestCase):
|
|||||||
|
|
||||||
reports = ReportControl()
|
reports = ReportControl()
|
||||||
|
|
||||||
|
|
||||||
def report_contains(text):
|
def report_contains(text):
|
||||||
def test_output_file(out, err, report_name, **options):
|
def test_output_file(out, err, report_name, **options):
|
||||||
ext = options["off"]
|
ext = options["off"]
|
||||||
@@ -135,16 +141,19 @@ def report_contains(text):
|
|||||||
elif os.path.isfile(filename):
|
elif os.path.isfile(filename):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % filename)
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
filename)
|
||||||
elif os.path.isfile(report_name + "." + ext):
|
elif os.path.isfile(report_name + "." + ext):
|
||||||
os.remove(report_name + "." + ext)
|
os.remove(report_name + "." + ext)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % (report_name + "." + ext))
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
(report_name + "." + ext))
|
||||||
return text in contents
|
return text in contents
|
||||||
return test_output_file
|
return test_output_file
|
||||||
|
|
||||||
|
|
||||||
def err_does_not_contain(text):
|
def err_does_not_contain(text):
|
||||||
def test_output_file(out, err, report_name, **options):
|
def test_output_file(dummy, err, report_name, **options):
|
||||||
if options.get("files", []):
|
if options.get("files", []):
|
||||||
for filename in options.get("files", []):
|
for filename in options.get("files", []):
|
||||||
if filename is None:
|
if filename is None:
|
||||||
@@ -154,18 +163,21 @@ def err_does_not_contain(text):
|
|||||||
elif os.path.isfile(filename):
|
elif os.path.isfile(filename):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % filename)
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
filename)
|
||||||
else:
|
else:
|
||||||
ext = options["off"]
|
ext = options["off"]
|
||||||
if os.path.isfile(report_name + "." + ext):
|
if os.path.isfile(report_name + "." + ext):
|
||||||
os.remove(report_name + "." + ext)
|
os.remove(report_name + "." + ext)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % (report_name + "." + ext))
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
(report_name + "." + ext))
|
||||||
return text not in err
|
return text not in err
|
||||||
return test_output_file
|
return test_output_file
|
||||||
|
|
||||||
|
|
||||||
def err_does_contain(text):
|
def err_does_contain(text):
|
||||||
def test_output_file(out, err, report_name, **options):
|
def test_output_file(dummy, err, report_name, **options):
|
||||||
if options.get("files", []):
|
if options.get("files", []):
|
||||||
for filename in options.get("files", []):
|
for filename in options.get("files", []):
|
||||||
if filename is None:
|
if filename is None:
|
||||||
@@ -175,21 +187,24 @@ def err_does_contain(text):
|
|||||||
elif os.path.isfile(filename):
|
elif os.path.isfile(filename):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % filename)
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
filename)
|
||||||
else:
|
else:
|
||||||
ext = options["off"]
|
ext = options["off"]
|
||||||
if os.path.isfile(report_name + "." + ext):
|
if os.path.isfile(report_name + "." + ext):
|
||||||
os.remove(report_name + "." + ext)
|
os.remove(report_name + "." + ext)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % (report_name + "." + ext))
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
(report_name + "." + ext))
|
||||||
if isinstance(text, list):
|
if isinstance(text, list):
|
||||||
return all([(line in err) for line in text])
|
return all([(line in err) for line in text])
|
||||||
else:
|
else:
|
||||||
return text in err
|
return text in err
|
||||||
return test_output_file
|
return test_output_file
|
||||||
|
|
||||||
|
|
||||||
def out_does_contain(text):
|
def out_does_contain(text):
|
||||||
def test_output_file(out, err, report_name, **options):
|
def test_output_file(out, dummy, report_name, **options):
|
||||||
if options.get("files", []):
|
if options.get("files", []):
|
||||||
for filename in options.get("files", []):
|
for filename in options.get("files", []):
|
||||||
if filename is None:
|
if filename is None:
|
||||||
@@ -199,13 +214,15 @@ def out_does_contain(text):
|
|||||||
elif os.path.isfile(filename):
|
elif os.path.isfile(filename):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % filename)
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
filename)
|
||||||
else:
|
else:
|
||||||
ext = options["off"]
|
ext = options["off"]
|
||||||
if os.path.isfile(report_name + "." + ext):
|
if os.path.isfile(report_name + "." + ext):
|
||||||
os.remove(report_name + "." + ext)
|
os.remove(report_name + "." + ext)
|
||||||
else:
|
else:
|
||||||
raise Exception("can't find '%s' in order to delete it" % (report_name + "." + ext))
|
raise Exception("can't find '%s' in order to delete it" %
|
||||||
|
(report_name + "." + ext))
|
||||||
if isinstance(text, list):
|
if isinstance(text, list):
|
||||||
return all([(line in out) for line in text])
|
return all([(line in out) for line in text])
|
||||||
else:
|
else:
|
||||||
@@ -305,31 +322,30 @@ report_list = [
|
|||||||
("endofline_report", "txt", []), # End of Line Report
|
("endofline_report", "txt", []), # End of Line Report
|
||||||
("family_descend_chart", "svg", []), # Family Descendant Tree
|
("family_descend_chart", "svg", []), # Family Descendant Tree
|
||||||
("family_group", "txt", []), # Family Group Report
|
("family_group", "txt", []), # Family Group Report
|
||||||
## COULD be dot ("familylines_graph", "dot", []), # Family Lines Graph
|
# COULD be dot ("familylines_graph", "dot", []), # Family Lines Graph
|
||||||
("fan_chart", "svg", []), # Fan Chart
|
("fan_chart", "svg", []), # Fan Chart
|
||||||
## COULD be dot ("hourglass_graph", "dot", []), # Hourglass Graph
|
# COULD be dot ("hourglass_graph", "dot", []), # Hourglass Graph
|
||||||
("indiv_complete", "txt", []), # Complete Individual Report
|
("indiv_complete", "txt", []), # Complete Individual Report
|
||||||
("kinship_report", "txt", []), # Kinship Report
|
("kinship_report", "txt", []), # Kinship Report
|
||||||
("notelinkreport", "txt", []), # Note Link Report
|
("notelinkreport", "txt", []), # Note Link Report
|
||||||
("number_of_ancestors", "txt", []), # Number of Ancestors Report
|
("number_of_ancestors", "txt", []), # Number of Ancestors Report
|
||||||
## NEED a place ("place_report", "txt", []), # Place Report
|
# NEED a place ("place_report", "txt", []), # Place Report
|
||||||
("records", "txt", []), # Records Report
|
("records", "txt", []), # Records Report
|
||||||
## COULD be dot ("rel_graph", "dot", []), # Relationship Graph
|
# COULD be dot ("rel_graph", "dot", []), # Relationship Graph
|
||||||
("statistics_chart", "svg", ["statistics_chart.svg",
|
("statistics_chart", "svg", ["statistics_chart.svg", # Statistics Charts
|
||||||
"statistics_chart-2.svg",
|
"statistics_chart-2.svg",
|
||||||
"statistics_chart-3.svg"]), # Statistics Charts
|
"statistics_chart-3.svg"]),
|
||||||
("summary", "txt", []), # Database Summary Report
|
("summary", "txt", []), # Database Summary Report
|
||||||
("timeline", "svg", ["timeline.svg", "timeline-2.svg"]), # Timeline Chart
|
("timeline", "svg", ["timeline.svg", "timeline-2.svg"]), # Timeline Chart
|
||||||
]
|
]
|
||||||
|
|
||||||
for (report_name, off, files) in report_list:
|
for (_report_name, _off, _files) in report_list:
|
||||||
reports.addreport(TestDynamic, report_name,
|
reports.addreport(TestDynamic, _report_name,
|
||||||
err_does_not_contain("Failed to write report."),
|
err_does_not_contain("Failed to write report."),
|
||||||
files=files,
|
files=_files,
|
||||||
off=off)
|
off=_off)
|
||||||
|
|
||||||
reports.addcli(TestDynamic, "tool_verify",
|
txt_list = [
|
||||||
out_does_contain([
|
|
||||||
"W: Early marriage, Family: F0000, Smith, Martin and Jefferson, Elna",
|
"W: Early marriage, Family: F0000, Smith, Martin and Jefferson, Elna",
|
||||||
"W: Multiple parents, Person: I0061, Jones, Roberta Michele",
|
"W: Multiple parents, Person: I0061, Jones, Roberta Michele",
|
||||||
"W: Multiple parents, Person: I0063, Jones, Frank Albert",
|
"W: Multiple parents, Person: I0063, Jones, Frank Albert",
|
||||||
@@ -339,8 +355,9 @@ reports.addcli(TestDynamic, "tool_verify",
|
|||||||
"W: Old age but no death, Person: I0009, Smith, Emil",
|
"W: Old age but no death, Person: I0009, Smith, Emil",
|
||||||
"W: Old age but no death, Person: I0011, Smith, Hanna",
|
"W: Old age but no death, Person: I0011, Smith, Hanna",
|
||||||
"W: Old age but no death, Person: I0058, Smith, Elaine Marie",
|
"W: Old age but no death, Person: I0058, Smith, Elaine Marie",
|
||||||
"W: Old age but no death, Person: I0072, Iverson, Alice Hannah",
|
"W: Old age but no death, Person: I0072, Iverson, Alice Hannah", ]
|
||||||
]),
|
reports.addcli(TestDynamic, "tool_verify",
|
||||||
|
out_does_contain(txt_list),
|
||||||
[None],
|
[None],
|
||||||
"--force",
|
"--force",
|
||||||
"-O", TREE_NAME,
|
"-O", TREE_NAME,
|
||||||
@@ -348,9 +365,10 @@ reports.addcli(TestDynamic, "tool_verify",
|
|||||||
"--action", "tool",
|
"--action", "tool",
|
||||||
"--options", "name=verify")
|
"--options", "name=verify")
|
||||||
|
|
||||||
|
txt_list = ["6 media objects were referenced, but not found",
|
||||||
|
"References to 6 media objects were kept"]
|
||||||
reports.addcli(TestDynamic, "tool_check",
|
reports.addcli(TestDynamic, "tool_check",
|
||||||
out_does_contain(["6 media objects were referenced, but not found",
|
out_does_contain(txt_list),
|
||||||
"References to 6 media objects were kept"]),
|
|
||||||
[None],
|
[None],
|
||||||
"--force",
|
"--force",
|
||||||
"-O", TREE_NAME,
|
"-O", TREE_NAME,
|
||||||
|
Reference in New Issue
Block a user