def run_suite(backslash_url, name='simple', interrupt=False): session_id = None with ExitStack() as stack: plugin = BackslashPlugin(backslash_url, keepalive_interval=10) plugin.fetch_token(username='******', password='******') @slash.hooks.register def session_start(): nonlocal session_id session_id = slash.context.session.id plugins.manager.install(plugin, activate=True) stack.callback(plugins.manager.uninstall, plugin) try: slash_run([ os.path.join('_sample_suites', name), '--session-label', 'testing' ]) except KeyboardInterrupt: if not interrupt: raise return session_id
def run_suite(backslash_url, name='simple'): with ExitStack() as stack: plugin = BackslashPlugin(backslash_url, keepalive_interval=10) plugin.fetch_token(username='******', password='******') plugins.manager.install(plugin, activate=True) stack.callback(plugins.manager.uninstall, plugin) slash_run([ os.path.join('_sample_suites', name), '--session-label', 'testing' ])
def suite(name, args): import slash import gossip from slash.frontend.slash_run import slash_run from backslash.contrib.slash_plugin import BackslashPlugin plugin = BackslashPlugin('http://127.0.0.1:8000') @gossip.register('backslash.session_start') def configure(session): session.add_subject('system1', product='Microwave', version='1.0', revision='100') slash.plugins.manager.install(plugin, activate=True) slash_run([from_project_root('_sample_suites', name)] + list(args))
def run(self, verify=True, expect_interruption=False, additional_args=(), args=None, commit=True): if commit: path = self.commit() report_stream = StringIO() returned = SlashRunResult(report_stream=report_stream) captured = [] with self._capture_events(returned): if args is None: args = [path] args.extend(additional_args) try: returned.exit_code = slash_run(args, report_stream=report_stream, app_callback=captured.append, test_sort_key=self._get_test_id_from_runnable ) except (KeyboardInterrupt, SystemExit, TerminatedException) as e: if isinstance(e, KeyboardInterrupt): assert expect_interruption, 'KeyboardInterrupt unexpectedly raised' returned.exit_code = -1 returned.error_message = str(e) else: assert not expect_interruption, 'KeyboardInterrupt did not happen' if captured: assert len(captured) == 1 returned.session = captured[0].session if verify: validate_run(self, returned, expect_interruption) return returned
def suite(name, args, interactive=False, debug=False): import slash import gossip from slash.frontend.slash_run import slash_run from backslash.contrib.slash_plugin import BackslashPlugin plugin = BackslashPlugin('http://127.0.0.1:8000', keepalive_interval=10) @gossip.register('backslash.session_start') def configure(session): session.add_subject('system1', product='Microwave', version='1.0', revision='100') slash.plugins.manager.install(plugin, activate=True) args = list(args) if interactive: args.append('-i') if debug: args.append('--pdb') slash_run([from_project_root('_sample_suites', name)] + args)
def run(self, verify=True, expect_interruption=False, additional_args=(), args=None, commit=True, sort=True, num_workers=1, expect_session_errors=False): if commit: self.commit() path = self._last_committed_path assert path is not None report_stream = StringIO() returned = SlashRunResult(report_stream=report_stream) captured = [] if args is None: args = [path] args.extend(additional_args) if self.is_parallel: args.extend([ '--parallel', str(num_workers), '-vvvvv', '--parallel-addr', 'localhost' ]) with self._capture_events(returned), self._custom_sorting(sort): with self._custom_slashrc(path): app = slash_run( args, report_stream=report_stream, app_callback=captured.append, ) returned.exit_code = app.exit_code if app.interrupted: assert expect_interruption, 'Unexpectedly interrupted' else: assert not expect_interruption, 'Session was not interrupted as expected' if captured: assert len(captured) == 1 returned.session = captured[0].session assert not returned.session.has_internal_errors( ), 'Session has internal errors!' if verify: validate_run(self, returned, expect_interruption=expect_interruption, expect_session_errors=expect_session_errors) return returned
def run(self, verify=True, expect_interruption=False, additional_args=(), args=None, commit=True, sort=True): if commit: self.commit() path = self._last_committed_path assert path is not None report_stream = StringIO() returned = SlashRunResult(report_stream=report_stream) captured = [] with self._capture_events(returned): if args is None: args = [path] args.extend(additional_args) try: with self._custom_slashrc(path): returned.exit_code = slash_run( args, report_stream=report_stream, app_callback=captured.append, test_sort_key=self._get_test_id_from_runnable if sort else None) except (KeyboardInterrupt, SystemExit, TerminatedException) as e: if isinstance(e, KeyboardInterrupt): assert expect_interruption, 'KeyboardInterrupt unexpectedly raised' returned.exit_code = -1 returned.error_message = str(e) else: assert not expect_interruption, 'KeyboardInterrupt did not happen' if captured: assert len(captured) == 1 returned.session = captured[0].session if verify: validate_run(self, returned, expect_interruption) return returned
def test_slash_run_calls_site_load(self): slash.site.load(working_directory=None) self.forge.replay() app = slash_run.slash_run([]) assert app.exit_code != 0
def suite(name, args, interactive=False, debug=False, use_subjects=False, use_related=False): import slash import gossip from slash.frontend.slash_run import slash_run from backslash.contrib.slash_plugin import BackslashPlugin class _Plugin(BackslashPlugin): def _get_initial_session_metadata(self): returned = super()._get_initial_session_metadata() returned.update({"users": { "some_data": [ { 'bla': '2', 'j': 3 }, ] }}) return returned def _get_extra_session_start_kwargs(self): returned = {} if use_subjects: returned['subjects'] = [{ 'name': 'microwave1', 'product': 'Microwave', 'version': 'v1', 'revision': '123456', }] return returned def session_start(self): super().session_start() if use_related: self.session.add_related_entity(entity_type='toaster', entity_name='toaster01') self.session.add_related_entity(entity_type='toaster', entity_name='toaster02') plugin = _Plugin('http://127.0.0.1:8000', keepalive_interval=10, propagate_exceptions=True) @gossip.register('backslash.session_start') def configure(session): session.add_subject('system1', product='Microwave', version='1.0', revision='100') slash.plugins.manager.install(plugin, activate=True) args = list(args) if interactive: args.append('-i') if debug: args.append('--pdb') slash_run([from_project_root('_sample_suites', name)] + args)
def test_slash_run_fails_fast_for_missing_files(): result = slash_run.slash_run(["/non/existing/path"], report_stream=NullFile()) assert result.exit_code != 0, "slash run unexpectedly succeeded for a missing path"
def test_slash_run_fails_fast_for_missing_files(self): result = slash_run.slash_run(["/non/existing/path"], report_stream=NullFile()) self.assertNotEquals( result, 0, "slash run unexpectedly succeeded for a missing path")
def run(self, *args): app = slash_run([self.path] + list(args)) assert not app.session.has_internal_errors( ), 'Session has internal errors!' return SuiteBuilderSuiteResult(app)
def _execute_slash_run(self, argv): return slash_run.slash_run(argv, report_stream=NullFile())
def test_slash_run_calls_site_load(self): slash.site.load() self.forge.replay() with self.assertRaises(SystemExit): slash_run.slash_run([])
def _slash_run(self): return slash_run.slash_run([self.root_path], report_stream=self.report_stream)
def test_slash_run_fails_fast_for_missing_files(self): result = slash_run.slash_run(["/non/existing/path"], report_stream=NullFile()) self.assertNotEquals(result, 0, "slash run unexpectedly succeeded for a missing path")
def _execute_slash_run(argv, suite_object): exitcode = slash_run.slash_run(argv, report_stream=NullFile()) suite_object.verify_last_run() return exitcode
def run(self): app = slash_run([self.path]) return SuiteBuilderSuiteResult(app)
def _console_run(suite): suite.disable_debug_info() path = suite.commit() stream = cStringIO() exit_code = slash_run([path], report_stream=stream, working_directory=path) return exit_code, stream.getvalue()