[Zope] Re: Testing products outside of zope (i.e., in python interpreter)?

Andrey V Khavryutchenko akhavr@compchem.kiev.ua
07 Jan 2000 02:50:55 +0200


Hi, Joe! 

>>>>> "JG" == Joe Grace writes:

JG> Hi, is there a way to test zope products outside of zope?  I find that
JG> I'm restarting zope just to update my product and test it, and that
JG> seems painfully slow.  I'd like to just run code outside of zope
JG> interactively in a shell.  Is that possible?  I'm trying with Boring
JG> product (super simple) and tripping over the Persistence import

JG> 	Import Error: cannot import name Persistent

JG> I've run into this problem before and assume that Persistent is a C
JG> function.  How do I make it available to my python interpreter?  

Add the directory, where it's located to sys.path (in Python) or PYTHONPATH 
environment variable. 

JG> I couldn't figure out where z2.py gets it, but I also am just dealing
JG> with the python environment for the first time.  I'm using Xemacs (on
JG> NT) if that makes giving some tips any easier. :-)

JG> I'll take pointers, tips, how-to reference, anything at this point.
JG> I'd be happy to make a How-To if I get enough information.

Right now I'm using two-stage aproach.

First I build the Data.fs of my site using following script:

#!/usr/bin/env python
# -*- python -*- file
# $Id: build.py,v 1.1.2.1 2000/01/06 15:37:02 akhavr Exp $
#
# Copyright (C) 2000 by Andrey V Khavryutchenko <akhavr@compchem.kiev.ua>

import os, sys, getopt

verbose=0

opts, args = getopt.getopt(sys.argv[1:],'v')

for o, v in opts:
    if o=='-v': verbose=1
    

ZopeLibPath=os.environ['ZOPE_HOME']
sys.path=['',
          os.path.join(ZopeLibPath,'lib','python'),
          ZopeLibPath
          ]+filter(None,sys.path)

import Zope
root = Zope.app()

import src

os.chdir('src')
src.build(root, verbose=verbose)
get_transaction().commit()


Then, I run test scripts like the following and compare their output to
what it should look like.

#!/usr/bin/env python
# -*- python -*- file
# $Id: register-user_correct.py,v 1.1.2.4 2000/01/06 22:15:26 akhavr Exp $
#
# Copyright (C) 2000 by Andrey V Khavryutchenko <akhavr@compchem.kiev.ua>

request = {
    'first'   : 'Andrey',
    'last'    : 'Khavryutchenko',
    'email'   : 'akhavr@compchem.kiev.ua',
    'login'   : 'akhavr',
    'passwd'  : 'abracada$%^ra',
    'passwd2' : 'abracada$%^ra'
    }


import init
site = init.site

from mkrequest import *

print '*** Main page'
site('/')
site('/style_css')
print '*** Select'
site('/register')
print '*** Register'
site('/register/do' + mkrequest(request))


==================== init.py
#!/usr/bin/env python
# -*- python -*- file
# $Id: init.py,v 1.1.2.5 2000/01/06 15:37:00 akhavr Exp $
#
# Copyright (C) 2000 by Andrey V Khavryutchenko <akhavr@compchem.kiev.ua>

import os, sys, string

ZopeLibPath=os.environ['ZOPE_HOME']
sys.path=['',
          os.path.join(ZopeLibPath,'lib','python'),
          ZopeLibPath
          ]+filter(None,sys.path)

import ZPublisher, Zope
root = Zope.app()

def site(url, d=None):
    return ZPublisher.Zope(url, d=d)


Hope this helps

-- 
SY, Andrey V Khavryutchenko  http://www.kbi.kiev.ua/~akhavr
Software & SPI Engineer      Visit my site

Shick's Law:
	There is no problem a good miracle can't solve.