def test_report_generate_nsb_simple(self, *args): tmpfile = tempfile.NamedTemporaryFile(delete=True) args = core.Param({"task_id": [GOOD_TASK_ID], "yaml_name": [GOOD_YAML_NAME]}) params = change_osloobj_to_paras(args) with mock.patch.object(report.consts, 'DEFAULT_HTML_FILE', tmpfile.name): report.Report().generate_nsb(params) data_act = None time_act = None keys_act = None tree_act = None with open(tmpfile.name) as f: for l in f.readlines(): if "var report_data = {" in l: data_act = ast.literal_eval(l.strip()[18:-1]) elif "var report_time = [" in l: time_act = ast.literal_eval(l.strip()[18:-1]) elif "var report_keys = [" in l: keys_act = ast.literal_eval(l.strip()[18:-1]) elif "var report_tree = [" in l: tree_act = ast.literal_eval(l.strip()[18:-1]) data_exp = { 'metric1': [1, 1, 2, 3, 5, 8], 'metric2': [0, 1, 2, 3, 4, 5], 'metric3': [8, 5, 3, 2, 1, 1], 'metric4': [5, 4, 3, 2, 1, 0], } time_exp = [ '16:49:26.372662', '16:49:27.374208', '16:49:28.375742', '16:49:29.377299', '16:49:30.378252', '16:49:30.379359', ] keys_exp = [ 'metric1', 'metric2', 'metric3', 'metric4', ] tree_exp = [ {'parent': '#', 'text': 'metric1', 'id': 'metric1'}, {'parent': '#', 'text': 'metric2', 'id': 'metric2'}, {'parent': '#', 'text': 'metric3', 'id': 'metric3'}, {'parent': '#', 'text': 'metric4', 'id': 'metric4'}, ] self.assertEqual(data_exp, data_act) self.assertEqual(time_exp, time_act) self.assertEqual(keys_exp, keys_act) self.assertEqual(tree_exp, tree_act)
def test_report_generate_nsb_simple(self, *args): tmpfile = tempfile.NamedTemporaryFile(delete=True) args = core.Param({ "task_id": [GOOD_TASK_ID], "yaml_name": [GOOD_YAML_NAME] }) params = change_osloobj_to_paras(args) with mock.patch.object(report.consts, 'DEFAULT_HTML_FILE', tmpfile.name): report.Report().generate_nsb(params) data_act = None time_act = None keys_act = None tree_act = None with open(tmpfile.name) as f: for l in f.readlines(): if "var report_data = {" in l: data_act = ast.literal_eval(l.strip()[18:-1]) elif "var report_time = [" in l: time_act = ast.literal_eval(l.strip()[18:-1]) elif "var report_keys = [" in l: keys_act = ast.literal_eval(l.strip()[18:-1]) elif "var report_tree = [" in l: tree_act = ast.literal_eval(l.strip()[18:-1]) data_exp = { 'metric1': [{ 'x': '16:49:26.372662', 'y': 1 }, { 'x': '16:49:27.374208', 'y': 1 }, { 'x': '16:49:28.375742', 'y': 2 }, { 'x': '16:49:29.377299', 'y': 3 }, { 'x': '16:49:30.378252', 'y': 5 }, { 'x': '16:49:30.379359', 'y': 8 }], 'metric2': [{ 'x': '16:49:26.372662', 'y': 0 }, { 'x': '16:49:27.374208', 'y': 1 }, { 'x': '16:49:28.375742', 'y': 2 }, { 'x': '16:49:29.377299', 'y': 3 }, { 'x': '16:49:30.378252', 'y': 4 }, { 'x': '16:49:30.379359', 'y': 5 }], 'metric3': [{ 'x': '16:49:26.372662', 'y': 8 }, { 'x': '16:49:27.374208', 'y': 5 }, { 'x': '16:49:28.375742', 'y': 3 }, { 'x': '16:49:29.377299', 'y': 2 }, { 'x': '16:49:30.378252', 'y': 1 }, { 'x': '16:49:30.379359', 'y': 1 }], 'metric4': [{ 'x': '16:49:26.372662', 'y': 5 }, { 'x': '16:49:27.374208', 'y': 4 }, { 'x': '16:49:28.375742', 'y': 3 }, { 'x': '16:49:29.377299', 'y': 2 }, { 'x': '16:49:30.378252', 'y': 1 }, { 'x': '16:49:30.379359', 'y': 0 }], 'myhostname.cpu_value.cpu.system.0': [{ 'x': '16:49:27.3837', 'y': 193798 }, { 'x': '16:49:28.3837', 'y': 193800 }, { 'x': '16:49:29.3837', 'y': 193801 }], 'myhostname.cpu_value.cpu.user.0': [{ 'x': '16:49:27.3836', 'y': 324050 }, { 'x': '16:49:28.3836', 'y': 324051 }, { 'x': '16:49:29.3836', 'y': 324054 }], 'myhostname.cpufreq_value.cpu.system.0': [{ 'x': '16:49:27.3837', 'y': 193798 }, { 'x': '16:49:28.3837', 'y': 193800 }, { 'x': '16:49:29.3837', 'y': 193801 }], 'myhostname.cpufreq_value.cpu.user.0': [{ 'x': '16:49:27.3836', 'y': 324050 }, { 'x': '16:49:28.3836', 'y': 324051 }, { 'x': '16:49:29.3836', 'y': 324054 }], 'myhostname.intel_pmu_value.cpu.system.0': [{ 'x': '16:49:27.3837', 'y': 193798 }, { 'x': '16:49:28.3837', 'y': 193800 }, { 'x': '16:49:29.3837', 'y': 193801 }], 'myhostname.intel_pmu_value.cpu.user.0': [{ 'x': '16:49:27.3836', 'y': 324050 }, { 'x': '16:49:28.3836', 'y': 324051 }, { 'x': '16:49:29.3836', 'y': 324054 }], 'myhostname.virt_value.cpu.system.0': [{ 'x': '16:49:27.3837', 'y': 193798 }, { 'x': '16:49:28.3837', 'y': 193800 }, { 'x': '16:49:29.3837', 'y': 193801 }], 'myhostname.virt_value.cpu.user.0': [{ 'x': '16:49:27.3836', 'y': 324050 }, { 'x': '16:49:28.3836', 'y': 324051 }, { 'x': '16:49:29.3836', 'y': 324054 }], 'myhostname.memory_value.cpu.system.0': [{ 'x': '16:49:27.3837', 'y': 193798 }, { 'x': '16:49:28.3837', 'y': 193800 }, { 'x': '16:49:29.3837', 'y': 193801 }], 'myhostname.memory_value.cpu.user.0': [{ 'x': '16:49:27.3836', 'y': 324050 }, { 'x': '16:49:28.3836', 'y': 324051 }, { 'x': '16:49:29.3836', 'y': 324054 }] } time_exp = [ '16:49:26.372662', '16:49:27.374208', '16:49:27.3836', '16:49:27.3837', '16:49:28.375742', '16:49:28.3836', '16:49:28.3837', '16:49:29.377299', '16:49:29.3836', '16:49:29.3837', '16:49:30.378252', '16:49:30.379359', ] keys_exp = sorted([ 'metric1', 'metric2', 'metric3', 'metric4', 'myhostname.cpu_value.cpu.system.0', 'myhostname.cpu_value.cpu.user.0', 'myhostname.cpufreq_value.cpu.system.0', 'myhostname.cpufreq_value.cpu.user.0', 'myhostname.intel_pmu_value.cpu.system.0', 'myhostname.intel_pmu_value.cpu.user.0', 'myhostname.virt_value.cpu.system.0', 'myhostname.virt_value.cpu.user.0', 'myhostname.memory_value.cpu.system.0', 'myhostname.memory_value.cpu.user.0', ]) tree_exp = [{ 'parent': '#', 'text': 'metric1', 'id': 'metric1' }, { 'parent': '#', 'text': 'metric2', 'id': 'metric2' }, { 'parent': '#', 'text': 'metric3', 'id': 'metric3' }, { 'parent': '#', 'text': 'metric4', 'id': 'metric4' }, { 'id': 'myhostname', 'parent': '#', 'text': 'myhostname' }, { 'id': 'myhostname.cpu_value', 'parent': 'myhostname', 'text': 'cpu_value' }, { 'id': 'myhostname.cpu_value.cpu', 'parent': 'myhostname.cpu_value', 'text': 'cpu' }, { 'id': 'myhostname.cpu_value.cpu.system', 'parent': 'myhostname.cpu_value.cpu', 'text': 'system' }, { 'id': 'myhostname.cpu_value.cpu.system.0', 'parent': 'myhostname.cpu_value.cpu.system', 'text': '0' }, { 'id': 'myhostname.cpu_value.cpu.user', 'parent': 'myhostname.cpu_value.cpu', 'text': 'user' }, { 'id': 'myhostname.cpu_value.cpu.user.0', 'parent': 'myhostname.cpu_value.cpu.user', 'text': '0' }, { 'id': 'myhostname.cpufreq_value', 'parent': 'myhostname', 'text': 'cpufreq_value' }, { 'id': 'myhostname.cpufreq_value.cpu', 'parent': 'myhostname.cpufreq_value', 'text': 'cpu' }, { 'id': 'myhostname.cpufreq_value.cpu.system', 'parent': 'myhostname.cpufreq_value.cpu', 'text': 'system' }, { 'id': 'myhostname.cpufreq_value.cpu.system.0', 'parent': 'myhostname.cpufreq_value.cpu.system', 'text': '0' }, { 'id': 'myhostname.cpufreq_value.cpu.user', 'parent': 'myhostname.cpufreq_value.cpu', 'text': 'user' }, { 'id': 'myhostname.cpufreq_value.cpu.user.0', 'parent': 'myhostname.cpufreq_value.cpu.user', 'text': '0' }, { 'id': 'myhostname.intel_pmu_value', 'parent': 'myhostname', 'text': 'intel_pmu_value' }, { 'id': 'myhostname.intel_pmu_value.cpu', 'parent': 'myhostname.intel_pmu_value', 'text': 'cpu' }, { 'id': 'myhostname.intel_pmu_value.cpu.system', 'parent': 'myhostname.intel_pmu_value.cpu', 'text': 'system' }, { 'id': 'myhostname.intel_pmu_value.cpu.system.0', 'parent': 'myhostname.intel_pmu_value.cpu.system', 'text': '0' }, { 'id': 'myhostname.intel_pmu_value.cpu.user', 'parent': 'myhostname.intel_pmu_value.cpu', 'text': 'user' }, { 'id': 'myhostname.intel_pmu_value.cpu.user.0', 'parent': 'myhostname.intel_pmu_value.cpu.user', 'text': '0' }, { 'id': 'myhostname.memory_value', 'parent': 'myhostname', 'text': 'memory_value' }, { 'id': 'myhostname.memory_value.cpu', 'parent': 'myhostname.memory_value', 'text': 'cpu' }, { 'id': 'myhostname.memory_value.cpu.system', 'parent': 'myhostname.memory_value.cpu', 'text': 'system' }, { 'id': 'myhostname.memory_value.cpu.system.0', 'parent': 'myhostname.memory_value.cpu.system', 'text': '0' }, { 'id': 'myhostname.memory_value.cpu.user', 'parent': 'myhostname.memory_value.cpu', 'text': 'user' }, { 'id': 'myhostname.memory_value.cpu.user.0', 'parent': 'myhostname.memory_value.cpu.user', 'text': '0' }, { 'id': 'myhostname.virt_value', 'parent': 'myhostname', 'text': 'virt_value' }, { 'id': 'myhostname.virt_value.cpu', 'parent': 'myhostname.virt_value', 'text': 'cpu' }, { 'id': 'myhostname.virt_value.cpu.system', 'parent': 'myhostname.virt_value.cpu', 'text': 'system' }, { 'id': 'myhostname.virt_value.cpu.system.0', 'parent': 'myhostname.virt_value.cpu.system', 'text': '0' }, { 'id': 'myhostname.virt_value.cpu.user', 'parent': 'myhostname.virt_value.cpu', 'text': 'user' }, { 'id': 'myhostname.virt_value.cpu.user.0', 'parent': 'myhostname.virt_value.cpu.user', 'text': '0' }] self.assertEqual(data_exp, data_act) self.assertEqual(time_exp, time_act) self.assertEqual(keys_exp, keys_act) self.assertEqual(tree_exp, tree_act)
def setUp(self): super(ReportTestCase, self).setUp() self.param = change_osloobj_to_paras({}) self.param.yaml_name = [FAKE_YAML_NAME] self.param.task_id = [FAKE_TASK_ID] self.rep = report.Report()
def do_generate_nsb(self, args): """Generate a report using the NSB template.""" param = change_osloobj_to_paras(args) report.Report().generate_nsb(param)
def do_generate(self, args): """Generate a report.""" param = change_osloobj_to_paras(args) report.Report().generate(param)