def test_job_make_test_suite_resolver(self): simple_tests_found = self._find_simple_test_candidates() config = {'references': simple_tests_found, 'base_logdir': self.tmpdir.name, 'test_runner': 'nrunner', 'show': ['none']} self.job = job.Job(config) self.job.setup() self.job.create_test_suite() self.assertEqual(len(simple_tests_found), len(self.job.test_suite)) if self.job.test_suite: self.assertIsInstance(self.job.test_suite[0], nrunner.Task)
def test_job_dryrun(self): config = { "resolver.references": ["/bin/true", "/bin/false"], "run.results_dir": self.tmpdir.name, "run.dry_run.enabled": True, "core.show": ["none"], } suite = TestSuite.from_config(config) self.job = job.Job(config, [suite]) self.job.setup() self.job.run() self.assertEqual(self.job.result.cancelled, 2)
def test_job_run_tests(self): simple_tests_found = self._find_simple_test_candidates(['true']) config = { 'show': ['none'], 'run.results_dir': self.tmpdir.name, 'run.store_logging_stream': [], 'run.references': simple_tests_found } self.job = job.Job(config) self.job.setup() self.job.create_test_suite() self.assertEqual(self.job.run_tests(), exit_codes.AVOCADO_ALL_OK)
def test_job_dryrun_no_base_logdir(self): config = { 'core.show': ['none'], 'run.store_logging_stream': [], 'run.dry_run.enabled': True } self.job = job.Job(config) with self.job: self.assertTrue(os.path.isdir(self.job.logdir)) self.assertTrue(os.path.isfile(os.path.join(self.job.logdir, 'id'))) self.assertFalse(os.path.isdir(self.job.logdir))
def setUp(self): self.tmpfile = tempfile.mkstemp() self.tmpdir = tempfile.mkdtemp() args = argparse.Namespace(json_output=self.tmpfile[1]) stream = _Stream() stream.logfile = 'debug.log' self.test_result = jsonresult.JSONTestResult(stream, args) self.test_result.filename = self.tmpfile[1] self.test_result.start_tests() self.test1 = test.Test(job=job.Job(), base_logdir=self.tmpdir) self.test1.status = 'PASS' self.test1.time_elapsed = 1.23
def test_job_create_test_suite_simple(self): simple_tests_found = self._find_simple_test_candidates() config = { 'show': ['none'], 'run.results_dir': self.tmpdir.name, 'run.store_logging_stream': [], 'run.references': simple_tests_found } self.job = job.Job(config) self.job.setup() self.job.create_test_suite() self.assertEqual(len(simple_tests_found), len(self.job.test_suite))
def test_job_dryrun(self): config = { 'resolver.references': ['/bin/true', '/bin/false'], 'run.results_dir': self.tmpdir.name, 'run.dry_run.enabled': True, 'core.show': ['none'] } suite = TestSuite.from_config(config) self.job = job.Job(config, [suite]) self.job.setup() self.job.run() self.assertEqual(self.job.result.cancelled, 2)
def test_job_self_account_time(self): args = argparse.Namespace(logdir=self.tmpdir) myjob = job.Job(args) myjob.time_start = 10.0 myjob.run() myjob.time_end = 20.0 # forcing a different value to check if it's not being # calculated when time_start or time_end are manually set myjob.time_elapsed = 100.0 self.assertEqual(myjob.time_start, 10.0) self.assertEqual(myjob.time_end, 20.0) self.assertEqual(myjob.time_elapsed, 100.0)
def test_job_run_account_time(self): config = {'core.show': ['none'], 'run.results_dir': self.tmpdir.name, 'run.store_logging_stream': []} self.job = job.Job(config) self.job.setup() # temporarily disable logging on console logging.disable(logging.ERROR) self.job.run() logging.disable(logging.NOTSET) self.assertNotEqual(self.job.time_start, -1) self.assertNotEqual(self.job.time_end, -1) self.assertNotEqual(self.job.time_elapsed, -1)
def test_job_get_failed_tests(self): config = { 'run.references': ['/bin/true', '/bin/false'], 'run.results_dir': self.tmpdir.name, 'run.store_logging_stream': [], 'run.dry_run.enabled': True, 'core.show': ['none'] } suite = TestSuite.from_config(config) self.job = job.Job(config, [suite]) self.job.setup() self.job.run() self.assertEqual(len(self.job.get_failed_tests()), 1)
def test_job_self_account_time(self): config = {'base_logdir': self.tmpdir.name, 'show': ['none']} self.job = job.Job(config) self.job.setup() self.job.time_start = 10.0 self.job.run() self.job.time_end = 20.0 # forcing a different value to check if it's not being # calculated when time_start or time_end are manually set self.job.time_elapsed = 100.0 self.assertEqual(self.job.time_start, 10.0) self.assertEqual(self.job.time_end, 20.0) self.assertEqual(self.job.time_elapsed, 100.0)
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) args = argparse.Namespace() args.xunit_output = self.tmpfile[1] self.test_result = xunit.xUnitTestResult(stream=_Stream(), args=args) self.test_result.start_tests() self.test1 = SimpleTest(job=job.Job(), base_logdir=self.tmpdir) self.test1.status = 'PASS' self.test1.time_elapsed = 1.23
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) args = argparse.Namespace(json_output=self.tmpfile[1]) self.test_result = jsonresult.JSONTestResult(FakeJob(args)) self.test_result.filename = self.tmpfile[1] self.test_result.start_tests() self.test1 = SimpleTest(job=job.Job(), base_logdir=self.tmpdir) self.test1.status = 'PASS' self.test1.time_elapsed = 1.23
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) args = argparse.Namespace(base_logdir=self.tmpdir) args.xunit_output = self.tmpfile[1] self.job = job.Job(args) self.test_result = Result(FakeJob(args)) self.test_result.tests_total = 1 self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir) self.test1._Test__status = 'PASS' self.test1.time_elapsed = 1.23
def new_job(config): """ Produce a new job object and thus a job. :param config: command line arguments :type config: {str, str} """ suite = TestSuite('suite', {}, tests=[], job_config=config) with job.Job(config, [suite]) as job_instance: loader, runner = config["graph"].l, config["graph"].r loader.logdir = job_instance.logdir runner.job = job_instance yield job_instance
def run(self, config): """ Run test modules or simple tests. :param config: Configuration received from command line parser and possibly other sources. :type config: dict """ if 'output_check_record' in config: process.OUTPUT_CHECK_RECORD_MODE = config.get( 'output_check_record', None) warnings.warn( "The following arguments will be changed to boolean soon: " "sysinfo, output-check, failfast, keep-tmp, " "ignore-missing-references, sysinfo and output-check", FutureWarning) if config.get('unique_job_id') is not None: try: int(config.get('unique_job_id'), 16) if len(config.get('unique_job_id')) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: config['job_timeout'] = time_to_seconds(config.get('job_timeout')) except ValueError as detail: LOG_UI.error(detail.args[0]) sys.exit(exit_codes.AVOCADO_FAIL) with job.Job(config) as job_instance: pre_post_dispatcher = JobPrePostDispatcher() try: # Run JobPre plugins output.log_plugin_failures(pre_post_dispatcher.load_failures) pre_post_dispatcher.map_method('pre', job_instance) job_run = job_instance.run() finally: # Run JobPost plugins pre_post_dispatcher.map_method('post', job_instance) result_dispatcher = ResultDispatcher() if result_dispatcher.extensions: result_dispatcher.map_method('render', job_instance.result, job_instance) return job_run
def test_job_self_account_time(self): config = {'core.show': ['none'], 'run.results_dir': self.tmpdir.name} self.job = job.Job(config) self.job.setup() self.job.time_start = 10.0 # temporarily disable logging on console logging.disable(logging.ERROR) self.job.run() logging.disable(logging.NOTSET) self.job.time_end = 20.0 # forcing a different value to check if it's not being # calculated when time_start or time_end are manually set self.job.time_elapsed = 100.0 self.assertEqual(self.job.time_start, 10.0) self.assertEqual(self.job.time_end, 20.0) self.assertEqual(self.job.time_elapsed, 100.0)
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) args = argparse.Namespace() args.xunit_output = self.tmpfile[1] self.test_result = xunit.xUnitTestResult(FakeJob(args)) self.test_result.start_tests() self.test1 = SimpleTest(job=job.Job(), base_logdir=self.tmpdir) self.test1.status = 'PASS' self.test1.time_elapsed = 1.23 unittests_path = os.path.dirname(os.path.abspath(__file__)) self.junit_schema_path = os.path.join(unittests_path, 'junit-4.xsd')
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() prefix = temp_dir_prefix(__name__, self, 'setUp') self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix) args = argparse.Namespace(json_output=self.tmpfile[1], base_logdir=self.tmpdir.name) self.job = job.Job(args) self.test_result = Result(FakeJob(args)) self.test_result.filename = self.tmpfile[1] self.test_result.tests_total = 1 self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir.name) self.test1._Test__status = 'PASS' self.test1.time_elapsed = 1.23
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) args = argparse.Namespace(base_logdir=self.tmpdir) args.xunit_output = self.tmpfile[1] self.job = job.Job(args) self.test_result = Result(FakeJob(args)) self.test_result.tests_total = 1 self.test_result.logfile = ("/.../avocado/job-results/" "job-2018-11-28T16.27-8fef221/job.log") self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir) self.test1._Test__status = 'PASS' self.test1.time_elapsed = 678.23689
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) args = argparse.Namespace(logdir=self.tmpdir) args.xunit_output = self.tmpfile[1] self.job = job.Job(args) self.test_result = Result(FakeJob(args)) self.test_result.tests_total = 1 self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir) self.test1._Test__status = 'PASS' self.test1.time_elapsed = 1.23 self.junit = os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, ".data", 'junit-4.xsd'))
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() prefix = temp_dir_prefix(__name__, self, 'setUp') self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix) config = {'run.results_dir': self.tmpdir.name, 'run.json.output': self.tmpfile[1]} self.job = job.Job(config) self.test_result = Result(UNIQUE_ID, LOGFILE) self.test_result.filename = self.tmpfile[1] self.test_result.tests_total = 1 self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir.name) self.test1._Test__status = 'PASS' self.test1.time_elapsed = 1.23
def run(self, args): """ Run test modules or simple tests. :param args: Command line args received from the run subparser. """ self._activate(args) if args.unique_job_id is not None: try: int(args.unique_job_id, 16) if len(args.unique_job_id) != 40: raise ValueError except ValueError: log = logging.getLogger("avocado.app") log.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) args.job_timeout = self._validate_job_timeout(args.job_timeout) job_instance = job.Job(args) return job_instance.run()
def run(self, args): """ Run test modules or simple tests. :param args: Command line args received from the run subparser. """ self._activate(args) self.view = output.View(app_args=args) if args.unique_job_id is not None: try: int(args.unique_job_id, 16) if len(args.unique_job_id) != 40: raise ValueError except ValueError: self.view.notify(event='error', msg='Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) args.job_timeout = self._validate_job_timeout(args.job_timeout) job_instance = job.Job(args) return job_instance.run()
def run(self, args): """ Run test modules or simple tests. :param args: Command line args received from the run subparser. """ if 'output_check_record' in args: process.OUTPUT_CHECK_RECORD_MODE = getattr(args, 'output_check_record', None) if args.unique_job_id is not None: try: int(args.unique_job_id, 16) if len(args.unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: args.job_timeout = time_to_seconds(args.job_timeout) except ValueError as detail: LOG_UI.error(detail.args[0]) sys.exit(exit_codes.AVOCADO_FAIL) with job.Job(args) as job_instance: pre_post_dispatcher = JobPrePostDispatcher() try: # Run JobPre plugins output.log_plugin_failures(pre_post_dispatcher.load_failures) pre_post_dispatcher.map_method('pre', job_instance) job_run = job_instance.run() finally: # Run JobPost plugins pre_post_dispatcher.map_method('post', job_instance) result_dispatcher = ResultDispatcher() if result_dispatcher.extensions: result_dispatcher.map_method('render', job_instance.result, job_instance) return job_run
def run(self, config): """ Run test modules or simple tests. :param config: Configuration received from command line parser and possibly other sources. :type config: dict """ if 'run.output_check_record' in config: check_record = config.get('run.output_check_record') process.OUTPUT_CHECK_RECORD_MODE = check_record unique_job_id = config.get('run.unique_job_id') if unique_job_id is not None: try: int(unique_job_id, 16) if len(unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: suite = TestSuite.from_config(config, name='') if suite.size == 0: sys.exit(exit_codes.AVOCADO_JOB_FAIL) except TestSuiteError as err: LOG_UI.error(err) sys.exit(exit_codes.AVOCADO_JOB_FAIL) with job.Job(config, [suite]) as job_instance: pre_post_dispatcher = JobPrePostDispatcher() try: # Run JobPre plugins output.log_plugin_failures(pre_post_dispatcher.load_failures) pre_post_dispatcher.map_method('pre', job_instance) job_run = job_instance.run() finally: # Run JobPost plugins pre_post_dispatcher.map_method('post', job_instance) return job_run
def setUp(self): class SimpleTest(Test): def test(self): pass self.tmpfile = tempfile.mkstemp() prefix = temp_dir_prefix(__name__, self, 'setUp') self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix) config = { 'run.xunit.output': self.tmpfile[1], 'run.results_dir': self.tmpdir.name } self.job = job.Job(config) self.test_result = Result(UNIQUE_ID, LOGFILE) self.test_result.tests_total = 1 self.test_result.logfile = ("/.../avocado/job-results/" "job-2018-11-28T16.27-8fef221/job.log") self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir.name) self.test1._Test__status = 'PASS' self.test1._Test__logfile = '' self.test1.time_elapsed = 678.23689
def setUp(self): super().setUp() class SimpleTest(Test): def test(self): pass json_output_path = os.path.join(self.tmpdir.name, 'results.json') config = { 'run.results_dir': self.tmpdir.name, 'job.run.result.json.output': json_output_path } self.job = job.Job(config) self.job.setup() self.test_result = Result(UNIQUE_ID, LOGFILE) self.test_result.filename = json_output_path self.test_result.tests_total = 1 self.test1 = SimpleTest(config=self.job.config, base_logdir=self.tmpdir.name) self.test1._Test__status = 'PASS' self.test1.time_elapsed = 1.23
def run(self, config): """ Run test modules or simple tests. :param config: Configuration received from command line parser and possibly other sources. :type config: dict """ if 'run.output_check_record' in config: check_record = config.get('run.output_check_record') process.OUTPUT_CHECK_RECORD_MODE = check_record warnings.warn( "The following arguments will be changed to boolean soon: " "sysinfo, output-check, failfast and keep-tmp. ", FutureWarning) unique_job_id = config.get('run.unique_job_id') if unique_job_id is not None: try: int(unique_job_id, 16) if len(unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) with job.Job(config) as job_instance: pre_post_dispatcher = JobPrePostDispatcher() try: # Run JobPre plugins output.log_plugin_failures(pre_post_dispatcher.load_failures) pre_post_dispatcher.map_method('pre', job_instance) job_run = job_instance.run() finally: # Run JobPost plugins pre_post_dispatcher.map_method('post', job_instance) return job_run
def run(self, config): """ Run test modules or simple tests. :param config: Configuration received from command line parser and possibly other sources. :type config: dict """ if 'run.output_check_record' in config: check_record = config.get('run.output_check_record') process.OUTPUT_CHECK_RECORD_MODE = check_record if config.get('run.test_runner') == 'runner': process.NRUNNER_MODE = False unique_job_id = config.get('run.unique_job_id') if unique_job_id is not None: try: int(unique_job_id, 16) if len(unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: suite = TestSuite.from_config(config, name='') if suite.size == 0: msg = ( "Suite is empty. There is no tests to run. This usually " "happens when you pass --ignore-missing-references and " "there is no more references to process.") LOG_UI.warning(msg) sys.exit(exit_codes.AVOCADO_FAIL) except TestSuiteError as err: LOG_UI.error(err) sys.exit(exit_codes.AVOCADO_JOB_FAIL) with job.Job(config, [suite]) as job_instance: return job_instance.run()