Ejemplo n.º 1
0
    def _verify_outputs( self, testdef, history, jobs, shed_tool_id, data_list, data_collection_list, galaxy_interactor ):
        assert len(jobs) == 1, "Test framework logic error, somehow tool test resulted in more than one job."
        job = jobs[ 0 ]

        maxseconds = testdef.maxseconds
        if testdef.num_outputs is not None:
            expected = testdef.num_outputs
            actual = len( data_list )
            if expected != actual:
                messaage_template = "Incorrect number of outputs - expected %d, found %s."
                message = messaage_template % ( expected, actual )
                raise Exception( message )
        found_exceptions = []

        def register_exception(e):
            if not found_exceptions:
                # Only print this stuff out once.
                for stream in ['stdout', 'stderr']:
                    if stream in job_stdio:
                        print >>sys.stderr, self._format_stream( job_stdio[ stream ], stream=stream, format=True )
            found_exceptions.append(e)

        if testdef.expect_failure:
            if testdef.outputs:
                raise Exception("Cannot specify outputs in a test expecting failure.")

        # Wait for the job to complete and register expections if the final
        # status was not what test was expecting.
        job_failed = False
        try:
            galaxy_interactor.wait_for_job( job[ 'id' ], history, maxseconds )
        except Exception as e:
            job_failed = True
            if not testdef.expect_failure:
                found_exceptions.append(e)

        job_stdio = galaxy_interactor.get_job_stdio( job[ 'id' ] )

        if not job_failed and testdef.expect_failure:
            error = AssertionError("Expected job to fail but Galaxy indicated the job successfully completed.")
            register_exception(error)

        expect_exit_code = testdef.expect_exit_code
        if expect_exit_code is not None:
            exit_code = job_stdio["exit_code"]
            if str(expect_exit_code) != str(exit_code):
                error = AssertionError("Expected job to complete with exit code %s, found %s" % (expect_exit_code, exit_code))
                register_exception(error)

        for output_index, output_tuple in enumerate(testdef.outputs):
            # Get the correct hid
            name, outfile, attributes = output_tuple
            output_testdef = bunch.Bunch( name=name, outfile=outfile, attributes=attributes )
            try:
                output_data = data_list[ name ]
            except (TypeError, KeyError):
                # Legacy - fall back on ordered data list access if data_list is
                # just a list (case with twill variant or if output changes its
                # name).
                if hasattr(data_list, "values"):
                    output_data = data_list.values()[ output_index ]
                else:
                    output_data = data_list[ len(data_list) - len(testdef.outputs) + output_index ]
            self.assertTrue( output_data is not None )
            try:
                galaxy_interactor.verify_output( history, jobs, output_data, output_testdef=output_testdef, shed_tool_id=shed_tool_id, maxseconds=maxseconds )
            except Exception as e:
                register_exception(e)

        other_checks = {
            "command_line": "Command produced by the job",
            "stdout": "Standard output of the job",
            "stderr": "Standard error of the job",
        }
        for what, description in other_checks.items():
            if getattr( testdef, what, None ) is not None:
                try:
                    data = job_stdio[what]
                    verify_assertions( data, getattr( testdef, what ) )
                except AssertionError, err:
                    errmsg = '%s different than expected\n' % description
                    errmsg += str( err )
                    register_exception( AssertionError( errmsg ) )
Ejemplo n.º 2
0
    def _verify_outputs(self, testdef, history, jobs, shed_tool_id, data_list,
                        data_collection_list, galaxy_interactor):
        assert len(
            jobs
        ) == 1, "Test framework logic error, somehow tool test resulted in more than one job."
        job = jobs[0]

        maxseconds = testdef.maxseconds
        if testdef.num_outputs is not None:
            expected = testdef.num_outputs
            actual = len(data_list)
            if expected != actual:
                messaage_template = "Incorrect number of outputs - expected %d, found %s."
                message = messaage_template % (expected, actual)
                raise Exception(message)
        found_exceptions = []

        def register_exception(e):
            if not found_exceptions:
                # Only print this stuff out once.
                for stream in ['stdout', 'stderr']:
                    if stream in job_stdio:
                        print >> sys.stderr, self._format_stream(
                            job_stdio[stream], stream=stream, format=True)
            found_exceptions.append(e)

        if testdef.expect_failure:
            if testdef.outputs:
                raise Exception(
                    "Cannot specify outputs in a test expecting failure.")

        # Wait for the job to complete and register expections if the final
        # status was not what test was expecting.
        job_failed = False
        try:
            galaxy_interactor.wait_for_job(job['id'], history, maxseconds)
        except Exception as e:
            job_failed = True
            if not testdef.expect_failure:
                found_exceptions.append(e)

        job_stdio = galaxy_interactor.get_job_stdio(job['id'])

        if not job_failed and testdef.expect_failure:
            error = AssertionError(
                "Expected job to fail but Galaxy indicated the job successfully completed."
            )
            register_exception(error)

        expect_exit_code = testdef.expect_exit_code
        if expect_exit_code is not None:
            exit_code = job_stdio["exit_code"]
            if str(expect_exit_code) != str(exit_code):
                error = AssertionError(
                    "Expected job to complete with exit code %s, found %s" %
                    (expect_exit_code, exit_code))
                register_exception(error)

        for output_index, output_tuple in enumerate(testdef.outputs):
            # Get the correct hid
            name, outfile, attributes = output_tuple
            output_testdef = bunch.Bunch(name=name,
                                         outfile=outfile,
                                         attributes=attributes)
            try:
                output_data = data_list[name]
            except (TypeError, KeyError):
                # Legacy - fall back on ordered data list access if data_list is
                # just a list (case with twill variant or if output changes its
                # name).
                if hasattr(data_list, "values"):
                    output_data = data_list.values()[output_index]
                else:
                    output_data = data_list[len(data_list) -
                                            len(testdef.outputs) +
                                            output_index]
            self.assertTrue(output_data is not None)
            try:
                galaxy_interactor.verify_output(history,
                                                jobs,
                                                output_data,
                                                output_testdef=output_testdef,
                                                shed_tool_id=shed_tool_id,
                                                maxseconds=maxseconds)
            except Exception as e:
                register_exception(e)

        other_checks = {
            "command_line": "Command produced by the job",
            "stdout": "Standard output of the job",
            "stderr": "Standard error of the job",
        }
        for what, description in other_checks.items():
            if getattr(testdef, what, None) is not None:
                try:
                    data = job_stdio[what]
                    verify_assertions(data, getattr(testdef, what))
                except AssertionError, err:
                    errmsg = '%s different than expected\n' % description
                    errmsg += str(err)
                    register_exception(AssertionError(errmsg))