TestDesign.py :  » Web-Frameworks » Webware » Webware-1.0.2 » MiddleKit » Tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » MiddleKit » Tests » TestDesign.py
#!/usr/bin/env python

"""TestDesign.py"""

from TestCommon import *
from MiddleKit.Design.Generate import Generate
from MiddleKit.Core.Model import Model


def importPyClasses(klasses):
  # See if we can import all of the classes
  print 'importing classes:', ', '.join(klasses.keys())
  for klassName in klasses.keys():
    code = 'from %s import %s\n' % (klassName, klassName)
    #sys.stdout.write(code)
    results = {}
    exec code in results
    assert results.has_key(klassName)


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)


if __name__ == '__main__':
  try:
    test(sys.argv[1], sys.argv[2])
  except Exception:
    import traceback
    exc_info = sys.exc_info()
    traceback.print_exception(*exc_info)
    print '>> ABOUT TO EXIT WITH CODE 1'
    sys.exit(1)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.