Пример #1
0
def test(modelFilename, workDir=workDir, toTestDir='../'):
	"""
	modelFilename: the correct filename to the existing model
	workDir:       the directory to remove and create and then put the
	               generated files in
	toTestDir:     a relative path to get from inside the workDir back
	               to the MiddleKit/Tests dir

	In most cases, the defaults for workDir and toTestDir are
	sufficient.	In funkalicious cases, like the MKMultipleStores test,
	overriding these defaults comes in handy.
	"""
	rmdir(workDir)     # get rid of files from previous runs
	os.mkdir(workDir)  # make a space for the files from this run

	# Run generate, load the model, and import some classes
	Generate().main('Generate.py --outdir %s --db MySQL --model %s' % (workDir, modelFilename))
	curDir = os.getcwd()
	os.chdir(workDir)
	try:
		model = Model(toTestDir+modelFilename)
		importPyClasses(model.klasses())
		return model
	finally:
		os.chdir(curDir)
Пример #2
0
    def makeModel(self):
        """ Constructs and returns a MiddleKit model for use with UserKit. """

        from MiddleKit.Core.Model import Model
        from MiddleKit.Core.Klasses import Klasses
        from MiddleKit.Core.Klass import Klass
        from MiddleKit.Core.StringAttr import StringAttr
        klass = Klass()
        klass.readDict({'Class': 'UserForMKTest'})
        klass.addAttr(
            StringAttr({
                'Name': 'name',
                'Type': 'string',
                'isRequired': 1,
            }))
        klass.addAttr(
            StringAttr({
                'Name': 'password',
                'Type': 'string',
                'isRequired': 1,
            }))
        klass.addAttr(
            StringAttr({
                'Name': 'externalId',
                'Type': 'string',
                'isRequired': 0,
            }))
        model = Model()
        model.setName(self.__class__.__name__)
        model.readParents([])
        klasses = model.klasses()
        klasses.addKlass(klass)
        model.awakeFromRead(
        )  # @@ 2001-02-17 ce: a little weird regarding name
        return model
Пример #3
0
def test(modelFilename, configFilename, workDir=workDir, toTestDir='../'):
    """Test method.

    modelFilename: the correct filename to the existing model
    workDir:       the directory to remove and create and then put the
                   generated files in
    toTestDir:     a relative path to get from inside the workDir back
                   to the MiddleKit/Tests dir

    In most cases, the defaults for workDir and toTestDir are
    sufficient.     In funkalicious cases, like the MKMultipleStores test,
    overriding these defaults comes in handy.

    """
    rmdir(workDir) # get rid of files from previous runs
    os.mkdir(workDir) # make a space for the files from this run

    # Run generate, load the model, and import some classes
    command = os.path.normpath('../Design/Generate.py')
    command += ' --outdir %s --db %s --model %s' % (workDir, dbName, modelFilename)
    if configFilename:
        command += ' --config ' + configFilename
    print command
    Generate().main(command)
    curDir = os.getcwd()
    os.chdir(workDir)
    try:
        if 0:
            print 'getcwd:', os.getcwd()
            print 'listdir:', os.listdir('.')
            print 'model path:', repr(toTestDir+modelFilename)
            print 'sys.path', sys.path
        model = Model(toTestDir+modelFilename, configFilename=configFilename)
        importPyClasses(model.klasses())
        return model
    finally:
        os.chdir(curDir)
Пример #4
0
def test(modelFilename, configFilename, workDir=workDir, toTestDir='../'):
    """Test method.

    modelFilename: the correct filename to the existing model
    workDir:       the directory to remove and create and then put the
                   generated files in
    toTestDir:     a relative path to get from inside the workDir back
                   to the MiddleKit/Tests dir

    In most cases, the defaults for workDir and toTestDir are
    sufficient.     In funkalicious cases, like the MKMultipleStores test,
    overriding these defaults comes in handy.
    """
    rmdir(workDir)  # get rid of files from previous runs
    os.mkdir(workDir)  # make a space for the files from this run

    # Run generate, load the model, and import some classes
    command = os.path.normpath('../Design/Generate.py')
    command += ' --outdir %s --db %s --model %s' % (workDir, dbName,
                                                    modelFilename)
    if configFilename:
        command += ' --config ' + configFilename
    print(command)
    Generate().main(command)
    curDir = os.getcwd()
    os.chdir(workDir)
    try:
        if 0:
            print('getcwd:', os.getcwd())
            print('listdir:', os.listdir('.'))
            print('model path:', repr(toTestDir + modelFilename))
            print('sys.path', sys.path)
        model = Model(toTestDir + modelFilename, configFilename=configFilename)
        importPyClasses(model.klasses())
        return model
    finally:
        os.chdir(curDir)