1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/f6bc826d0ec2/ changeset: f6bc826d0ec2 user: carlfeberhard date: 2013-03-12 18:28:58 summary: browser tests: better parsing of environ vars, prevent subprocess hanging, allow setting debug flags via environ var affected #: 3 files
diff -r d8009117d5a0af02767c27162a2d5bd3befb9b5d -r f6bc826d0ec20da52746e0703774175e835aee94 test/casperjs/casperjs_runner.py --- a/test/casperjs/casperjs_runner.py +++ b/test/casperjs/casperjs_runner.py @@ -47,6 +47,7 @@ _TODO = """ get data back from js scripts (uploaded files, etc.) use returned json to output list of failed assertions if code == 2 + better way to turn debugging on from the environment """
# ==================================================================== @@ -72,7 +73,7 @@ debug = False # bit of a hack - this is the beginning of the last string when capserjs --verbose=true --logLevel=debug # use this to get subprocess to stop waiting for output - casper_done_str = '[info] [phantom] Done' + casper_done_str = '# Tests complete'
# convert js test results to unittest.TestResults results_adapter = None #CasperJsonToUnittestResultsConverter() @@ -140,8 +141,11 @@ command_line_list.append( '--return-json' )
# check flag to output (very) verbose debugging messages from casperjs and tests - if self.debug: + #NOTE: this can be set in the class or by using the debug_these_tests flag in server_env + if( ( self.debug ) + or ( rel_script_path in self.env.debug_these_tests ) ): command_line_list.extend([ '--verbose=true', '--logLevel=debug' ]) + #TODO: add capture, html output flags
#TODO: allow casperjs cli options ('--includes='), ?in args, kwargs? command_line_list.extend( args ) @@ -297,16 +301,15 @@ class Test_01_User( CasperJSTestCase ): """TestCase that uses javascript and a headless browser to test dynamic pages. """ - #debug = True def test_10_registration( self ): """User registration tests: register new user, logout, attempt bad registrations. """ # all keywords will be compiled into a single JSON obj and passed to the server #self.run_js_script( 'registration-tests.js', + # testUser=test_user ) # # this causes a time out in history-panel-tests: why? # # also: I can't seem to bump the timeout to an error (using a handler) - causes script to hang # # removing for the sake of bbot - # testUser=test_user ) self.run_js_script( 'registration-tests.js' )
#TODO:?? could theoretically do db cleanup, checks here with SQLALX @@ -321,7 +324,6 @@ class Test_02_Tools( CasperJSTestCase ): """(Minimal) casperjs tests for tools. """ - #debug = True def test_10_upload( self ): """Tests uploading files """ @@ -331,7 +333,6 @@ class Test_03_HistoryPanel( CasperJSTestCase ): """(Minimal) casperjs tests for tools. """ - #debug = True def test_00_history_panel( self ): """Test history panel basics (controls, structure, refresh, history options menu, etc.). """ @@ -347,6 +348,8 @@ # ==================================================================== MAIN if __name__ == '__main__': log.setLevel( logging.DEBUG ) + from server_env import log as server_env_log + server_env_log.setLevel( logging.DEBUG ) setup_module() #TODO: server_env config doesn't work with unittest's lame main fn unittest.main()
diff -r d8009117d5a0af02767c27162a2d5bd3befb9b5d -r f6bc826d0ec20da52746e0703774175e835aee94 test/casperjs/server_env.py --- a/test/casperjs/server_env.py +++ b/test/casperjs/server_env.py @@ -22,6 +22,7 @@ ENV_FILE_DIR = 'GALAXY_TEST_FILE_DIR' ENV_TOOL_SHED_TEST_FILE = 'GALAXY_TOOL_SHED_TEST_FILE' ENV_SAVED_FILES_DIR = 'GALAXY_TEST_SAVE' # AKA: twilltestcase.keepOutdir + ENV_DEBUG_THESE_TESTS = 'GALAXY_DEBUG_THESE_TESTS'
DEFAULT_PROTOCOL = 'http' DEFAULT_HOST = 'localhost' @@ -33,8 +34,7 @@ does not yet exist. """ # singleton pattern - if( ( not cls._instance ) - or ( config ) ): + if not cls._instance: log.debug( 'creating singleton instance of "%s", config: %s', str( cls ), str( config ) ) cls._instance = cls( config ) return cls._instance @@ -43,60 +43,93 @@ self.config = env_config_dict or {}
self.protocol = self._get_setting_from_config_or_env( - 'protocol', self.ENV_PROTOCOL, self.DEFAULT_PROTOCOL ) + 'protocol', self.ENV_PROTOCOL, self.DEFAULT_PROTOCOL ) #TODO: required=True ) self.host = self._get_setting_from_config_or_env( - 'host', self.ENV_HOST, self.DEFAULT_HOST ) + 'host', self.ENV_HOST, self.DEFAULT_HOST ) #TODO: required=True ) self.port = self._get_setting_from_config_or_env( - 'port', self.ENV_PORT, self.DEFAULT_PORT ) + 'port', self.ENV_PORT, self.DEFAULT_PORT ) #TODO: required=True )
+ #TODO: move these setters/init'rs into a parser dict self.history_id = self._get_setting_from_config_or_env( - 'history_id', self.ENV_HISTORY_ID, default=None ) + 'history_id', self.ENV_HISTORY_ID ) self.file_dir = self._get_setting_from_config_or_env( - 'file_dir', self.ENV_FILE_DIR, default=None ) - + 'file_dir', self.ENV_FILE_DIR ) self.tool_shed_test_file = self._get_setting_from_config_or_env( - 'tool_shed_test_file', self.ENV_TOOL_SHED_TEST_FILE, default=None ) + 'tool_shed_test_file', self.ENV_TOOL_SHED_TEST_FILE ) self.shed_tools_dict = self._get_shed_tools_dict()
+ # saved output goes here: test diffs, screenshots, html, etc. self.saved_output_dir = self._get_setting_from_config_or_env( - 'saved_output_dir', self.ENV_SAVED_FILES_DIR, default=None ) - self._init_saved_files_dir() + 'saved_output_dir', self.ENV_SAVED_FILES_DIR ) + self._create_saved_output_dir()
- def _get_setting_from_config_or_env( self, config_name, env_name, default=False ): + # if a test script (e.g. 'history-panel-tests.js') is listed in this var, + # the test will output additional/full debug info + self.debug_these_tests = self._get_setting_from_config_or_env( + 'debug_these_tests', self.ENV_DEBUG_THESE_TESTS ) + self._parse_debug_these_tests() + + log.debug( 'server_env: %s', str( self.as_dict() ) ) + + def as_dict( self, attributes=None ): + if not attributes: + #TODO:?? raise to class scope? + attributes = [ 'protocol', 'host', 'port', 'history_id', 'file_dir', + 'tool_shed_test_file', 'shed_tools_dict', 'saved_output_dir', 'debug_these_tests' ] + this_dict = {} + for attr_name in attributes: + attr_val = getattr( self, attr_name ) + this_dict[ attr_name ] = attr_val + return this_dict + + def _get_setting_from_config_or_env( self, config_name, env_name, default=None ): """Try to get a setting from (in order): TestEnvironment.config, the os env, or some default (if not False). """ - #TODO: if falsy value needed, use None - not ideal - config = self.config.get( config_name, None ) - env = os.environ.get( env_name, None ) - if( ( not ( config or env ) ) - and ( default == False ) ): - raise AttributeError( '"%s" was not set via config or %s or default' %( config_name, env_name ) ) - return config or env or default + config_val = self.config.get( config_name, None ) + env_val = os.environ.get( env_name, None ) + return config_val or env_val or default
def _get_shed_tools_dict( self ): """Read the shed tools from the tool shed test file if given, otherwise an empty dict. """ + shed_tools_dict = {} if self.tool_shed_test_file: - f = open( self.tool_shed_test_file, 'r' ) - text = f.read() - f.close() - return from_json_string( text ) - else: - return {} + try: + f = open( self.tool_shed_test_file, 'r' ) + text = f.read() + f.close() + shed_tools_dict = from_json_string( text ) + except Exception, exc: + log.error( 'Error reading tool shed test file "%s": %s', self.tool_shed_test_file, exc, exc_info=True )
- def _init_saved_files_dir( self ): + return shed_tools_dict + + def _create_saved_output_dir( self ): """Set up the desired directory to save test output. """ - if self.saved_output_dir > '': + if self.saved_output_dir: try: - os.makedirs( self.saved_output_dir ) + if not os.path.exists( self.saved_output_dir ): + os.makedirs( self.saved_output_dir ) except Exception, exc: log.error( 'unable to create saved files directory "%s": %s', self.saved_output_dir, exc, exc_info=True ) self.saved_output_dir = None
+ def _parse_debug_these_tests( self, delim=',' ): + """Simple parser for the list of test scripts on which to set debug=True. + """ + debug_list = [] + if self.debug_these_tests: + try: + debug_list = self.debug_these_tests.split( delim ) + except Exception, exc: + log.error( 'unable to parse debug_these_tests "%s": %s', + self.debug_these_tests, exc, exc_info=True ) + self.debug_these_tests = debug_list + @property def url( self ): """Builds and returns the url of the test server.
diff -r d8009117d5a0af02767c27162a2d5bd3befb9b5d -r f6bc826d0ec20da52746e0703774175e835aee94 test/casperjs/spaceghost.js --- a/test/casperjs/spaceghost.js +++ b/test/casperjs/spaceghost.js @@ -432,7 +432,10 @@ var returnCode = ( this.test.testResults.failed )?( 2 ):( 0 );
// if --return-json is used: output json and exit + //NOTE: used by the test runner to gather JSON test info from stdout if( this.options.returnJsonOnly ){ + // echo a string to indicate that tests are complete (used in casperjs_runner.py to stop process) + this.echo( '# Tests complete' ); this.outputStateAsJson(); this.exit( returnCode );
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
galaxy-commits@lists.galaxyproject.org