How to use pick_runner_class method in avocado

Best Python code snippet using avocado_python

test_nrunner.py

Source:test_nrunner.py Github

copy

Full Screen

...77 self.assertEqual(runnable.get_json(), expected)78 def test_runner_from_runnable_error(self):79 runnable = nrunner.Runnable('unsupported_kind', '')80 try:81 runnable.pick_runner_class()82 except ValueError as e:83 self.assertEqual(str(e), 'Unsupported kind of runnable: unsupported_kind')84class RunnableFromCommandLineArgs(unittest.TestCase):85 def test_noop(self):86 parsed_args = {'kind': 'noop', 'uri': None}87 runnable = nrunner.Runnable.from_args(parsed_args)88 self.assertEqual(runnable.kind, 'noop')89 self.assertIsNone(runnable.uri)90 def test_exec_args(self):91 parsed_args = {'kind': 'exec', 'uri': '/path/to/executable',92 'arg': ['-a', '-b', '-c']}93 runnable = nrunner.Runnable.from_args(parsed_args)94 self.assertEqual(runnable.kind, 'exec')95 self.assertEqual(runnable.uri, '/path/to/executable')96 self.assertEqual(runnable.args, ('-a', '-b', '-c'))97 self.assertEqual(runnable.kwargs, {})98 def test_exec_args_kwargs(self):99 parsed_args = {'kind': 'exec', 'uri': '/path/to/executable',100 'arg': ['-a', '-b', '-c'],101 'kwargs': [('DEBUG', '1'), ('LC_ALL', 'C')]}102 runnable = nrunner.Runnable.from_args(parsed_args)103 self.assertEqual(runnable.kind, 'exec')104 self.assertEqual(runnable.uri, '/path/to/executable')105 self.assertEqual(runnable.args, ('-a', '-b', '-c'))106 self.assertEqual(runnable.kwargs.get('DEBUG'), '1')107 self.assertEqual(runnable.kwargs.get('LC_ALL'), 'C')108 def test_kwargs_json_empty_dict(self):109 parsed_args = {'kind': 'noop', 'uri': None,110 'kwargs': [('empty', 'json:{}')]}111 runnable = nrunner.Runnable.from_args(parsed_args)112 self.assertEqual(runnable.kind, 'noop')113 self.assertIsNone(runnable.uri)114 self.assertEqual(runnable.kwargs.get('empty'), {})115 def test_kwargs_json_dict(self):116 parsed_args = {117 'kind': 'noop', 'uri': None,118 'kwargs': [('tags', 'json:{"arch": ["x86_64", "ppc64"]}'),119 ('hi', 'json:"hello"')]120 }121 runnable = nrunner.Runnable.from_args(parsed_args)122 self.assertEqual(runnable.kind, 'noop')123 self.assertIsNone(runnable.uri)124 self.assertEqual(runnable.kwargs.get('hi'), 'hello')125 self.assertEqual(runnable.tags.get('arch'), ["x86_64", "ppc64"])126class RunnableToRecipe(unittest.TestCase):127 def setUp(self):128 prefix = temp_dir_prefix(__name__, self, 'setUp')129 self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix)130 def test_runnable_to_recipe_noop(self):131 runnable = nrunner.Runnable('noop', None)132 recipe_path = os.path.join(self.tmpdir.name, 'recipe.json')133 runnable.write_json(recipe_path)134 self.assertTrue(os.path.exists(recipe_path))135 loaded_runnable = nrunner.Runnable.from_recipe(recipe_path)136 self.assertEqual(loaded_runnable.kind, 'noop')137 def test_runnable_to_recipe_uri(self):138 runnable = nrunner.Runnable('exec', '/bin/true')139 recipe_path = os.path.join(self.tmpdir.name, 'recipe.json')140 runnable.write_json(recipe_path)141 self.assertTrue(os.path.exists(recipe_path))142 loaded_runnable = nrunner.Runnable.from_recipe(recipe_path)143 self.assertEqual(loaded_runnable.kind, 'exec')144 self.assertEqual(loaded_runnable.uri, '/bin/true')145 def test_runnable_to_recipe_args(self):146 runnable = nrunner.Runnable('exec', '/bin/sleep', '0.01')147 recipe_path = os.path.join(self.tmpdir.name, 'recipe.json')148 runnable.write_json(recipe_path)149 self.assertTrue(os.path.exists(recipe_path))150 loaded_runnable = nrunner.Runnable.from_recipe(recipe_path)151 self.assertEqual(loaded_runnable.kind, 'exec')152 self.assertEqual(loaded_runnable.uri, '/bin/sleep')153 self.assertEqual(loaded_runnable.args, ('0.01', ))154 def tearDown(self):155 self.tmpdir.cleanup()156class Runner(unittest.TestCase):157 def test_runner_noop(self):158 runnable = nrunner.Runnable('noop', None)159 runner_klass = runnable.pick_runner_class()160 runner = runner_klass(runnable)161 results = [status for status in runner.run()]162 last_result = results[-1]163 self.assertEqual(last_result['status'], 'finished')164 self.assertIn('time', last_result)165 def test_runner_exec(self):166 runnable = nrunner.Runnable('exec', sys.executable,167 '-c', 'import time; time.sleep(0.01)')168 runner_klass = runnable.pick_runner_class()169 runner = runner_klass(runnable)170 results = [status for status in runner.run()]171 last_result = results[-1]172 self.assertEqual(last_result['status'], 'finished')173 self.assertEqual(last_result['returncode'], 0)174 self.assertEqual(last_result['stdout'], b'')175 self.assertEqual(last_result['stderr'], b'')176 self.assertIn('time', last_result)177 def test_runner_exec_test_ok(self):178 runnable = nrunner.Runnable('exec-test', sys.executable,179 '-c', 'import time; time.sleep(0.01)')180 runner_klass = runnable.pick_runner_class()181 runner = runner_klass(runnable)182 results = [status for status in runner.run()]183 last_result = results[-1]184 self.assertEqual(last_result['status'], 'finished')185 self.assertEqual(last_result['result'], 'pass')186 self.assertEqual(last_result['returncode'], 0)187 self.assertEqual(last_result['stdout'], b'')188 self.assertEqual(last_result['stderr'], b'')189 self.assertIn('time', last_result)190 @skipUnlessPathExists('/bin/false')191 def test_runner_exec_test_fail(self):192 runnable = nrunner.Runnable('exec-test', '/bin/false')193 runner_klass = runnable.pick_runner_class()194 runner = runner_klass(runnable)195 results = [status for status in runner.run()]196 last_result = results[-1]197 self.assertEqual(last_result['status'], 'finished')198 self.assertEqual(last_result['result'], 'fail')199 self.assertEqual(last_result['returncode'], 1)200 self.assertEqual(last_result['stdout'], b'')201 self.assertEqual(last_result['stderr'], b'')202 self.assertIn('time', last_result)203 def test_runner_python_unittest_ok(self):204 runnable = nrunner.Runnable('python-unittest', 'unittest.TestCase')205 runner_klass = runnable.pick_runner_class()206 runner = runner_klass(runnable)207 results = [status for status in runner.run()]208 output1 = ('----------------------------------------------------------'209 '------------\nRan 0 tests in ')210 output2 = 's\n\nOK\n'211 result = results[-1]212 self.assertEqual(result['status'], 'finished')213 self.assertEqual(result['result'], 'pass')214 self.assertTrue(result['output'].startswith(output1))215 self.assertTrue(result['output'].endswith(output2))216 def test_runner_python_unittest_fail(self):217 runnable = nrunner.Runnable('python-unittest', 'unittest.TestCase.fail')218 runner_klass = runnable.pick_runner_class()219 runner = runner_klass(runnable)220 results = [status for status in runner.run()]221 output1 = ('============================================================='222 '=========\nFAIL: fail (unittest.case.TestCase)'223 '\nFail immediately, with the given message.')224 output2 = '\n\nFAILED (failures=1)\n'225 result = results[-1]226 self.assertEqual(result['status'], 'finished')227 self.assertEqual(result['result'], 'fail')228 self.assertTrue(result['output'].startswith(output1))229 self.assertTrue(result['output'].endswith(output2))230 def test_runner_python_unittest_skip(self):231 runnable = nrunner.Runnable(232 'python-unittest',233 'selftests.unit.test_test.TestClassTestUnit.DummyTest.skip')234 runner_klass = runnable.pick_runner_class()235 runner = runner_klass(runnable)236 results = [status for status in runner.run()]237 output1 = ('----------------------------------------------------------'238 '------------\nRan 1 test in ')239 output2 = 's\n\nOK (skipped=1)\n'240 result = results[-1]241 self.assertEqual(result['status'], 'finished')242 self.assertEqual(result['result'], 'skip')243 self.assertTrue(result['output'].startswith(output1))244 self.assertTrue(result['output'].endswith(output2))245 def test_runner_python_unittest_error(self):246 runnable = nrunner.Runnable('python-unittest', 'error')247 runner_klass = runnable.pick_runner_class()248 runner = runner_klass(runnable)249 results = [status for status in runner.run()]250 output1 = ('============================================================='251 '=========\nERROR: error')252 output2 = '\n\nFAILED (errors=1)\n'253 result = results[-1]254 self.assertEqual(result['status'], 'finished')255 self.assertEqual(result['result'], 'error')256 self.assertTrue(result['output'].startswith(output1))257 self.assertTrue(result['output'].endswith(output2))258 def test_runner_python_unittest_empty_uri_error(self):259 runnable = nrunner.Runnable('python-unittest', '')260 runner_klass = runnable.pick_runner_class()261 runner = runner_klass(runnable)262 results = [status for status in runner.run()]263 output = 'uri is required but was not given'264 result = results[-1]265 self.assertEqual(result['status'], 'finished')266 self.assertEqual(result['result'], 'error')267 self.assertEqual(result['output'], output)268class RunnerTmp(unittest.TestCase):269 def setUp(self):270 prefix = temp_dir_prefix(__name__, self, 'setUp')271 self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix)272 @skipUnlessPathExists('/bin/sh')273 def test_runner_tap_fail(self):274 tap_script = """#!/bin/sh...

Full Screen

Full Screen

task.py

Source:task.py Github

copy

Full Screen

...167 args.append(status_service.uri)168 return args169 def run(self):170 self.setup_output_dir()171 runner_klass = self.runnable.pick_runner_class()172 runner = runner_klass()173 for status in runner.run(self.runnable):174 if status["status"] == "started":175 status.update({"output_dir": self.runnable.output_dir})176 status.update({"id": self.identifier})177 if self.job_id is not None:178 status.update({"job_id": self.job_id})179 for status_service in self.status_services:180 status_service.post(status)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful