diff --git a/bin/test_report b/bin/test_report index 0899d2f..10138bb 100755 --- a/bin/test_report +++ b/bin/test_report @@ -2,30 +2,44 @@ import yaml import unittest + +def generate_test(test_type, test_data): + def test_method(self): + test_function = getattr(self, test_type) + if isinstance(test_data, list): + test_function(*test_data) + else: + test_function(test_data) + return test_method + + class TestReport(unittest.TestCase): - def test_report(self): - try: - with open("/tmp/flexbe_app_report.log", 'r') as f: - report = yaml.load(f) - except IOError: - return # skip test since there is no report to evaluate - for test_type, tests in report.items(): - for test_name, test_data in tests.items(): - if test_type == "assertTrue": - self.assertTrue(test_data, test_name) - - def test_behavior_report(self): - try: - with open("/tmp/flexbe_app_behavior_report.log", 'r') as f: - report = yaml.safe_load(f) - except IOError: - return # skip test since there is no report to evaluate - for test_type, tests in report.items(): - for test_name, test_data in tests.items(): - if test_type == "assertTrue": - self.assertTrue(test_data, test_name) + def test_report(self): + try: + with open("/tmp/flexbe_app_report.log", 'r') as f: + report = yaml.load(f) + except IOError: + return # skip test since there is no report to evaluate + for test_type, tests in report.items(): + for test_name, test_data in tests.items(): + if test_type == "assertTrue": + self.assertTrue(test_data, test_name) + if __name__ == '__main__': - import rosunit - rosunit.unitrun("flexbe_app", "test_report", TestReport) + try: + with open("/tmp/flexbe_app_behavior_report.log", 'r') as f: + report = yaml.safe_load(f) + except IOError: + pass # add no tests because there is no report to evaluate + else: + for test_type, tests in report.items(): + for test_name, test_data in tests.items(): + function_name = "test_%s_%s" % (test_name, test_type) + test_function = generate_test(test_type, test_data) + test_function.__name__ = function_name + setattr(TestReport, function_name, test_function) + + import rosunit + rosunit.unitrun("flexbe_app", "test_report", TestReport) diff --git a/src/_test/checkbehaviorsreport.js b/src/_test/checkbehaviorsreport.js index 17994d3..2c25af9 100644 --- a/src/_test/checkbehaviorsreport.js +++ b/src/_test/checkbehaviorsreport.js @@ -15,7 +15,7 @@ CheckBehaviorsReport = new (function() { IO.BehaviorLoader.loadBehavior(m, function(error_string) { console.log(error_string); if (error_string != undefined) { - report.assertTrue["behavior_"+behavior] = false; + report.assertTrue["behavior_"+behavior] = [false, error_string]; console.log(behavior+" is false"); } else{