def test_to_xml_description(self): tt1 = DEFINE.TranslatedText(_content="this is the first test description", lang="en") tt2 = DEFINE.TranslatedText(_content="this is the second test description", lang="en") desc = DEFINE.Description() desc.TranslatedText = [tt1, tt2] desc_xml = desc.to_xml() tts = desc_xml.findall("TranslatedText") self.assertEqual(tts[0].text, "this is the first test description")
def test_add_description(self): tt1 = DEFINE.TranslatedText(_content="Age at Screening Date (Screening Date - Birth date)", lang="en") tt2 = DEFINE.TranslatedText(_content="For the complete algorithm see the referenced external document.", lang="fr") self.methoddef.Description = DEFINE.Description() self.methoddef.Description.TranslatedText = [tt1, tt2] self.assertEqual(len(self.methoddef.Description.TranslatedText), 2) self.assertEqual(self.methoddef.Description.TranslatedText[1]._content, 'For the complete algorithm see the referenced external document.')
def test_add_description(self): attrs = {"_content": "this is the first test description", "lang": "en"} tt1 = DEFINE.TranslatedText(**attrs) attrs = {"_content": "this is the second test description", "lang": "en"} tt2 = DEFINE.TranslatedText(**attrs) self.item.Description.TranslatedText.append(tt1) self.item.Description.TranslatedText.append(tt2) self.assertEqual(self.item.Description.TranslatedText[1]._content, "this is the second test description")
def test_to_dict_description(self): tt1 = DEFINE.TranslatedText(_content="this is the first test description", lang="en") tt2 = DEFINE.TranslatedText(_content="this is the second test description", lang="en") desc = DEFINE.Description() desc.TranslatedText = [tt1, tt2] desc_dict = desc.to_dict() print(desc_dict) self.assertDictEqual(desc_dict["TranslatedText"][1], {'_content': 'this is the second test description', 'lang': 'en'})
def test_to_json(self): attrs = self.set_item_attributes() item = DEFINE.ItemDef(**attrs) item.Description.TranslatedText.append(DEFINE.TranslatedText(_content="this is the first test description", lang="en")) item.Question.TranslatedText = [DEFINE.TranslatedText(_content="Any AEs?", lang="en")] item.CodeListRef = DEFINE.CodeListRef(CodeListOID="CL.NY_SUB_Y_N_2011-10-24") item_json = item.to_json() item_dict = json.loads(item_json) self.assertEqual(item_dict["OID"], "ODM.IT.AE.AEYN")
def test_add_description(self): tt1 = DEFINE.TranslatedText( _content="this is the first test description", lang="en") tt2 = DEFINE.TranslatedText( _content="this is the second test description", lang="en") self.igd.Description = DEFINE.Description() self.igd.Description.TranslatedText = [tt1, tt2] self.assertEqual(len(self.igd.Description.TranslatedText), 2) self.assertEqual(self.igd.Description.TranslatedText[1]._content, 'this is the second test description')
def test_to_dict(self): attrs = self.set_item_attributes() item = DEFINE.ItemDef(**attrs) item.Description.TranslatedText = [DEFINE.TranslatedText(_content="this is the first test description", lang="en")] item.Question.TranslatedText = [DEFINE.TranslatedText(_content="Any AEs?", lang="en")] item.CodeListRef = DEFINE.CodeListRef(CodeListOID="CL.NY_SUB_Y_N_2011-10-24") item_dict = item.to_dict() expected_dict = {'OID': 'ODM.IT.AE.AEYN', 'Name': 'Any AEs?', 'DataType': 'text', 'Length': 1, 'SASFieldName': 'AEYN', "CommentOID": "ODM.CO.120", 'Description': {'TranslatedText': [{'_content': 'this is the first test description', 'lang': 'en'}]}, 'Question': {'TranslatedText': [{'_content': 'Any AEs?', 'lang': 'en'}]}, 'CodeListRef': {'CodeListOID': 'CL.NY_SUB_Y_N_2011-10-24'}} self.assertDictEqual(item_dict, expected_dict)
def test_comment_def(self): comment = DEFINE.CommentDef(OID="COM.VS.VISITNUM") comment.Description.TranslatedText.append( DEFINE.TranslatedText( _content="Assigned from the TV domain based on the VISIT", lang="en")) self.assertEqual("COM.VS.VISITNUM", comment.OID)
def test_add_value_list_ref(self): vlr = DEFINE.ValueListRef(ValueListOID="VL.DA.DAORRES") attrs = {"OID": "IT.DA.DAORRES", "Name": "DAORRES", "DataType": "text", "Length": "2", "SASFieldName": "DAORRES"} itd = DEFINE.ItemDef(**attrs) tt1 = DEFINE.TranslatedText(_content="Assessment Result in Original Units", lang="en") desc = DEFINE.Description() desc.TranslatedText.append(tt1) itd.Description = desc itd.ValueListRef = vlr self.assertEqual(itd.ValueListRef.ValueListOID, "VL.DA.DAORRES") self.assertEqual(itd.OID, "IT.DA.DAORRES")
def test_to_dict(self): attrs = self.set_attributes() method = DEFINE.MethodDef(**attrs) desc = DEFINE.Description() tt1 = DEFINE.TranslatedText(_content="Age at Screening Date (Screening Date - Birth date)", lang="en") desc.TranslatedText = [tt1] method.Description = desc fex = DEFINE.FormalExpression(Context="Python 3.7", _content="print('hello world')") method.FormalExpression = [fex] method_dict = method.to_dict() self.assertEqual(method_dict["OID"], "ODM.MT.AGE") self.assertDictEqual(method_dict, self.expected_dict())
def test_to_xml(self): attrs = self.set_item_attributes() item = DEFINE.ItemDef(**attrs) item.Description.TranslatedText = [DEFINE.TranslatedText(_content="this is the first test description", lang="en")] item.CodeListRef = DEFINE.CodeListRef(CodeListOID="CL.NY_SUB_Y_N_2011-10-24") item.RangeCheck = [DEFINE.RangeCheck(Comparator="EQ", SoftHard="Soft", ItemOID="IT.DA.DAORRES")] item.RangeCheck[0].CheckValue = [DEFINE.CheckValue(_content="DIABP")] item_xml = item.to_xml() self.assertEqual(item_xml.attrib["OID"], "ODM.IT.AE.AEYN") cv = item_xml.find("*/CheckValue") self.assertEqual(cv.text, "DIABP") dt = item_xml.findall("Description/TranslatedText") self.assertEqual(len(dt), 1)
def test_itemgroupdef_iterator(self): """ test the ability to reference a specific or slice of ItemRefs """ attrs = self.set_itemgroupdef_attributes() igd = DEFINE.ItemGroupDef(**attrs) tt = DEFINE.TranslatedText(_content="Vital Signs", lang="en") igd.Description = DEFINE.Description() igd.Description.TranslatedText = [tt] item_refs = self.set_itemrefs() igd.ItemRef = item_refs parser = ODM_PARSER.ODMParser(self.test_file, self.nsr) parser.parse() parser.MetaDataVersion() irs = [ir.ItemOID for ir in igd] self.assertEqual(len(irs), 10)
def test_itemgroupdef_slice(self): """ test the ability to reference a specific or slice of ItemRefs """ attrs = self.set_itemgroupdef_attributes() igd = DEFINE.ItemGroupDef(**attrs) tt = DEFINE.TranslatedText(_content="Vital Signs", lang="en") igd.Description = DEFINE.Description() igd.Description.TranslatedText = [tt] item_refs = self.set_itemrefs() igd.ItemRef = item_refs parser = ODM_PARSER.ODMParser(self.test_file, self.nsr) parser.parse() parser.MetaDataVersion() self.assertEqual(len(igd), 10) self.assertEqual(igd.ItemRef[0].ItemOID, "IT.STUDYID") slice_itr = igd.ItemRef[1:5] self.assertEqual(slice_itr[1].ItemOID, "IT.TA.ARMCD")
def test_itemgroupdef_round_trip(self): """ system test to create and serialize an ItemGroupDef object """ attrs = self.set_itemgroupdef_attributes() igd = DEFINE.ItemGroupDef(**attrs) tt = DEFINE.TranslatedText(_content="Vital Signs", lang="en") igd.Description = DEFINE.Description() igd.Description.TranslatedText = [tt] item_refs = self.set_itemrefs() igd.ItemRef = item_refs parser = ODM_PARSER.ODMParser(self.test_file, self.nsr) parser.parse() mdv = parser.MetaDataVersion() igd_list = parser.ItemGroupDef(parent=mdv[0]) igd_dict = igd_list[0] self.assertEqual(igd_dict["OID"], "IG.TA") ir_list = parser.ItemRef(parent=igd_dict["elem"]) # tests the __len__ in ItemGroupDef as well as the add_item_ref self.assertEqual(len(ir_list), len(igd))
def test_to_xml(self): attrs = self.set_itemgroupdef_attributes() igd = DEFINE.ItemGroupDef(**attrs) tt = DEFINE.TranslatedText( _content="this is the first test description", lang="en") desc = DEFINE.Description() desc.TranslatedText = [tt] igd.Description = desc ir1 = DEFINE.ItemRef(ItemOID="IT.STUDYID", Mandatory="Yes", OrderNumber=1) ir2 = DEFINE.ItemRef(ItemOID="IT.VS.VSTEST", Mandatory="No", OrderNumber=2) igd.ItemRef = [ir1, ir2] igd_xml = igd.to_xml() self.assertEqual(igd_xml.attrib["OID"], "IG.VS") self.assertListEqual(["Description", "ItemRef", "ItemRef"], [e.tag for e in igd_xml.getchildren()])
def test_to_json(self): attrs = self.set_itemgroupdef_attributes() igd = DEFINE.ItemGroupDef(**attrs) tt = DEFINE.TranslatedText( _content="this is the first test description", lang="en") igd.Description = DEFINE.Description() igd.Description.TranslatedText = [tt] ir1 = DEFINE.ItemRef(ItemOID="IT.STUDYID", Mandatory="Yes", OrderNumber=1) ir2 = DEFINE.ItemRef(ItemOID="IT.VS.VSTEST", Mandatory="No", OrderNumber=2) igd.ItemRef = [ir1, ir2] igd_json = igd.to_json() igd_dict = json.loads(igd_json) print(igd_dict) self.assertEqual(igd_dict["OID"], "IG.VS") self.assertEqual(igd_dict["ItemRef"][1]["ItemOID"], "IT.VS.VSTEST")
def test_set_description(self): attrs = {"_content": "Assessment Result in Original Units", "lang": "en"} tt1 = DEFINE.TranslatedText(**attrs) self.item.Description.TranslatedText.append(tt1) self.assertEqual(self.item.Description.TranslatedText[0].lang, "en") self.assertEqual(self.item.Description.TranslatedText[0]._content, "Assessment Result in Original Units")