Beispiel #1
0
# Basic use cases and unit tests
# ==============================================================================
#


def TEST_serialization():
    from testdata import TestData
    ref_name = "my study case"
    studyData = TestData()
    studyData.setName(ref_name)

    print "serialize data ..."
    serialString = serialize(studyData)
    print "unserialize data ..."
    unserialData = unserialize(serialString)

    res_name = unserialData.getName()
    print res_name
    if (ref_name != res_name):
        return False

    unserialData.log()
    unserialData.setName("an other name")

    return True


if __name__ == "__main__":
    import unittester
    unittester.run("salome/kernel/__init__", "TEST_serialization")
Beispiel #2
0
    return True

def TEST_lookup():
    symbol_dic = TEST_getTestDictionnary()

    name = 'lithium'
    symbol = 'Li'
    # use a dictionary as initialization argument
    look = Lookup(symbol_dic)
    print look.get_key(name)      # [Li']
    if look.get_key(name) != symbol:
        print "get "+str(look.get_key(name))+" while "+str(symbol)+" was expected"
        return False
    print look.get_value(symbol)  # lithium

    # use a list of pairs instead of a dictionary as initialization argument
    # (will be converted to a dictionary by the class internally)
    age_list = [['Fred', 23], ['Larry', 28], ['Ene', 23]]
    look2 = Lookup(age_list)
    print look2.get_keys(23)        # ['Ene', 'Fred']
    if look2.get_keys(23)[0] != 'Ene' or look2.get_keys(23)[1] != 'Fred':
        print "get "+str(look2.get_keys(23))+" while ['Ene', 'Fred'] was expected"
        return False
    print look2.get_value('Fred')  # 23
    return True

if __name__ == '__main__':
    import unittester
    unittester.run("diclookup", "TEST_find_value")
    unittester.run("diclookup", "TEST_lookup")
    print "########## find 1"
    rootpath=TESTDOCDIR
    listfiles=findFiles(rootpath)
    for filename in listfiles:
        print filename

    print "########## find 2"
    excludes=[os.path.join(TESTDOCDIR,"doc")]
    listfiles=findFiles(rootpath,excludes)
    for filename in listfiles:
        print filename

    return True

# This is the test callback function
def visitfile_withargs(file, rootid):
    print 'visiting file %s (rootid=%s)'%(file,str(rootid))

def visitfile_withoutargs(file):
    print 'visiting file %s'%(file)

def TEST_walktree():
    #walktree(TESTDOCDIR, visitfile_withargs, rootid=2)
    walktree(TESTDOCDIR, visitfile_withoutargs)
    return True

if __name__ == "__main__":
    import unittester
    unittester.run("syshelper", "TEST_findFiles")
    unittester.run("syshelper", "TEST_walktree")
Beispiel #4
0

def TEST_keyOf():
    codes = Enumerate([
        'KERNEL',  # This should take the value 0
        'GUI',  # This should take the value 1
        'GEOM',  # ...
        'MED',
        'SMESH'
    ])

    if (codes.keyOf(codes.KERNEL) != 'KERNEL'
            or codes.keyOf(codes.GUI) != 'GUI'
            or codes.keyOf(codes.GEOM) != 'GEOM'
            or codes.keyOf(codes.MED) != 'MED'
            or codes.keyOf(codes.SMESH) != 'SMESH'):
        return False
    return True


if __name__ == "__main__":
    import unittester
    unittester.run("enumerate", "TEST_simple")
    unittester.run("enumerate", "TEST_createFromList")
    unittester.run("enumerate", "TEST_createFromString")
    unittester.run("enumerate", "TEST_contains")
    unittester.run("enumerate", "TEST_isValid")
    unittester.run("enumerate", "TEST_offset")
    unittester.run("enumerate", "TEST_listvalues")
    unittester.run("enumerate", "TEST_keyOf")
Beispiel #5
0
def TEST_serialize():
    import salome.kernel
    ref_testdata = TestData()
    ref_testdata.setName("The firts name")
    res_testdata = salome.kernel.unserialize(
        salome.kernel.serialize(ref_testdata))

    print res_testdata.getName()

    if res_testdata.getName() != ref_testdata.getName():
        return False

    # Is the unserialized data still functional?
    try:
        res_testdata.setName("An other name")
        print res_testdata.getName()
    except:
        print e
        return False
    return True


if __name__ == "__main__":
    from unittester import run
    run("salome/kernel/testdata", "TEST_getName")
    run("salome/kernel/testdata", "TEST_useBadKey")
    run("salome/kernel/testdata", "TEST_useBadType")
    run("salome/kernel/testdata", "TEST_useBadRange")
    run("salome/kernel/testdata", "TEST_serialize")
Beispiel #6
0
        print filename

    print "########## find 2"
    excludes = [os.path.join(TESTDOCDIR, "doc")]
    listfiles = findFiles(rootpath, excludes)
    for filename in listfiles:
        print filename

    return True


# This is the test callback function
def visitfile_withargs(file, rootid):
    print 'visiting file %s (rootid=%s)' % (file, str(rootid))


def visitfile_withoutargs(file):
    print 'visiting file %s' % (file)


def TEST_walktree():
    #walktree(TESTDOCDIR, visitfile_withargs, rootid=2)
    walktree(TESTDOCDIR, visitfile_withoutargs)
    return True


if __name__ == "__main__":
    import unittester
    unittester.run("syshelper", "TEST_findFiles")
    unittester.run("syshelper", "TEST_walktree")
        print err
        return True

def TEST_serialize():
    import salome.kernel
    ref_testdata = TestData()
    ref_testdata.setName("The firts name")
    res_testdata = salome.kernel.unserialize(salome.kernel.serialize(ref_testdata))

    print res_testdata.getName()

    if res_testdata.getName() != ref_testdata.getName():
        return False

    # Is the unserialized data still functional?
    try:
        res_testdata.setName("An other name")
        print res_testdata.getName()
    except:
        print e
        return False
    return True

if __name__ == "__main__":
    from unittester import run
    run("salome/kernel/testdata","TEST_getName")
    run("salome/kernel/testdata","TEST_useBadKey")
    run("salome/kernel/testdata","TEST_useBadType")
    run("salome/kernel/testdata","TEST_useBadRange")
    run("salome/kernel/testdata","TEST_serialize")
Beispiel #8
0
        print e
        return True


def TEST_defaultValues():
    typemap = {}
    typemap["stringdata"] = TypeString
    typemap["integerdata"] = TypeInteger

    ref_value = "my initial value"
    defaultmap = {}
    defaultmap["stringdata"] = ref_value

    data = DataModeler(typemap=typemap, defaultmap=defaultmap)
    print data.stringdata
    if data.stringdata != ref_value:
        return False
    else:
        return True


if __name__ == "__main__":
    from unittester import run
    run("salome/kernel/datamodeler", "TEST_usecase")
    run("salome/kernel/datamodeler", "TEST_addAttribute")
    run("salome/kernel/datamodeler", "TEST_badAttributeName")
    run("salome/kernel/datamodeler", "TEST_badAttributeType")
    run("salome/kernel/datamodeler", "TEST_badAttributeRange")
    run("salome/kernel/datamodeler", "TEST_voidAttributeAllowed")
    run("salome/kernel/datamodeler", "TEST_defaultValues")
        return False
    except Exception, e:
        print e
        return True

def TEST_defaultValues():
    typemap={}
    typemap["stringdata"] = TypeString
    typemap["integerdata"] = TypeInteger

    ref_value = "my initial value"
    defaultmap={}
    defaultmap["stringdata"] = ref_value

    data = DataModeler(typemap=typemap,defaultmap=defaultmap)
    print data.stringdata
    if data.stringdata != ref_value:
        return False
    else:
        return True

if __name__ == "__main__":
    from unittester import run
    run("salome/kernel/datamodeler","TEST_usecase")
    run("salome/kernel/datamodeler","TEST_addAttribute")
    run("salome/kernel/datamodeler","TEST_badAttributeName")
    run("salome/kernel/datamodeler","TEST_badAttributeType")
    run("salome/kernel/datamodeler","TEST_badAttributeRange")
    run("salome/kernel/datamodeler","TEST_voidAttributeAllowed")
    run("salome/kernel/datamodeler","TEST_defaultValues")
Beispiel #10
0
# Basic use cases and unit test functions
# ==============================================================================
#
def somethingGoesWrong():
    raise UiException("Something goes wrong")


def TEST_uimessage():
    try:
        somethingGoesWrong()
        return False
    except UiException, err:
        print 'ERROR: %s' % str(err)
        if (str(err) == "Something goes wrong"):
            return True
        else:
            return False


def TEST_specificException():
    print DevelException("err")
    print AdminException("err")
    print UserException("err")
    return True


if __name__ == "__main__":
    import unittester
    unittester.run("uiexception", "TEST_uimessage")
    unittester.run("uiexception", "TEST_specificException")
    if codes.listvalues() != [20, 21, 22, 23, 24]:
        return False
    return True

def TEST_keyOf():
    codes = Enumerate([
        'KERNEL', # This should take the value 0
        'GUI', # This should take the value 1
        'GEOM', # ...
        'MED',
        'SMESH'])

    if ( codes.keyOf(codes.KERNEL) != 'KERNEL' or
         codes.keyOf(codes.GUI) != 'GUI' or
         codes.keyOf(codes.GEOM) != 'GEOM' or
         codes.keyOf(codes.MED) != 'MED' or
         codes.keyOf(codes.SMESH) != 'SMESH'):
            return False
    return True

if __name__ == "__main__":
    import unittester
    unittester.run("enumerate", "TEST_simple")
    unittester.run("enumerate", "TEST_createFromList")
    unittester.run("enumerate", "TEST_createFromString")
    unittester.run("enumerate", "TEST_contains")
    unittester.run("enumerate", "TEST_isValid")
    unittester.run("enumerate", "TEST_offset")
    unittester.run("enumerate", "TEST_listvalues")
    unittester.run("enumerate", "TEST_keyOf")
#
# ==============================================================================
# Basic use cases and unit tests
# ==============================================================================
#

def TEST_serialization():
    from testdata import TestData
    ref_name = "my study case"
    studyData = TestData()
    studyData.setName(ref_name)

    print "serialize data ..."
    serialString = serialize(studyData)
    print "unserialize data ..."
    unserialData = unserialize(serialString)

    res_name = unserialData.getName()
    print res_name
    if ( ref_name != res_name ):
        return False

    unserialData.log()
    unserialData.setName("an other name")

    return True

if __name__ == "__main__":
    import unittester
    unittester.run("salome/kernel/__init__","TEST_serialization")
#
# ==============================================================================
# Basic use cases and unit test functions
# ==============================================================================
#
def somethingGoesWrong():
    raise UiException("Something goes wrong")

def TEST_uimessage():
    try:
        somethingGoesWrong()
        return False
    except UiException, err:
        print 'ERROR: %s' % str(err)
        if ( str(err) == "Something goes wrong" ):
            return True
        else:
            return False

def TEST_specificException():
    print DevelException("err")
    print AdminException("err")
    print UserException("err")
    return True

if __name__ == "__main__":
    import unittester
    unittester.run("uiexception","TEST_uimessage")
    unittester.run("uiexception","TEST_specificException")
    
Beispiel #14
0
    import GEOM
    from salome.geom import geomBuilder
    geompy = geomBuilder.New(salome.myStudy)

    box = geompy.MakeBoxDXDYDZ(200, 200, 200)
    id = geompy.addToStudy( box, 'box' )
    return id

def TEST_objectsManipulation():
    myEntry = TEST_createObject()

    mySObject = IDToSObject(myEntry)
    entry     = SObjectToID(mySObject)

    if str(entry) != str(myEntry):
        return False


    myObject = IDToObject(myEntry)
    print myObject
    if myObject is None:
        return False

    return True

if __name__ == "__main__":
    import unittester
    unittester.run("services","TEST_getComponent")
    unittester.run("services","TEST_getComponentList")
    unittester.run("services","TEST_objectsManipulation")