Back to index

plone3  3.1.7
Functions | Variables
kss.demo.selenium_utils.builder Namespace Reference

Functions

def getRootDirOfModule
def getRootDirOfClass
def getRootDirOfInstance
def getSeleniumTestsFromSuite
def formatcommand
def cookSeleniumTests

Variables

tuple template
tuple variable_regexp = re.compile('\$\{(?P<varname>\w*)\}')

Function Documentation

Cook selenium tests

Definition at line 74 of file builder.py.

00074 
00075 def cookSeleniumTests(filenames):
00076     """Cook selenium tests
00077     """
00078     # Try to open the file for writing.
00079     output_dir =  getRootDirOfModule('kss.demo.selenium_utils')
00080     output_filename = os.path.join(output_dir, 'seltest_all.py')
00081     try:
00082         f = open(output_filename, 'wb')
00083     except IOError, exc:
00084         raise IOError, ('Cannot open file "%s" for writing. '
00085                         'Make sure zope process has write access in directory. '
00086                         '["%s"]') \
00087                         % (output_filename, exc)
00088 
00089     htmlparser = HTMLTreeBuilder.TreeBuilder()
00090     tests = []
00091 
00092     # Now, we find all filenames that are in the suite passed to us.
00093     testname = 'all'
00094 
00095     for filename in filenames:
00096         tree = HTMLTreeBuilder.parse(filename)
00097         root = tree.getroot()
00098 
00099         try:
00100             testname = root.find('.//title').text
00101         except AttributeError:
00102             continue
00103         commands = []
00104         for row in root.findall('.//tbody/tr'):
00105             commands.append(formatcommand(*[td.text for td in row.findall('td')]))
00106 
00107         testfilename = 'seltest_%s.py' % testname
00108         testbody='    def test_%s(self):\n'%testname+' '*8+'\n        '.join(commands)+'\n'
00109         tests.append(testbody)
00110 
00111     # Use the last test's name as filename (???)
00112     # XXX I think we want to change this.
00113     f.write(template.substitute(dict(
00114         testname=testname,
00115         tests='\n'.join(tests),
00116         )))
00117     f.close()

Here is the call graph for this function:

def kss.demo.selenium_utils.builder.formatcommand (   command,
  args 
)

Definition at line 57 of file builder.py.

00057 
00058 def formatcommand(command, *args):
00059     if not command:
00060         return '' # Change this to raise an exception?
00061 
00062     arguments = []
00063     for arg in args:
00064         if not arg:
00065             continue
00066         matched = variable_regexp.match(arg)
00067         if matched is None:
00068             arguments.append('"%s"'%arg)
00069         else:
00070             arguments.append("self.getVar('%s')"%matched.group('varname'))
00071     return 'self.%s(%s)' % (command, ', '.join(arguments))
00072 
00073 

Here is the caller graph for this function:

Definition at line 13 of file builder.py.

00013 
00014 def getRootDirOfClass(cls):
00015     return getRootDirOfModule(cls.__module__)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 16 of file builder.py.

00016 
00017 def getRootDirOfInstance(obj):
00018     return getRootDirOfClass(obj.__class__)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 10 of file builder.py.

00010 
00011 def getRootDirOfModule(module_name):
00012     return os.path.dirname(sys.modules[module_name].__file__)

Here is the caller graph for this function:

def kss.demo.selenium_utils.builder.getSeleniumTestsFromSuite (   owner_instance,
  suite 
)
Get absolute filenames of all tests from the suite.
Suite contains the directory that we need to find.
owner_instance is used for the directory finding,
the suite's directory is traversed relative from that.

Definition at line 19 of file builder.py.

00019 
00020 def getSeleniumTestsFromSuite(owner_instance, suite):
00021     """Get absolute filenames of all tests from the suite.
00022     Suite contains the directory that we need to find.
00023     owner_instance is used for the directory finding,
00024     the suite's directory is traversed relative from that.
00025     """
00026     test_filenames = []
00027     # The owner instance is only used to traverse the sute directory
00028     # relative from it.
00029     root_dir = getRootDirOfInstance(owner_instance)
00030     tests_root_dir = os.path.join(root_dir, suite.test_directory)
00031     for test_filename in os.listdir(tests_root_dir):
00032         if test_filename.lower().endswith('.html') or \
00033                 test_filename.endswith('.htm'):
00034             test_filenames.append((test_filename, os.path.join(tests_root_dir, test_filename)))
00035     # sort the testfilenames
00036     test_filenames.sort()
00037     # return only the absolute filenames
00038     test_filenames = [filename[1] for filename in test_filenames]
00039     return test_filenames

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 Template(textwrap.dedent('''\
00002         from seleniumtestcase import SeleniumTestCase
00003         import unittest, time
00004 
00005         class seltest_$testname(SeleniumTestCase):
00006 
00007         $tests
00008 
00009         def test_suite():
00010             return unittest.makeSuite(seltest_$testname)
00011 
00012         if __name__ == "__main__":
00013             unittest.main()
00014         '''))

Definition at line 40 of file builder.py.

tuple kss.demo.selenium_utils.builder.variable_regexp = re.compile('\$\{(?P<varname>\w*)\}')

Definition at line 55 of file builder.py.