From 72e7836cbb625b8a4c895335873e373226cb5d3d Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Wed, 17 Feb 2010 11:07:08 -0500 Subject: [PATCH] Enhance functional test framework so that a boolean form field ( checkbox ) can have a false value ( be unchecked ). Add a 2nd test to gops_concat that uses this behavior. --- .../{gops-concat.dat => gops_concat_out1.bed} | 0 test/base/twilltestcase.py | 24 +++++++++++++++++-- tools/new_operations/concat.xml | 10 ++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) rename test-data/{gops-concat.dat => gops_concat_out1.bed} (100%) diff --git a/test-data/gops-concat.dat b/test-data/gops_concat_out1.bed similarity index 100% rename from test-data/gops-concat.dat rename to test-data/gops_concat_out1.bed diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py index c560ac3ed06..c93d2187be2 100644 --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -857,8 +857,28 @@ class TwillTestCase( unittest.TestCase ): elif control.is_of_kind( "list" ): try: if control.is_of_kind( "multilist" ): - for elem in control_value: - control.get( name=elem ).selected = True + if control.type == "checkbox": + def is_checked( value ): + # Copied from form_builder.CheckboxField + if value == True: + return True + if isinstance( value, basestring ) and value.lower() in ( "yes", "true", "on" ): + return True + # This may look strange upon initial inspection, but see the comments in the get_html() method + # above for clarification. Basically, if value is not True, then it will always be a list with + # 2 input fields ( a checkbox and a hidden field ) if the checkbox is checked. If it is not + # checked, then value will be only the hidden field. + return isinstance( value, list ) and len( value ) == 2 + try: + checkbox = control.get() + checkbox.selected = is_checked( control_value ) + except ClientForm.AmbiguityError: + # if there's more than one checkbox, use the behaviour for + # ClientForm.ListControl - see twill code.. + pass + else: + for elem in control_value: + control.get( name=elem ).selected = True else: # control.is_of_kind( "singlelist" ) for elem in control_value: tc.fv( f.name, control.name, str( elem ) ) diff --git a/tools/new_operations/concat.xml b/tools/new_operations/concat.xml index 8a62466a4af..e2099fb5e9c 100644 --- a/tools/new_operations/concat.xml +++ b/tools/new_operations/concat.xml @@ -20,8 +20,14 @@ - - + + + + + + + +