def leftEqual(left, right, visitedIdInstances, muteLogs=True) :
    if ObjectHelper.isNone(left) or ObjectHelper.isNone(right) :
        return left is None and right is None
    isEqual = True
    leftIsCollection = ObjectHelper.isCollection(left)
    rightIsCollection = ObjectHelper.isCollection(right)
    if leftIsCollection and rightIsCollection :
        if len(left) == len(right) :
            for itemLeft, itemRight in zip(left, right) :
                if isEqual :
                    isEqual = isEqual and ObjectHelper.equals(itemLeft, itemRight, visitedIdInstances=visitedIdInstances, muteLogs=muteLogs)
                else :
                    break
            return isEqual
        else :
            return False
    elif (leftIsCollection and not rightIsCollection) or (not leftIsCollection and rightIsCollection) :
        return False
    else :
        attrinuteDataList = ReflectionHelper.getAttributeDataList(left)
        if not muteLogs :
            LogHelper.prettyPython(leftEqual, f'{left} data list', attrinuteDataList, logLevel=LogHelper.DEBUG, condition=not muteLogs)
        if 0 == len(attrinuteDataList) :
            return False
        for value, name in attrinuteDataList :
            if isEqual :
                isEqual = isEqual and ObjectHelper.equals(value, ReflectionHelper.getAttributeOrMethod(right, name), visitedIdInstances=visitedIdInstances, muteLogs=muteLogs)
            else :
                break
        return isEqual
Exemplo n.º 2
0
def sample(collection, length=None):
    if ObjectHelper.isCollection(collection):
        if ObjectHelper.isDictionary(collection):
            if ObjectHelper.isNone(length):
                key = RandomHelperHelper.sampleCollection(
                    list(collection.keys()), list)
                return {key: collection[key]}
            sampleDictionaryKeys = RandomHelperHelper.sampleCollection(
                list(collection.keys()), list, length=length)
            sampleDictionary = {}
            for key in sampleDictionaryKeys:
                sampleDictionary[key] = collection[key]
            return sampleDictionary
        elif ObjectHelper.isList(collection):
            return RandomHelperHelper.sampleCollection(collection,
                                                       list,
                                                       length=length)
        elif ObjectHelper.isSet(collection):
            return RandomHelperHelper.sampleCollection(collection,
                                                       set,
                                                       length=length)
        elif ObjectHelper.isTuple(collection):
            return RandomHelperHelper.sampleCollection(collection,
                                                       tuple,
                                                       length=length)
    raise Exception(f'The "{collection}" argument is not a collection')
Exemplo n.º 3
0
def updateSettingTree(toUpdateSettingTree, gatheringSettingTree):
    if ObjectHelper.isNotEmpty(gatheringSettingTree):
        if ObjectHelper.isNone(toUpdateSettingTree) or StringHelper.isBlank(
                toUpdateSettingTree):
            toUpdateSettingTree = {}
        if ObjectHelper.isCollection(
                gatheringSettingTree) and ObjectHelper.isDictionary(
                    gatheringSettingTree):
            for key, value in gatheringSettingTree.items():
                if ObjectHelper.isNotEmpty(value) and ObjectHelper.isNotNone(
                        value):
                    if key not in toUpdateSettingTree or ObjectHelper.isEmpty(
                            toUpdateSettingTree[key]):
                        toUpdateSettingTree[key] = value
                    else:
                        updateSettingTree(toUpdateSettingTree[key],
                                          gatheringSettingTree[key])
                elif key not in toUpdateSettingTree:
                    toUpdateSettingTree[key] = value
def isSettingValue(settingValue):
    return ObjectHelper.isNotEmpty(settingValue) or ObjectHelper.isCollection(
        settingValue)