How to use select_by_prefix method in Behave

Best Python code snippet using behave

__init__.py

Source:__init__.py Github

copy

Full Screen

...44 context.scene.objects.active = obj45def select_only_and_make_active(obj, context=bpy.context):46 set_active_object(obj, context)47 select_only(obj)48def select_by_prefix(prefix):49 for obj in bpy.context.scene.objects:50 if obj.name.startswith(prefix): obj.select = True51def assign_material_to_selected(material):52 assign_material_to_objects(material, bpy.context.selected_objects)53def assign_material_to_objects(material, objects):54 for obj in objects:55 obj.active_material = material56def assign_parent_to_selected(parent):57 assign_parent_to_objects(parent, bpy.context.selected_objects)58def assign_parent_to_objects(parent, objects):59 for obj in objects:60 obj.parent = parent61def scale_value(inval):62 MINV = 20000...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...15 "args": "Command line args for test run.",16})17def test_all(ctx, args="", options=""):18 """Run all tests (default)."""19 pytest_args = select_by_prefix(args, ctx.pytest.scopes)20 behave_args = select_by_prefix(args, ctx.behave_test.scopes)21 pytest_should_run = not args or (args and pytest_args)22 behave_should_run = not args or (args and behave_args)23 if pytest_should_run:24 pytest(ctx, pytest_args, options=options)25 if behave_should_run:26 behave(ctx, behave_args, options=options)27@task28def clean(ctx, dry_run=False):29 """Cleanup (temporary) test artifacts."""30 directories = ctx.test.clean.directories or []31 files = ctx.test.clean.files or []32 cleanup_dirs(directories, dry_run=dry_run)33 cleanup_files(files, dry_run=dry_run)34@task(name="unit")35def unittest(ctx, args="", options=""):36 """Run unit tests."""37 pytest(ctx, args, options)38@task39def pytest(ctx, args="", options=""):40 """Run unit tests."""41 args = args or ctx.pytest.args42 options = options or ctx.pytest.options43 ctx.run("pytest {options} {args}".format(options=options, args=args))44@task(help={45 "args": "Command line args for behave",46 "format": "Formatter to use (progress, pretty, ...)",47})48# pylint: disable=redefined-builtin49def behave(ctx, args="", format="", options=""):50 """Run behave tests."""51 format = format or ctx.behave_test.format52 options = options or ctx.behave_test.options53 args = args or ctx.behave_test.args54 if os.path.exists("bin/behave"):55 behave_cmd = "{python} bin/behave".format(python=sys.executable)56 else:57 behave_cmd = "{python} -m behave".format(python=sys.executable)58 for group_args in grouped_by_prefix(args, ctx.behave_test.scopes):59 ctx.run("{behave} -f {format} {options} {args}".format(60 behave=behave_cmd, format=format, options=options, args=group_args))61@task(help={62 "args": "Tests to run (empty: all)",63 "report": "Coverage report format to use (report, html, xml)",64})65def coverage(ctx, args="", report="report", append=False):66 """Determine test coverage (run pytest, behave)"""67 append = append or ctx.coverage.append68 report_formats = ctx.coverage.report_formats or []69 if report not in report_formats:70 report_formats.insert(0, report)71 opts = []72 if append:73 opts.append("--append")74 pytest_args = select_by_prefix(args, ctx.pytest.scopes)75 behave_args = select_by_prefix(args, ctx.behave_test.scopes)76 pytest_should_run = not args or (args and pytest_args)77 behave_should_run = not args or (args and behave_args)78 if not args:79 behave_args = ctx.behave_test.args or "features"80 if isinstance(pytest_args, list):81 pytest_args = " ".join(pytest_args)82 if isinstance(behave_args, list):83 behave_args = " ".join(behave_args)84 # -- RUN TESTS WITH COVERAGE:85 if pytest_should_run:86 ctx.run("coverage run {options} -m pytest {args}".format(87 args=pytest_args, options=" ".join(opts)))88 if behave_should_run:89 behave_options = ctx.behave_test.coverage_options or ""90 os.environ["COVERAGE_PROCESS_START"] = os.path.abspath(".coveragerc")91 behave(ctx, args=behave_args, options=behave_options)92 del os.environ["COVERAGE_PROCESS_START"]93 # -- POST-PROCESSING:94 ctx.run("coverage combine")95 for report_format in report_formats:96 ctx.run("coverage {report_format}".format(report_format=report_format))97# ---------------------------------------------------------------------------98# UTILITIES:99# ---------------------------------------------------------------------------100def select_prefix_for(arg, prefixes):101 for prefix in prefixes:102 if arg.startswith(prefix):103 return prefix104 return os.path.dirname(arg)105def select_by_prefix(args, prefixes):106 selected = []107 for arg in args.strip().split():108 assert not arg.startswith("-"), "REQUIRE: arg, not options"109 scope = select_prefix_for(arg, prefixes)110 if scope:111 selected.append(arg)112 return " ".join(selected)113def grouped_by_prefix(args, prefixes):114 """Group behave args by (directory) scope into multiple test-runs."""115 group_args = []116 current_scope = None117 for arg in args.strip().split():118 assert not arg.startswith("-"), "REQUIRE: arg, not options"119 scope = select_prefix_for(arg, prefixes)...

Full Screen

Full Screen

RDBService.py

Source:RDBService.py Github

copy

Full Screen

...89 clause = "SET " + ", ".join(terms) + f" where id = {id}"90 # print(clause)91 # print(args)92 return clause, args93def select_by_prefix(db_schema, table_name, column_name, value_prefix):94 conn = _get_db_connection()95 cur = conn.cursor()96 sql = "select * from " + db_schema + "." + table_name + " where " + \97 column_name + " like " + "'" + value_prefix + "%'"98 print("SQL Statement = " + cur.mogrify(sql, None))99 res = cur.execute(sql)100 res = cur.fetchall()101 conn.close()102 return res103def select_by_template(db_schema, table_name, template, field_list):104 limit = template.get('limit');105 offset = template.get('offset');106 template = {k: v for k, v in template.items() if k!= 'limit' and k!='offset'}107 wc,args = _where_clause_args(template)...

Full Screen

Full Screen

select_by_name.py

Source:select_by_name.py Github

copy

Full Screen

1# ##### BEGIN GPL LICENSE BLOCK #####2#3# This program is free software; you can redistribute it and/or4# modify it under the terms of the GNU General Public License5# as published by the Free Software Foundation; either version 26# of the License, or (at your option) any later version.7#8# This program is distributed in the hope that it will be useful,9# but WITHOUT ANY WARRANTY; without even the implied warranty of10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11# GNU General Public License for more details.12#13# You should have received a copy of the GNU General Public License14# along with this program; if not, write to the Free Software Foundation,15# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.16#17# ##### END GPL LICENSE BLOCK #####18# (c) 2018 Dan Pool (dpdp) 19import bpy2021# from bpy import context22import os23os.system('cls')2425bl_info = {26 "name": "SelectByBasename",27 "author": "Dan Pool (dpdp)",28 "version": (0, 0, 1),29 "blender": (2, 79, 0),30 "description": "Selects all objects with the same base name as the current object",31 "location": "Select > Select by Prefix",32 "warning": "",33 "wiki_url": "",34 "tracker_url": "",35 "category": "Object"}363738class SelectByPrefix(bpy.types.Operator):39 """Select all objects with the same prefix"""40 bl_idname = "object.select_by_prefix"41 bl_label = "Select by Prefix"42 bl_options = {'REGISTER', 'UNDO'}43 global converted4445 @classmethod46 def poll(cls, context):47 return ((len(context.selected_objects) > 0)48 and (context.mode == 'OBJECT'))4950 def execute(self, context):5152 # determine selected material53 sname = context.object.name # type: object5455 if not '_' in sname:56 spreffix = [sname, None]57 else: 58 spreffix = sname.split('_')59 60 for ob in context.scene.objects:61 if not '_' in ob.name:62 preffixes = ob.name, None63 else:64 preffixes = ob.name.split('_')65 if preffixes[0]==spreffix[0]:66 ob.select = True6768 return {'FINISHED'}6970class SelectBySuffix(bpy.types.Operator):71 """Select all objects with the same suffix"""72 bl_idname = "object.select_by_suffix"73 bl_label = "Select by Suffix"74 bl_options = {'REGISTER', 'UNDO'}75 global converted7677 @classmethod78 def poll(cls, context):79 return ((len(context.selected_objects) > 0)80 and (context.mode == 'OBJECT'))8182 def execute(self, context):8384 # determine selected material85 sname = context.object.name # type: object8687 if not '_' in sname:88 ssuffix = [sname, None]89 else: 90 ssuffix = sname.split('_')91 92 for ob in context.scene.objects:93 if not '_' in ob.name:94 suffixes = ob.name, None95 else:96 suffixes = ob.name.split('_')97 if ssuffix[-1]==suffixes[-1]:98 ob.select = True99100 return {'FINISHED'} 101102103104def register():105 bpy.utils.register_module(__name__)106 bpy.types.VIEW3D_MT_select_object.append(menu_func)107108109def unregister():110 bpy.utils.unregister_module(__name__)111 bpy.types.VIEW3D_MT_select_object.remove(menu_func)112113114def menu_func(self, context):115 self.layout.separator()116 self.layout.operator(SelectBySuffix.bl_idname)117 self.layout.operator(SelectByPrefix.bl_idname)118 119120121if __name__ == "__main__": ...

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 Behave 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