Added:
branches/0.9.2-dev/twill/tests/script-tests/
branches/0.9.2-dev/twill/tests/script-tests/neverfail-inheritance-child.twill
branches/0.9.2-dev/twill/tests/script-tests/neverfail-inheritance-parent.twill
Modified:
branches/0.9.2-dev/twill/tests/test-misc.py
branches/0.9.2-dev/twill/twill/commands.py
branches/0.9.2-dev/twill/twill/extensions/csv_iterate.py
branches/0.9.2-dev/twill/twill/parse.py
Log:
fixed failure of runfile to inherit --never-fail; associated tests.
See issue #31.
Added:
branches/0.9.2-dev/twill/tests/script-tests/neverfail-inheritance-child.twill
==============================================================================
--- (empty file)
+++
branches/0.9.2-dev/twill/tests/script-tests/neverfail-inheritance-child.twill
Sun Apr 12 08:08:38 2009
@@ -0,0 +1,2 @@
+# generate failure
+run "assert 0, 'foo'"
\ No newline at end of file
Added:
branches/0.9.2-dev/twill/tests/script-tests/neverfail-inheritance-parent.twill
==============================================================================
--- (empty file)
+++
branches/0.9.2-dev/twill/tests/script-tests/neverfail-inheritance-parent.twill
Sun Apr 12 08:08:38 2009
@@ -0,0 +1,2 @@
+# test inheritance of '--never-fail' from command-line args thru runfile.
+runfile script-tests/neverfail-inheritance-child.twill
Modified: branches/0.9.2-dev/twill/tests/test-misc.py
==============================================================================
--- branches/0.9.2-dev/twill/tests/test-misc.py (original)
+++ branches/0.9.2-dev/twill/tests/test-misc.py Sun Apr 12 08:08:38 2009
@@ -95,5 +95,9 @@
twill.commands.run("print 'hello'")
+def test_inheritance():
+
twill.parse.execute_file('script-tests/neverfail-inheritance-parent.twill',
+ never_fail=True)
+
def teardown_module():
pass
Modified: branches/0.9.2-dev/twill/twill/commands.py
==============================================================================
--- branches/0.9.2-dev/twill/twill/commands.py (original)
+++ branches/0.9.2-dev/twill/twill/commands.py Sun Apr 12 08:08:38 2009
@@ -595,8 +595,14 @@
import parse
global_dict, local_dict = get_twill_glocals()
+ # inherit things like 'never_fail'; override others.
+ parent_execute_params = local_dict.get('__execute_parameters__', {})
+ params = dict(parent_execute_params) # copy
+ params['no_reset'] = True
+ params.pop('initial_url', None) # get rid of initial_url
+
for f in files:
- parse.execute_file(f, no_reset=True)
+ parse.execute_file(f, **params)
def setglobal(name, value):
"""
Modified: branches/0.9.2-dev/twill/twill/extensions/csv_iterate.py
==============================================================================
--- branches/0.9.2-dev/twill/twill/extensions/csv_iterate.py (original)
+++ branches/0.9.2-dev/twill/twill/extensions/csv_iterate.py Sun Apr 12
08:08:38 2009
@@ -19,10 +19,18 @@
For each line in <csv_file>, read in a list of comma-separated values,
put them in $col1...$colN, and execute <script>.
"""
+ # @CTB test that execute_script kwargs like never-fail get inherited.
+
from twill import namespaces, execute_file, commands
global_dict, local_dict = namespaces.get_twill_glocals()
+ # inherit things like 'never_fail'; override others.
+ parent_execute_params = local_dict.get('__execute_parameters__', {})
+ params = dict(parent_execute_params) # copy
+ params['no_reset'] = True
+ params.pop('initial_url', None) # get rid of initial_url
+
reader = csv.reader(open(filename, "rb"))
for i, row in enumerate(reader):
if DEBUG:
@@ -30,4 +38,4 @@
for i, col in enumerate(row):
global_dict["col%d" % (i + 1,)] = col
- execute_file(scriptname, no_reset=True)
+ execute_file(scriptname, **params)
Modified: branches/0.9.2-dev/twill/twill/parse.py
==============================================================================
--- branches/0.9.2-dev/twill/twill/parse.py (original)
+++ branches/0.9.2-dev/twill/twill/parse.py Sun Apr 12 08:08:38 2009
@@ -164,6 +164,9 @@
def execute_file(filename, **kw):
"""
Execute commands from a file.
+
+ Takes same keyword arguments as _execute_script, with the exception of
+ 'source', which is overriden to be the name of the source file.
"""
# read the input lines
if filename == "-":
@@ -178,11 +181,18 @@
def _execute_script(inp, **kw):
"""
Execute lines taken from a file-like iterator.
+
+ Keyword arguments and defaults:
+ - no_reset=False; do reset the browser for each script.
+ - initial_url; load the given URL before anything else.
+ - never_fail=False; trap errors and don't allow failures to
percolate.
+ - source='<input>'; filename of source file (used for error
reporting).
"""
# initialize new local dictionary & get global + current local
namespaces.new_local_dict()
globals_dict, locals_dict = namespaces.get_twill_glocals()
-
+
+ locals_dict['__execute_parameters__'] = kw
locals_dict['__url__'] = commands.browser.get_url()
# reset browser