Login | Register
My pages Projects Community openCollabNet

Discussions > users > Cannot use module "re", why not?

maxq
Discussion topic

Hide all messages in topic

All messages in topic

Re: [maxq-users] Creating a base class

Author oliverbock
Full name Oliver Bock
Date 2007-05-22 13:49:49 PDT
Message John,

I cannot quite remember what the Validator stuff does. I think I
tried to get rid of it at one stage, but met with some resistance. I
recommend the Compact base class instead.

Anyway, I'm sure you don't want the Validator stuff in both base
class and your script class. I'd try removing it from your base
class file. Also, you don't need the

>> if __name__ == 'main':

in your base class. It is boilerplate code that instantiates the
test object in your script class. The base class instance will be
automatically created as part of this process.


   Oliver

--
On 23/05/2007, at 01:23, jh wrote:
> I have tried unsuccessfully to create a base class using a
> standard script. I want to put all the functions I use most often
> in this base class. In th file main.py below I have done nothing
> but change the import class to baseClass and added a calle to
> logon. The first time I run it I get the error:
>
> NameError: validatorPkg
>
> The second time I run it (after a baseClass class file is
> generated) I get the error:
>
> ImportError: cannot import name baseClass
>
> I experimented with other jython scripts and have been able to do
> this. I don't understand all that is going on with the first 8
> lines of the standard script and I suspect that this has something
> to do with it. I am guessing that those lines are not executed when
> I try to import from the baseClass file. I also tried moving those
> lines (except the if) inside the class to no avail.

Creating a base class

Author hms_suprise
Full name john v hite
Date 2007-05-22 08:23:53 PDT
Message I have tried unsuccessfully to create a base class using a standard script.
I want to put all the functions I use most often in this base class. In th
file main.py below I have done nothing but change the import class to
baseClass and added a calle to logon. The first time I run it I get the
error:

NameError: validatorPkg

The second time I run it (after a baseClass class file is generated) I get
the error:

ImportError: cannot import name baseClass

I experimented with other jython scripts and have been able to do this. I
don't understand all that is going on with the first 8 lines of the standard
script and I suspect that this has something to do with it. I am guessing
that those lines are not executed when I try to import from the baseClass
file. I also tried moving those lines (except the if) inside the class to no
avail.

Ideas?

Thanks,

John
~~~~~~~~~~~~~~~~~~~~​~~~~~~~~~~~~~~~~~~~~​~~
File main.py
# Generated by MaxQ [com.bitmechanic.max​q.generator.JythonCo​deGenerator]
from PyHttpTestCase import PyHttpTestCase
from com.bitmechanic.maxq import Config
global validatorPkg
if __name__ == 'main':
    validatorPkg = Config.getValidatorPkgName()
# Determine the validator for this testcase.
exec 'from '+validatorPkg+' import Validator'

from baseClass import baseClass

# definition of test class
class main(baseClass):
    def runTest(self):
        self.msg('Test started')
        self.logon()

    # ^^^ Insert new recordings here. (Do not remove this line.)


# Code to load and run the test
if __name__ == 'main':
    test = main("main")
    test.Run()

~~~~~~~~~~~~~~~~~~~~​~~~~~~~~~~~~~~~~~~~~​~~~~~~~~
File baseClass.py
# Generated by MaxQ [com.bitmechanic.max​q.generator.JythonCo​deGenerator]
from PyHttpTestCase import PyHttpTestCase
from com.bitmechanic.maxq import Config
global validatorPkg
if __name__ == 'main':
    validatorPkg = Config.getValidatorPkgName()
# Determine the validator for this testcase.
exec 'from '+validatorPkg+' import Validator'


# definition of test class
class baseClass(PyHttpTestCase):
    def logon(self):
        self.msg('Logon.')

    # ^^^ Insert new recordings here. (Do not remove this line.)


# Code to load and run the test
if __name__ == 'main':
    test = baseClass("baseClass")
    test.logon()

Re: [maxq-users] Cannot use module "re", why not?

Author oliverbock
Full name Oliver Bock
Date 2007-05-19 19:29:05 PDT
Message > I need to use regular expressions. So I tried to import it:
>
> import re
> ...
> What is the problem here? I read that the module "re" is contained
> in Jython. If I don't import it, I get another error:

The MaxQ distribution includes only the base Jython JAR file. If you
want the libraries then see the section "Using the Full Jython
Libraries" under Recipes in the command line.


    Oliver

Cannot use module "re", why not?

Author Hans Schwaebli <hans_schwaebli at yahoo dot com>
Full name Hans Schwaebli <hans_schwaebli at yahoo dot com>
Date 2007-05-19 15:56:19 PDT
Message I need to use regular expressions. So I tried to import it:

import re

But when running, it says:

Traceback (innermost last):
  File "<string>", line 2, in ?
ImportError: no module named re

What is the problem here? I read that the module "re" is contained in Jython. If I don't import it, I get another error:

Traceback (innermost last):
  File "<string>", line 27, in ?
  File "<string>", line 13, in runTest
NameError: re

Any solution?

 
--------------------​-------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.
Attachments
Messages per page: