[Checkins] SVN: gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py refactor to ease testing

Godefroid Chapelle gotcha at bubblenet.be
Tue Jan 4 09:52:06 EST 2011


Log message for revision 119347:
  refactor to ease testing

Changed:
  U   gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py

-=-
Modified: gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py
===================================================================
--- gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py	2011-01-04 14:36:22 UTC (rev 119346)
+++ gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py	2011-01-04 14:52:06 UTC (rev 119347)
@@ -95,32 +95,41 @@
     return options, directory
 
 
-def main():
-    parser = make_parser()
-    options, directory = parse_options(parser)
-    tests = []
+def parse_directory(directory, verbose):
     pattern = os.path.join(directory, '*.html')
     for filename in glob.glob(pattern):
+        if verbose:
+            print "Parsing [%s]" % filename
         filename = os.path.abspath(filename)
-        if options.verbose:
-            print "Parsing [%s]" % filename
-        tree = HTMLTreeBuilder.parse(filename)
-        root = tree.getroot()
-
-        try:
-            testname = root.find('.//title').text
-        except AttributeError:
+        testname, commands = parse_file(filename)
+        if testname is None:
             continue
-        commands = []
-        for row in root.findall('.//tbody/tr'):
-            command = formatcommand(*[td.text for td in row.findall('td')])
-            commands.append(command)
-
         method_body = method_body_template.substitute(dict(
             testname=testname,
             commands='\n'.join(commands)))
-        tests.append(method_body)
+        yield method_body
 
+
+def parse_file(filename):
+    tree = HTMLTreeBuilder.parse(filename)
+    root = tree.getroot()
+
+    try:
+        testname = root.find('.//title').text
+    except AttributeError:
+        return None, None
+    commands = []
+    for row in root.findall('.//tbody/tr'):
+        command = formatcommand(*[td.text for td in row.findall('td')])
+        commands.append(command)
+    return testname, commands
+
+
+def main():
+    parser = make_parser()
+    options, directory = parse_options(parser)
+    tests = parse_directory(directory, options.verbose)
+
     target = os.path.abspath(options.target)
     if options.verbose:
         print "Generating [%s]" % target



More information about the checkins mailing list