def test_to_dict(self): category_list = query_category.QueryCategoryList() category_list.extend([ query_category.QueryCategory("llq.id", "Id", "Job Step Id", record_parser.DetailLabelParser, ("Job Step Id", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.owner", "Owner", "Owner", record_parser.DetailLabelParser, ("Owner", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.queue_full_date", "Queue Date", "Queue Date", record_parser.DetailLabelParser, ("Queue Date", ), value_saver.FullDateSaver, ()), query_category.QueryCategory("llq.status", "Status", "Status", record_parser.DetailLabelParser, ("Status", ), value_saver.JobStatusSaver, ()) ]) test_case_list = list() nwp_output = os.path.join( os.path.dirname(__file__), "../data/detail_query/llq/llq.detail.query.output.nwp.txt") with open(nwp_output) as nwp_output_file: lines = nwp_output_file.readlines() model = query_model.LoadLevelerQueryModel.build_from_category_list( lines, category_list) model_dict = model.to_dict() self.assertTrue('items' in model_dict) self.assertEqual(len(model_dict['items']), 3)
def setUp(self): self.category_list = query_category.QueryCategoryList() self.category_list.extend([ query_category.QueryCategory("llq.id", "Id", "Job Step Id", record_parser.DetailLabelParser, ("Job Step Id", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.owner", "Owner", "Owner", record_parser.DetailLabelParser, ("Owner", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.queue_full_date", "Queue Date", "Queue Date", record_parser.DetailLabelParser, ("Queue Date", ), value_saver.FullDateSaver, ()), query_category.QueryCategory("llq.job_script", "Job Script", "Cmd", record_parser.DetailLabelParser, ("Cmd", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.status", "Status", "Status", record_parser.DetailLabelParser, ("Status", ), value_saver.JobStatusSaver, ()) ])
def test_to_dict(self): category_list = query_category.QueryCategoryList() category_list.extend([ query_category.QueryCategory("llq.id", "Id", "Job Step Id", record_parser.DetailLabelParser, ("Job Step Id", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.owner", "Owner", "Owner", record_parser.DetailLabelParser, ("Owner", ), value_saver.StringSaver, ()), ]) serial_job_running_file_path = os.path.join( os.path.dirname(__file__), "../data/detail_query/llq/serial_job_running.txt") with open(serial_job_running_file_path) as serial_job_running_file: record = serial_job_running_file.readlines() item = query_item.QueryItem.build_from_category_list( record, category_list) item_dict = item.to_dict() self.assertTrue('props' in item_dict) self.assertIsInstance(item_dict['props'], list) self.assertEqual(len(item_dict['props']), 2)
def test_build_model(self): check_method = self.check_build_model category_list = query_category.QueryCategoryList() category_list.extend([ query_category.QueryCategory("llclass.name", "Name", "Name", record_parser.DetailLabelParser, ("Name", ), value_saver.StringSaver, ()), query_category.QueryCategory("llclass.free_slots", "Free Slots", "Free_slots", record_parser.DetailLabelParser, ("Free_slots", ), value_saver.NumberSaver, ()), query_category.QueryCategory("llclass.maximum_slots", "Maximum Slots", "Maximum_slots", record_parser.DetailLabelParser, ("Maximum_slots", ), value_saver.NumberSaver, ()) ]) test_case_list = list() nwp_output = os.path.join( os.path.dirname(__file__), "../data/detail_query/llclass/operation.txt") with open(nwp_output) as nwp_output_file: record = nwp_output_file.readlines() test_case_list.append({ 'record': record, 'category_list': category_list, 'records': [{ 'index': 0, 'properties': [{ 'category_id': 'llclass.name', 'text': 'operation' }, { 'category_id': 'llclass.free_slots', 'text': '384' }, { 'category_id': 'llclass.maximum_slots', 'text': '2560' }] }] }) for a_test_case in test_case_list: check_method(a_test_case)
def test_llq_detail_category_list(self): category_list = query_category.QueryCategoryList() category_list.extend([ query_category.QueryCategory("llq.id", "Id", "Job Step Id", record_parser.DetailLabelParser, ("Job Step Id", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.owner", "Owner", "Owner", record_parser.DetailLabelParser, ("Owner", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.class", "Class", "Class", record_parser.DetailLabelParser, ("Class", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.job_script", "Job Script", "Cmd", record_parser.DetailLabelParser, ("Cmd", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.status", "Status", "Status", record_parser.DetailLabelParser, ("Status", ), value_saver.JobStatusSaver, ()) ]) assert len(category_list) == 5 assert category_list.index_from_id("llq.id") == 0 with pytest.raises(ValueError): category_list.index_from_id("llclass.id") assert category_list.contains_id("llq.id") assert not category_list.contains_id("llclass.id") assert category_list.category_from_id("llq.id").id == "llq.id" assert category_list.category_from_id("llclass.id") is None assert category_list.index_from_label("Class") == 2 assert category_list.contains_label("Class") assert category_list.category_from_label("Class").id == "llq.class"
def test_deep_copy(self): category = query_category.QueryCategory() category.id = "llq.id" category.record_parser = record_parser.DetailLabelParser("Job Step Id") category.value_saver = value_saver.StringSaver() new_category = copy.deepcopy(category) new_category.id = "llq.submitted" new_category.record_parser.label = "Submitted" assert category.id != new_category.id assert category.record_parser is not new_category.record_parser assert category.record_parser.label is not new_category.record_parser.label
def test_create_query_category(self): id_category = query_category.QueryCategory( category_id="llq.id", display_name="Id", label="Job Step Id", record_parser_class=record_parser.DetailLabelParser, record_parser_arguments=("Job Step Id", ), value_saver_class=value_saver.StringSaver) assert id_category.id == "llq.id" assert id_category.display_name == "Id" assert id_category.label == "Job Step Id" assert isinstance(id_category.record_parser, record_parser.DetailLabelParser) assert id_category.record_parser.label == "Job Step Id" assert isinstance(id_category.value_saver, value_saver.StringSaver)
def test_build_model(self): check_method = self.check_build_model category_list = query_category.QueryCategoryList() category_list.extend([ query_category.QueryCategory("llq.id", "Id", "Job Step Id", record_parser.DetailLabelParser, ("Job Step Id", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.owner", "Owner", "Owner", record_parser.DetailLabelParser, ("Owner", ), value_saver.StringSaver, ()), query_category.QueryCategory("llq.queue_full_date", "Queue Date", "Queue Date", record_parser.DetailLabelParser, ("Queue Date", ), value_saver.FullDateSaver, ()), query_category.QueryCategory("llq.status", "Status", "Status", record_parser.DetailLabelParser, ("Status", ), value_saver.JobStatusSaver, ()) ]) test_case_list = list() nwp_output = os.path.join( os.path.dirname(__file__), "../data/detail_query/llq/llq.detail.query.output.nwp.txt") with open(nwp_output) as nwp_output_file: record = nwp_output_file.readlines() test_case_list.append({ 'record': record, 'category_list': category_list, 'records': [{ 'index': 0, 'properties': [{ 'category_id': 'llq.id', 'text': 'cma20n04.3473800.0' }, { 'category_id': 'llq.status', 'text': 'R' }] }, { 'index': 1, 'properties': [{ 'category_id': 'llq.id', 'text': 'cma19n04.3473768.0' }, { 'category_id': 'llq.status', 'text': 'R' }] }] }) for a_test_case in test_case_list: check_method(a_test_case)