Modified:
branches/0.9.2-dev/twill/setup.py
branches/0.9.2-dev/twill/tests/__init__.py
branches/0.9.2-dev/twill/tests/test-form.py
branches/0.9.2-dev/twill/tests/test-form.twill
branches/0.9.2-dev/twill/tests/twilltestserver.py
branches/0.9.2-dev/twill/twill/commands.py
branches/0.9.2-dev/twill/twill/utils.py
Log:
fix and tests for #45, the weird checkbox/list thing
Modified: branches/0.9.2-dev/twill/setup.py
==============================================================================
--- branches/0.9.2-dev/twill/setup.py (original)
+++ branches/0.9.2-dev/twill/setup.py Fri Apr 10 07:05:41 2009
@@ -10,13 +10,13 @@
setup(name = 'twill',
- version = '0.9',
+ version = '0.9.2',
download_url = 'http://darcs.idyll.org/~t/projects/twill-0.9.tar.gz',
description = 'twill Web browsing language',
author = 'C. Titus Brown',
author_email = 'ti...@idyll.org',
- license='MIT',
+ license='BSD',
packages = ['twill', 'twill.other_packages',
'twill.other_packages._mechanize_dist',
@@ -28,7 +28,7 @@
scripts = ['twill-fork'],
maintainer = 'C. Titus Brown',
- maintainer_email = 'ti...@caltech.edu',
+ maintainer_email = 'ti...@idyll.org',
url = 'http://twill.idyll.org/',
long_description = """\
@@ -39,7 +39,7 @@
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
- 'License :: OSI Approved :: MIT License',
+ 'License :: OSI Approved :: New BSD License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
Modified: branches/0.9.2-dev/twill/tests/__init__.py
==============================================================================
--- branches/0.9.2-dev/twill/tests/__init__.py (original)
+++ branches/0.9.2-dev/twill/tests/__init__.py Fri Apr 10 07:05:41 2009
@@ -1,19 +1,28 @@
+from twill import commands as tc
+
import twilltestlib
import twilltestserver
def setup(package):
twilltestlib.cd_testdir()
twilltestlib.run_server(twilltestserver.create_publisher)
-
+ print "started server"
url = twilltestlib.get_url()
-
- from twill.commands import go, find
- try:
- go(url)
- find("These are the twill tests")
- except:
- raise Exception("\n\n***\n\nHello! The twill test server is not
running or cannot be reached; please free port 8080 (or set TWILL_TEST_PORT
to something else), and clear your proxy settings too!\n\n***\n\n")
+
+ from twill.commands import go, find, show
+
+ tc.go(url)
+ tc.show()
+
+ # try:
+ # tc.go(url)
+ # tc.show()
+ # # find("These are the twill tests")
+ # # omg, ctb, except WHAT?!
+ # except:
+ # raise Exception("\n\n***\n\nHello! The twill test server is not
running or cannot be reached; please free port 8080 (or set TWILL_TEST_PORT
to something else), and clear your proxy settings too!\n\n***\n\n")
def teardown(package):
twilltestlib.kill_server()
+ print "killed server"
twilltestlib.pop_testdir()
Modified: branches/0.9.2-dev/twill/tests/test-form.py
==============================================================================
--- branches/0.9.2-dev/twill/tests/test-form.py (original)
+++ branches/0.9.2-dev/twill/tests/test-form.py Fri Apr 10 07:05:41 2009
@@ -60,8 +60,6 @@
except Exception:
pass
- commands.go('http://www.google.com/')
- browser.get_title()
# test the twill script.
twilltestlib.execute_twill_script('test-form.twill', initial_url=url)
Modified: branches/0.9.2-dev/twill/tests/test-form.twill
==============================================================================
--- branches/0.9.2-dev/twill/tests/test-form.twill (original)
+++ branches/0.9.2-dev/twill/tests/test-form.twill Fri Apr 10 07:05:41 2009
@@ -9,7 +9,7 @@
go /testform
-# first test selecting by ID...
+# test select by id
fv the_form some_id value
# OK, reset
@@ -117,15 +117,19 @@
#
# ...and checkbox can be set to True.
#
-
+echo 'this is the problem'
+show
fv 1 checkboxtest True
submit
+show
find "CHECKBOXTEST: ==True=="
+echo 'made it to second test'
fv 1 checkboxtest 1
submit
find "CHECKBOXTEST: ==True=="
+echo 'made it to third test'
fv 1 checkboxtest -1
submit
find "CHECKBOXTEST: ==True=="
@@ -151,6 +155,21 @@
submit
find "CHECKBOXTEST: ==False=="
+#
+# test checkboxen in lists
+#
+
+go /checkboxen_with_lists_pos
+fv 1 checkboxen foo
+submit
+find "CHECKBOXEN: ==foo=="
+
+go /checkboxen_with_lists_neg
+fv 1 checkboxen foo
+showforms
+submit
+show
+find "CHECKBOXEN: ==foo=="
###
no_require
Modified: branches/0.9.2-dev/twill/tests/twilltestserver.py
==============================================================================
--- branches/0.9.2-dev/twill/tests/twilltestserver.py (original)
+++ branches/0.9.2-dev/twill/tests/twilltestserver.py Fri Apr 10 07:05:41
2009
@@ -96,7 +96,8 @@
"test_checkboxes", 'test_global_form',
'tidy_fixable_html', 'BS_fixable_html', 'unfixable_html',
'effed_up_forms', 'effed_up_forms2', 'broken_linktext',
- 'exit', 'display_post', 'display_environ']
+ 'exit', 'display_post', 'display_environ',
+ 'checkboxen_with_lists_pos', 'checkboxen_with_lists_neg']
def test_global_form(self):
return """
@@ -304,8 +305,8 @@
image_submit)
def simpleform(self):
- """
- no submit button...
+ """no submit button...
+ used in test-basic.twill
"""
request = get_request()
@@ -315,6 +316,9 @@
return "%s %s <form method=POST><input type=text name=n><input
type=text name=n2></form>" % (w1.parse(request), w2.parse(request),)
def multisubmitform(self):
+ """ form with multiple submit buttons (with different names).
+ used in test-back, test-multisub, and test-unit-support.
+ """
request = get_request()
submit1 = widget.SubmitWidget('sub_a', value='sub_a')
@@ -343,6 +347,8 @@
submit2.render())
def testformaction(self):
+ """used in test-form.twill.
+ """
request = get_request()
keys = [ k for k in request.form.keys() if request.form[k] ]
@@ -351,6 +357,8 @@
return "==" + " AND ".join(keys) + "=="
def testform(self):
+ """selecty box and text inputs. used in test-form and
test-formfill.
+ """
request = get_request()
s = ""
@@ -465,6 +473,53 @@
</form>
""" % (s,)
+ def checkboxen_with_lists_pos(self):
+ request = get_request()
+
+ s = ""
+ if request.form and request.form.has_key('checkboxen'):
+ val = request.form['checkboxen']
+
+ if not isinstance(val, str):
+ val = val[0]
+
+ s += "CHECKBOXEN: ==%s==" % val
+
+ return """
+ %s
+ <p></p>
+ <form method=POST>
+ <ul>
+ <li><input type="checkbox" name="checkboxen" value="foo"
/></li>
+ <li><input type="checkbox" name="checkboxen" value="bar"
/></li>
+ </ul>
+ <input type="submit" value="post">
+ </form>
+ """ % (s,)
+
+ def checkboxen_with_lists_neg(self):
+ request = get_request()
+
+ s = ""
+ if request.form and request.form.has_key('checkboxen'):
+ val = request.form['checkboxen']
+
+ if not isinstance(val, str):
+ val = val[0]
+
+ s += "CHECKBOXEN: ==%s==" % val
+
+ return """
+ %s
+ <p></p>
+ <form method=POST>
+ <ul>
+ <li><input type="checkbox" name="checkboxen" value="foo"
/></li>
+ </ul>
+ <input type="submit" value="post">
+ </form>
+ """ % (s,)
+
def formpostredirect(self):
"""
Test redirect after a form POST. This tests a specific bug in
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 Fri Apr 10 07:05:41 2009
@@ -348,7 +348,7 @@
"""
>> showlinks
- Show all of the links on the current page.
+ Show a list of all the links on the current page.
"""
browser.showlinks()
return list(browser._browser.links())
Modified: branches/0.9.2-dev/twill/twill/utils.py
==============================================================================
--- branches/0.9.2-dev/twill/twill/utils.py (original)
+++ branches/0.9.2-dev/twill/twill/utils.py Fri Apr 10 07:05:41 2009
@@ -100,9 +100,7 @@
print>>OUT, ''
def make_boolean(value):
- """
- Convert the input value into a boolean like so:
-
+ """Convert the input value into a boolean like so:
>> make_boolean('true')
True
>> make_boolean('false')
@@ -153,22 +151,25 @@
if isinstance(control, ClientForm.CheckboxControl):
try:
checkbox = control.get()
- checkbox.selected = make_boolean(val)
+ if val == checkbox.attrs['value']:
+ checkbox.selected = True
+ else:
+ checkbox.selected = make_boolean(val)
return
except ClientForm.AmbiguityError:
# if there's more than one checkbox, use the behaviour for
# ClientForm.ListControl, below.
pass
-
+
+
if isinstance(control, ClientForm.ListControl):
#
# for ListControls (checkboxes, multiselect, etc.) we first need
# to find the right *value*. Then we need to set it +/-.
#
-
+
# figure out if we want to *select* it, or if we want to *deselect*
# it (flag T/F). By default (no +/-) select...
-
if val.startswith('-'):
val = val[1:]
flag = False
@@ -219,7 +220,7 @@
"""
Check whether all these controls are actually the the same
checkbox.
-
+
Hidden controls can combine with checkboxes, to allow form
processors to ensure a False value is returned even if user
does not check the checkbox. Without the hidden control, no
@@ -251,15 +252,15 @@
def run_tidy(html):
"""
Run the 'tidy' command-line program on the given HTML string.
-
+
Return a 2-tuple (output, errors). (None, None) will be returned if
'tidy' doesn't exist or otherwise fails.
"""
global _tidy_cmd, _tidy_exists
-
+
from commands import _options
require_tidy = _options.get('require_tidy')
-
+
if not _tidy_exists:
if require_tidy:
raise TwillException("tidy does not exist and require_tidy is
set")
@@ -278,22 +279,22 @@
shell=False)
(stdout, stderr) = process.communicate(html)
-
+
clean_html = stdout
errors = stderr
except OSError:
_tidy_exists = False
-
+
errors = None
if require_tidy and clean_html is None:
raise TwillException("tidy does not exist and require_tidy is set")
-
+
return (clean_html, errors)
class ConfigurableParsingFactory(mechanize.Factory):
"""
A factory that listens to twill config options regarding parsing.
-
+
First: clean up passed-in HTML using tidy?
Second: parse using the regular parser, or BeautifulSoup?
Third: should we fail on, or ignore, parse errors?
@@ -302,74 +303,75 @@
def __init__(self):
self.basic_factory = mechanize.DefaultFactory()
self.soup_factory = mechanize.RobustFactory()
-
+
self.set_response(None)
-
+
def set_request_class(self, request_class):
self.basic_factory.set_request_class(request_class)
self.soup_factory.set_request_class(request_class)
-
+
def set_response(self, response):
if not response:
self.factory = None
self._orig_html = self._html = self._url = None
return
-
+
###
-
+
if self.use_BS():
self.factory = self.soup_factory
else:
self.factory = self.basic_factory
cleaned_response = self._cleanup_html(response)
self.factory.set_response(cleaned_response)
-
+
def links(self):
return self.factory.links()
def forms(self):
return self.factory.forms()
-
+
def get_global_form(self):
return self.factory.global_form
global_form = property(get_global_form)
-
+
def _get_title(self):
return self.factory.title
title = property(_get_title)
-
+
def _get_encoding(self):
return self.factory.encoding
encoding = property(_get_encoding)
-
+
def _get_is_html(self):
return self.factory.is_html
is_html = property(_get_is_html)
-
+
def _cleanup_html(self, response):
response.seek(0)
self._orig_html = response.read()
self._url = response.geturl()
response.seek(0)
-
+
self._html = self._orig_html
-
+
from twill.commands import _options
use_tidy = _options.get('use_tidy')
if use_tidy:
(new_html, errors) = run_tidy(self._html)
if new_html:
self._html = new_html
-
+
return mechanize.make_response(self._html,
response._headers.items(),
response._url, response.code,
response.msg)
-
+
def use_BS(self):
from twill.commands import _options
flag = _options.get('use_BeautifulSoup')
-
+
return flag
+
###