Esempio n. 1
0
 def test_dump_index(self, api_paths):
     myIo = IoAdapter(raiseExceptions=True)
     containerList = myIo.readFile(
         inputFilePath=str(api_paths['pathPdbxDictionary']))
     dApi = DictionaryApi(containerList=containerList, consolidate=True)
     print("Index = %r\n" % dApi.getItemNameList('pdbx_nmr_spectral_dim'))
     print("Index = %r\n" %
           dApi.getAttributeNameList('pdbx_nmr_spectral_dim'))
     catIndex = dApi.getCategoryIndex()
     print("Index = %r\n" % catIndex['pdbx_nmr_spectral_dim'])
     assert catIndex['pdbx_nmr_spectral_dim'] is not None
Esempio n. 2
0
    def testDumpIndex(self):
        """Test case -  dump methods for dictionary metadata"""

        try:
            myIo = IoAdapter(raiseExceptions=True)
            self.__containerList = myIo.readFile(inputFilePath=self.__pathPdbxDictionary)
            dApi = DictionaryApi(containerList=self.__containerList, consolidate=True, verbose=self.__verbose)
            if self.__verbose:
                dApi.dumpCategoryIndex(fh=self.__lfh)
            logger.debug("Index = %r\n", dApi.getItemNameList("pdbx_nmr_spectral_dim"))
            logger.debug("Index = %r\n", dApi.getAttributeNameList("pdbx_nmr_spectral_dim"))
            catIndex = dApi.getCategoryIndex()
            logger.debug("Index = %r\n", catIndex["pdbx_nmr_spectral_dim"])
            self.assertIsNotNone(catIndex["pdbx_nmr_spectral_dim"])
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
    def test_markup_category_group(self, in_tmpdir, test_files, out_file_name,
                                   groupSelectList):
        oFile = out_file_name
        rL = []

        myIo = IoAdapter()
        containerList = myIo.readFile(
            str(test_files / "mmcif_pdbx_v5_next.dic"))
        dApi = DictionaryApi(containerList=containerList, consolidate=True)
        #
        groupList = dApi.getCategoryGroups()
        print('groupList %s\n' % groupList)
        for groupName in groupList:
            if groupSelectList and groupName not in groupSelectList:
                continue

            #
            # Goup header details
            #
            rL.append("# Category Group %s" % groupName)
            rL.append("")
            rL.append("")
            rL.append("%s" % dApi.getCategoryGroupDescription(groupName))
            rL.append("")
            rL.append("---")
            rL.append("")
            catNameList = dApi.getCategoryGroupCategories(groupName=groupName)
            #
            cList = self.__sortIgnoreCase(catNameList)
            for catName in cList:
                print('Group %s category %s\n' % (groupName, catName))
                catDescription = dApi.getCategoryDescription(category=catName)
                catExTupList = dApi.getCategoryExampleList(category=catName)
                keyItemNameList = dApi.getCategoryKeyList(category=catName)
                keyAttNameList = [
                    CifName.attributePart(k) for k in keyItemNameList
                ]
                #
                # Category header details
                #
                rL.append("## Category %s" % catName)
                rL.append("")
                rL.append("")
                rL.append(" %s" % catDescription)
                rL.append("")
                rL.append("---")
                rL.append("")
                if catExTupList:
                    rL.extend(
                        self.__formatTupListInset(catExTupList, tab='     '))
                    #
                    # summary table
                    #
                rL.append("")
                rL.append("---")
                rL.append("")
                rL.append(
                    "| Attribute | Key | Required | Type | Units | Enumerated | Bounded |"
                )
                rL.append(
                    "| --------- | --- | -------- | ---- | ----- | ---------- | ------- |"
                )
                aList = self.__sortIgnoreCase(
                    dApi.getAttributeNameList(category=catName))
                for attName in aList:
                    isKey = attName in keyAttNameList
                    attDescription = dApi.getDescription(category=catName,
                                                         attribute=attName)
                    attUnits = dApi.getUnits(category=catName,
                                             attribute=attName)
                    attMandatory = dApi.getMandatoryCode(category=catName,
                                                         attribute=attName)
                    attTypeCode = dApi.getTypeCode(category=catName,
                                                   attribute=attName)

                    enumTupList = dApi.getEnumListWithDetail(category=catName,
                                                             attribute=attName)
                    if len(enumTupList) > 0:
                        isEnum = True
                    else:
                        isEnum = False
                    bL = dApi.getBoundaryList(category=catName,
                                              attribute=attName)
                    if len(bL) > 0:
                        isBounded = True
                    else:
                        isBounded = False
                    rL.append(
                        '| %s | %s | %s | %s | %s | %s | %s |' %
                        (attName, self.__trB(isKey), attMandatory, attTypeCode,
                         attUnits, self.__trB(isEnum), self.__trB(isBounded)))
                #
                rL.append("")
                rL.append("---")
                rL.append("")
                #
                for attName in aList:
                    isKey = attName in keyAttNameList
                    attMandatory = dApi.getMandatoryCode(category=catName,
                                                         attribute=attName)
                    #
                    tN = '_' + catName + '.' + attName
                    if isKey:
                        tN = tN + ' (key)'
                    elif attMandatory.upper() in ['YES', 'Y']:
                        tN = tN + ' (required)'
                    #
                    rL.append("#### %s\n" % tN)
                    rL.append("")
                    attDescription = dApi.getDescription(category=catName,
                                                         attribute=attName)
                    rL.append(" %s\n" % attDescription)
                    rL.append("")
                    attUnits = dApi.getUnits(category=catName,
                                             attribute=attName)
                    attTypeCode = dApi.getTypeCode(category=catName,
                                                   attribute=attName)

                    enumTupList = dApi.getEnumListWithDetail(category=catName,
                                                             attribute=attName)
                    if len(enumTupList) > 0:
                        rL.append("")
                        rL.append("---")
                        rL.append("")
                        rL.append("| Allowed Values | Detail |")
                        rL.append("| -------------- | ------ |")
                        for tup in enumTupList:
                            if tup[1] and len(tup[1]) > 0:
                                rL.append("| %s | %s |" % (tup[0], tup[1]))
                            else:
                                rL.append("| %s | %s |" % (tup[0], ' '))
                        rL.append("")

                    #
                    bL = dApi.getBoundaryList(category=catName,
                                              attribute=attName)
                    btL = self.__processbounds(bL)
                    if len(btL) > 0:
                        tup = btL[0]
                        rL.append("")
                        rL.append("---")
                        rL.append("")
                        rL.append("| %s | %s |" % (tup[0], tup[1]))
                        #
                        rL.append("| ------------- | ------ |")
                        for tup in btL[1:]:
                            rL.append("| %s | %s |" % (tup[0], tup[1]))
                        rL.append("")
                    rL.append("")
        with open(str(oFile), 'w') as ofh:
            ofh.write('\n'.join(rL))
    def __testScanRepo(self, contentType, scanType="full"):
        """Utility method to scan repo for data type and coverage content.

        Using mock repos for tests.
        """
        try:
            containerList = self.__mU.doImport(self.__pathPdbxDictionary,
                                               fmt="mmcif-dict")
            dictApi = DictionaryApi(containerList=containerList,
                                    consolidate=True,
                                    verbose=True)

            failedFilePath = os.path.join(
                HERE, "test-output",
                "%s-failed-list-%s.txt" % (contentType, scanType))
            savedFilePath = os.path.join(
                HERE, "test-output",
                "%s-path-list-%s.txt" % (contentType, scanType))
            scanDataFilePath = os.path.join(HERE, "test-output",
                                            "%s-scan-data.pic" % (contentType))
            dataCoverageFilePath = os.path.join(
                HERE, "test-output",
                "%s-scan-data-coverage-%s.json" % (contentType, scanType))
            dataCoverageItemFilePath = os.path.join(
                HERE, "test-output",
                "%s-scan-data-item-coverage-%s.tdd" % (contentType, scanType))
            dataTypeFilePath = os.path.join(
                HERE, "test-output",
                "%s-scan-data-type-%s.json" % (contentType, scanType))
            #
            ###
            categoryList = sorted(dictApi.getCategoryList())
            dictSchema = {
                catName: sorted(dictApi.getAttributeNameList(catName))
                for catName in categoryList
            }
            attributeDataTypeD = OrderedDict()
            for catName in categoryList:
                aD = {}
                for atName in dictSchema[catName]:
                    aD[atName] = dictApi.getTypeCode(catName, atName)
                attributeDataTypeD[catName] = aD
            ###
            #
            sr = ScanRepoUtil(self.__cfgOb,
                              attributeDataTypeD=attributeDataTypeD,
                              numProc=self.__numProc,
                              chunkSize=self.__chunkSize,
                              fileLimit=self.__fileLimit,
                              workPath=self.__cachePath)
            ok = sr.scanContentType(contentType,
                                    scanType=scanType,
                                    inputPathList=None,
                                    scanDataFilePath=scanDataFilePath,
                                    failedFilePath=failedFilePath,
                                    saveInputFileListPath=savedFilePath)
            self.assertTrue(ok)
            ok = sr.evalScan(scanDataFilePath,
                             dataTypeFilePath,
                             evalType="data_type")
            self.assertTrue(ok)
            ok = sr.evalScan(scanDataFilePath,
                             dataCoverageFilePath,
                             evalType="data_coverage")
            self.assertTrue(ok)
            ok = sr.evalScanItem(scanDataFilePath, dataCoverageItemFilePath)
            self.assertTrue(ok)

            return ok
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Esempio n. 5
0
    def __testMarkupCategoryGroup(self, oFile, groupSelectList=None):
        """Test case -  extract the content to be rendered -"""
        startTime = time.time()
        logger.debug("\nStarting at %s\n",
                     time.strftime("%Y %m %d %H:%M:%S", time.localtime()))
        try:
            rL = []

            myIo = IoAdapter()
            containerList = myIo.readFile(self.__pathPdbxV50Dictionary)
            dApi = DictionaryApi(containerList=containerList,
                                 consolidate=True,
                                 verbose=self.__verbose)
            #
            groupList = dApi.getCategoryGroups()
            logger.debug("groupList %s\n", groupList)
            for groupName in groupList:
                if groupSelectList and groupName not in groupSelectList:
                    continue

                #
                # Goup header details
                #
                rL.append("# Category Group %s" % groupName)
                rL.append("")
                rL.append("")
                rL.append("%s" % dApi.getCategoryGroupDescription(groupName))
                rL.append("")
                rL.append("---")
                rL.append("")
                catNameList = dApi.getCategoryGroupCategories(
                    groupName=groupName)
                #
                cList = self.__sortIgnoreCase(catNameList)
                for catName in cList:
                    logger.debug("Group %s category %s\n", groupName, catName)
                    catDescription = dApi.getCategoryDescription(
                        category=catName)
                    catExTupList = dApi.getCategoryExampleList(
                        category=catName)
                    keyItemNameList = dApi.getCategoryKeyList(category=catName)
                    keyAttNameList = [
                        CifName.attributePart(k) for k in keyItemNameList
                    ]
                    #
                    # Category header details
                    #
                    rL.append("## Category %s" % catName)
                    rL.append("")
                    rL.append("")
                    rL.append(" %s" % catDescription)
                    rL.append("")
                    rL.append("---")
                    rL.append("")
                    if catExTupList:
                        rL.extend(
                            self.__formatTupListInset(catExTupList,
                                                      tab="     "))
                        #
                        # summary table
                        #
                    rL.append("")
                    rL.append("---")
                    rL.append("")
                    rL.append(
                        "| Attribute | Key | Required | Type | Units | Enumerated | Bounded |"
                    )
                    rL.append(
                        "| --------- | --- | -------- | ---- | ----- | ---------- | ------- |"
                    )
                    aList = self.__sortIgnoreCase(
                        dApi.getAttributeNameList(category=catName))
                    for attName in aList:
                        isKey = attName in keyAttNameList
                        attDescription = dApi.getDescription(category=catName,
                                                             attribute=attName)
                        attUnits = dApi.getUnits(category=catName,
                                                 attribute=attName)
                        attMandatory = dApi.getMandatoryCode(category=catName,
                                                             attribute=attName)
                        attTypeCode = dApi.getTypeCode(category=catName,
                                                       attribute=attName)

                        enumTupList = dApi.getEnumListWithDetail(
                            category=catName, attribute=attName)
                        if enumTupList:
                            isEnum = True
                        else:
                            isEnum = False
                        bL = dApi.getBoundaryList(category=catName,
                                                  attribute=attName)
                        if bL:
                            isBounded = True
                        else:
                            isBounded = False
                        rL.append("| %s | %s | %s | %s | %s | %s | %s |" %
                                  (attName, self.__trB(isKey), attMandatory,
                                   attTypeCode, attUnits, self.__trB(isEnum),
                                   self.__trB(isBounded)))
                    #
                    rL.append("")
                    rL.append("---")
                    rL.append("")
                    #
                    for attName in aList:
                        isKey = attName in keyAttNameList
                        attMandatory = dApi.getMandatoryCode(category=catName,
                                                             attribute=attName)
                        #
                        tN = "_" + catName + "." + attName
                        if isKey:
                            tN = tN + " (key)"
                        elif attMandatory.upper() in ["YES", "Y"]:
                            tN = tN + " (required)"
                        #
                        rL.append("#### %s\n" % tN)
                        rL.append("")
                        attDescription = dApi.getDescription(category=catName,
                                                             attribute=attName)
                        rL.append(" %s\n" % attDescription)
                        rL.append("")
                        attUnits = dApi.getUnits(category=catName,
                                                 attribute=attName)
                        attTypeCode = dApi.getTypeCode(category=catName,
                                                       attribute=attName)

                        enumTupList = dApi.getEnumListWithDetail(
                            category=catName, attribute=attName)
                        if enumTupList:
                            rL.append("")
                            rL.append("---")
                            rL.append("")
                            rL.append("| Allowed Values | Detail |")
                            rL.append("| -------------- | ------ |")
                            for tup in enumTupList:
                                if tup[1]:
                                    rL.append("| %s | %s |" % (tup[0], tup[1]))
                                else:
                                    rL.append("| %s | %s |" % (tup[0], " "))
                            rL.append("")

                        #
                        bL = dApi.getBoundaryList(category=catName,
                                                  attribute=attName)
                        btL = self.__processbounds(bL)
                        if btL:
                            tup = btL[0]
                            rL.append("")
                            rL.append("---")
                            rL.append("")
                            rL.append("| %s | %s |" % (tup[0], tup[1]))
                            #
                            rL.append("| ------------- | ------ |")
                            for tup in btL[1:]:
                                rL.append("| %s | %s |" % (tup[0], tup[1]))
                            rL.append("")
                        rL.append("")
            with open(oFile, "w") as ofh:
                ofh.write("\n".join(rL))

        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()

        endTime = time.time()
        logger.debug("\nCompleted at %s (%.2f seconds)",
                     time.strftime("%Y %m %d %H:%M:%S", time.localtime()),
                     endTime - startTime)