Best Python code snippet using Testify_python
test_blackboard_behaviours.py
Source:test_blackboard_behaviours.py
1#!/usr/bin/env python2#3# License: BSD4# https://raw.githubusercontent.com/splintered-reality/py_trees/devel/LICENSE5#6##############################################################################7# Imports8##############################################################################9import py_trees10import py_trees.console as console11import operator12from py_trees.common import Status13from py_trees.behaviours import (14 CheckBlackboardVariableExists,15 WaitForBlackboardVariable16)17from py_trees.blackboard import Blackboard, Client18##############################################################################19# Logging Level20##############################################################################21# py_trees.logging.level = py_trees.logging.Level.DEBUG22# logger = py_trees.logging.Logger("Nosetest")23##############################################################################24# Helpers25##############################################################################26def assert_banner():27 print(console.green + "----- Asserts -----" + console.reset)28def assert_details(text, expected, result):29 print(console.green + text +30 "." * (70 - len(text)) +31 console.cyan + "{}".format(expected) +32 console.yellow + " [{}]".format(result) +33 console.reset)34class Nested(object):35 def __init__(self):36 self.foo = 'bar'37def create_blackboard():38 """39 Create a blackboard with a few variables.40 Fill with as many different types as we need to get full coverage on41 pretty printing blackboard tests.42 """43 Blackboard.clear()44 blackboard = Client(name="Tester")45 for key in {"foo", "some_tuple", "nested", "nothing"}:46 blackboard.register_key(47 key=key,48 access=py_trees.common.Access.READ49 )50 for key in {"foo", "some_tuple", "nested", "nothing"}:51 blackboard.register_key(52 key=key,53 access=py_trees.common.Access.WRITE54 )55 blackboard.foo = "bar"56 blackboard.some_tuple = (1, "bar")57 blackboard.nested = Nested()58 blackboard.nothing = None59 return blackboard60##############################################################################61# Tests62##############################################################################63def test_variable_exists():64 console.banner("Check Existence of Variable")65 unused_client = create_blackboard()66 tuples = []67 tuples.append((CheckBlackboardVariableExists(68 name="check_foo_exists", variable_name="foo"), Status.SUCCESS))69 tuples.append((CheckBlackboardVariableExists(70 name="check_bar_exists", variable_name="bar"), Status.FAILURE))71 tuples.append((CheckBlackboardVariableExists(72 name="check_nested_foo_exists", variable_name="nested.foo"), Status.SUCCESS))73 tuples.append((CheckBlackboardVariableExists(74 name="check_nested_bar_exists", variable_name="nested.bar"), Status.FAILURE))75 for b, unused in tuples:76 b.tick_once()77 assert_banner()78 for b, asserted_result in tuples:79 assert_details(80 text="looking for '{}'".format(b.variable_name),81 expected=asserted_result,82 result=b.status83 )84 assert(b.status == asserted_result)85def test_wait_for_variable():86 console.banner("Wait for Variable")87 unused_client = create_blackboard()88 tuples = []89 tuples.append((WaitForBlackboardVariable(90 name="Wait for Foo", variable_name="foo"), Status.SUCCESS))91 tuples.append((WaitForBlackboardVariable(92 name="Wait for Bar", variable_name="bar"), Status.RUNNING))93 tuples.append((WaitForBlackboardVariable(94 name="Wait for nested.foo", variable_name="nested.foo"), Status.SUCCESS))95 tuples.append((WaitForBlackboardVariable(96 name="Wait for nested.bar", variable_name="nested.bar"), Status.RUNNING))97 for b, unused in tuples:98 b.tick_once()99 assert_banner()100 for b, asserted_result in tuples:101 assert_details(102 text="waiting for '{}'".format(b.variable_name),103 expected=asserted_result,104 result=b.status105 )106 assert(b.status == asserted_result)107def test_unset_blackboard_variable():108 console.banner("Unset Blackboard Variable")109 blackboard = create_blackboard()110 blackboard.foo = "bar"111 clear_foo = py_trees.behaviours.UnsetBlackboardVariable(name="Clear Foo", key="foo")112 clear_bar = py_trees.behaviours.UnsetBlackboardVariable(name="Clear Bar", key="bar")113 py_trees.display.unicode_blackboard()114 assert_banner()115 assert_details(116 text="'/foo' exists",117 expected=True,118 result="/foo" in Blackboard.storage.keys()119 )120 assert("/foo" in Blackboard.storage.keys())121 print("Ticking 'Clear Foo' once...")122 clear_foo.tick_once()123 assert_details(124 text="'/foo' does not exist",125 expected=True,126 result="/foo" not in Blackboard.storage.keys()127 )128 assert("/foo" not in Blackboard.storage.keys())129 print("Ticking 'Clear Bar' once...")130 clear_bar.tick_once()131 assert_details(132 text="'/bar' does not exist",133 expected=True,134 result="/bar" not in Blackboard.storage.keys()135 )136 assert("/bar" not in Blackboard.storage.keys())137 assert_details(138 text="'/foo' still does not exist",139 expected=True,140 result="/foo" not in Blackboard.storage.keys()141 )142 assert("/foo" not in Blackboard.storage.keys())143def test_set_blackboard_variable():144 console.banner("Set Blackboard Variable")145 blackboard = create_blackboard()146 set_foo = py_trees.behaviours.SetBlackboardVariable(147 name="Set Foo",148 variable_name="foo",149 variable_value="bar"150 )151 conservative_set_foo = py_trees.behaviours.SetBlackboardVariable(152 name="Conservative Set Foo",153 variable_name="foo",154 variable_value="bar",155 overwrite=False156 )157 blackboard.unset("foo")158 assert_banner()159 set_foo.tick_once()160 assert_details(161 text="Set 'foo' (doesn't exist)",162 expected="bar",163 result=blackboard.foo164 )165 assert("bar" == blackboard.foo)166 blackboard.foo = "whoop"167 set_foo.tick_once()168 assert_details(169 text="Set 'foo' (exists)",170 expected="bar",171 result=blackboard.foo172 )173 blackboard.unset("foo")174 assert_details(175 text="Set 'foo' Status",176 expected=py_trees.common.Status.SUCCESS,177 result=set_foo.status178 )179 assert(set_foo.status == Status.SUCCESS)180 conservative_set_foo.tick_once()181 assert_details(182 text="Conservative 'foo' (doesn't exist)",183 expected="bar",184 result=blackboard.foo185 )186 assert("bar" == blackboard.foo)187 blackboard.foo = "whoop"188 conservative_set_foo.tick_once()189 assert_details(190 text="Conservative Set 'foo' (exists)",191 expected="whoop",192 result=blackboard.foo193 )194 assert("whoop" == blackboard.foo)195 assert_details(196 text="Conservative Set 'foo' Status",197 expected=py_trees.common.Status.FAILURE,198 result=conservative_set_foo.status199 )200 assert(conservative_set_foo.status == Status.FAILURE)201 nested_set_foo = py_trees.behaviours.SetBlackboardVariable(202 name="Nested Set Foo",203 variable_name="nested.foo",204 variable_value="dude",205 overwrite=True206 )207 nested_set_foo.tick_once()208 assert_details(209 text="Nested set foo (value)",210 expected="dude",211 result=blackboard.nested.foo212 )213 assert(blackboard.nested.foo == "dude")214 assert_details(215 text="Nested set foo (status)",216 expected=py_trees.common.Status.SUCCESS,217 result=nested_set_foo.status218 )219 assert(nested_set_foo.status == py_trees.common.Status.SUCCESS)220 blackboard.nested = 5221 nested_set_foo.tick_once()222 assert_details(223 text="Nested set foo, no nested attribute (status)",224 expected=py_trees.common.Status.FAILURE,225 result=nested_set_foo.status226 )227 assert(nested_set_foo.status == py_trees.common.Status.FAILURE)228 @py_trees.utilities.static_variables(counter=0)229 def generator():230 generator.counter += 1231 return generator.counter232 blackboard.unset("foo")233 set_blackboard_variable_from_generator = py_trees.behaviours.SetBlackboardVariable(234 name="Generator Set",235 variable_name="foo",236 variable_value=generator,237 )238 set_blackboard_variable_from_generator.tick_once()239 assert_details(240 text="Generated Foo",241 expected=1,242 result=blackboard.foo243 )244 assert(blackboard.foo == 1)245 set_blackboard_variable_from_generator.tick_once()246 assert_details(247 text="Generated Foo",248 expected=2,249 result=blackboard.foo250 )251 assert(blackboard.foo == 2)252def test_check_variable_value():253 console.banner("Check Variable Value")254 unused_client = create_blackboard()255 tuples = []256 print(py_trees.display.unicode_blackboard())257 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(258 name="check_foo_equals_bar", variable_name="foo", expected_value="bar"), Status.SUCCESS))259 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(260 name="check_foo_equals_foo", variable_name="foo", expected_value="foo"), Status.FAILURE))261 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(262 name="check_non_existant_bar_equals_bar", variable_name="bar", expected_value="bar"), Status.FAILURE))263 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(264 name="check_nested_foo_equals_bar", variable_name="nested.foo", expected_value="bar"),265 Status.SUCCESS))266 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(267 name="check_nested_foo_equals_foo", variable_name="nested.foo", expected_value="foo"),268 Status.FAILURE))269 for b, unused in tuples:270 b.tick_once()271 print("Feedback message {}".format(b.feedback_message))272 print("")273 assert_banner()274 for b, asserted_result in tuples:275 assert_details(276 text=b.name,277 expected=asserted_result,278 result=b.status279 )280 assert(b.status == asserted_result)281def test_check_variable_value_inverted():282 console.banner("Check Variable Value Neq")283 unused_client = create_blackboard()284 tuples = []285 print(py_trees.display.unicode_blackboard())286 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(287 name="check_foo_not_equals_bar", variable_name="foo", expected_value="bar",288 comparison_operator=operator.ne), Status.FAILURE))289 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(290 name="check_foo_not_equals_foo", variable_name="foo", expected_value="foo",291 comparison_operator=operator.ne), Status.SUCCESS))292 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(293 name="check_non_existant_bar_not_equals_bar", variable_name="bar", expected_value="bar",294 comparison_operator=operator.ne), Status.FAILURE))295 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(296 name="check_nested_foo_not_equals_bar", variable_name="nested.foo", expected_value="bar",297 comparison_operator=operator.ne),298 Status.FAILURE))299 tuples.append((py_trees.behaviours.CheckBlackboardVariableValue(300 name="check_nested_foo_not_equals_foo", variable_name="nested.foo", expected_value="foo",301 comparison_operator=operator.ne),302 Status.SUCCESS))303 for b, unused in tuples:304 b.tick_once()305 print("Feedback message {}".format(b.feedback_message))306 print("")307 assert_banner()308 for b, asserted_result in tuples:309 assert_details(310 text=b.name,311 expected=asserted_result,312 result=b.status313 )314 assert(b.status == asserted_result)315def test_wait_for_variable_value():316 console.banner("Wait for Variable Value")317 unused_client = create_blackboard()318 tuples = []319 print(py_trees.display.unicode_blackboard())320 tuples.append((py_trees.behaviours.WaitForBlackboardVariableValue(321 name="check_foo_equals_bar", variable_name="foo", expected_value="bar"), Status.SUCCESS))322 tuples.append((py_trees.behaviours.WaitForBlackboardVariableValue(323 name="check_foo_equals_foo", variable_name="foo", expected_value="foo"), Status.RUNNING))324 tuples.append((py_trees.behaviours.WaitForBlackboardVariableValue(325 name="check_non_existant_bar_equals_bar", variable_name="bar", expected_value="bar"), Status.RUNNING))326 tuples.append((py_trees.behaviours.WaitForBlackboardVariableValue(327 name="check_nested_foo_equals_bar", variable_name="nested.foo", expected_value="bar"),328 Status.SUCCESS))329 tuples.append((py_trees.behaviours.WaitForBlackboardVariableValue(330 name="check_nested_foo_equals_foo", variable_name="nested.foo", expected_value="foo"),331 Status.RUNNING))332 for b, unused in tuples:333 b.tick_once()334 print("Feedback message {}".format(b.feedback_message))335 print("")336 assert_banner()337 for b, asserted_result in tuples:338 assert_details(339 text=b.name,340 expected=asserted_result,341 result=b.status342 )343 assert(b.status == asserted_result)344def test_check_variable_values():345 console.banner("Check Variable Values")346 blackboard = Client(name="Blackboard")347 for key in {"a", "b", "c", "d"}:348 blackboard.register_key(349 key=key,350 access=py_trees.common.Access.WRITE351 )352 b = py_trees.behaviours.CheckBlackboardVariableValues(353 name="Checks",354 checks=[355 py_trees.common.ComparisonExpression(variable="a", operator=operator.eq, value="a"),356 py_trees.common.ComparisonExpression(variable="b", operator=operator.eq, value="b"),357 py_trees.common.ComparisonExpression(variable="c", operator=operator.eq, value="c"),358 py_trees.common.ComparisonExpression(variable="d", operator=operator.eq, value="d")359 ],360 operator=operator.and_,361 namespace="results",362 )363 datasets = [364 {'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'operator': operator.and_, 'text': 'AND', 'result': py_trees.common.Status.SUCCESS},365 {'a': 'z', 'b': 'b', 'c': 'c', 'd': 'd', 'operator': operator.and_, 'text': 'AND', 'result': py_trees.common.Status.FAILURE},366 {'a': 'z', 'b': 'b', 'c': 'c', 'd': 'd', 'operator': operator.or_, 'text': 'OR', 'result': py_trees.common.Status.SUCCESS},367 {'a': 'z', 'b': 'z', 'c': 'z', 'd': 'z', 'operator': operator.or_, 'text': 'OR', 'result': py_trees.common.Status.FAILURE},368 {'a': 'a', 'b': 'z', 'c': 'z', 'd': 'z', 'operator': operator.xor, 'text': 'XOR', 'result': py_trees.common.Status.SUCCESS},369 {'a': 'a', 'b': 'b', 'c': 'z', 'd': 'z', 'operator': operator.xor, 'text': 'XOR', 'result': py_trees.common.Status.FAILURE},370 ]371 print("Comparison Operator: operator.eq")372 print("")373 assert_banner()374 for data in datasets:375 blackboard.a = data['a']376 blackboard.b = data['b']377 blackboard.c = data['c']378 blackboard.d = data['d']379 b.operator = data['operator']380 b.tick_once()381 assert_details(382 text="[a:{}|b:{}|c:{}|d:{}]{} - {}".format(blackboard.a, blackboard.b, blackboard.c, blackboard.d, b.feedback_message, data['text']),383 expected=data['result'],384 result=b.status385 )...
test_blackboard.py
Source:test_blackboard.py
1#!/usr/bin/env python2#3# License: BSD4# https://raw.githubusercontent.com/stonier/py_trees/devel/LICENSE5#6##############################################################################7# Imports8##############################################################################9# enable some python3 compatibility options:10# (unicode_literals not compatible with python2 uuid module)11from __future__ import absolute_import, print_function12# from nose.tools import assert_raises13import py_trees14from py_trees import Blackboard, Status15import py_trees.console as console16import operator17##############################################################################18# Logging Level19##############################################################################20# py_trees.logging.level = py_trees.logging.Level.DEBUG21# logger = py_trees.logging.Logger("Nosetest")22##############################################################################23# Helpers24##############################################################################25class FooBar(object):26 def __init__(self):27 self.foo = 'bar'28def create_blackboard():29 """30 Fill with as many different types as we need to get full coverage on31 pretty printing blackboard tests.32 """33 blackboard = Blackboard()34 blackboard.foo = "bar"35 blackboard.some_tuple = (1, "bar")36 blackboard.foobar = FooBar()37 blackboard.nothing = None38 return blackboard39##############################################################################40# Tests41##############################################################################42def test_print_blackboard():43 print(console.bold + "\n****************************************************************************************" + console.reset)44 print(console.bold + "* Blackboard" + console.reset)45 print(console.bold + "****************************************************************************************\n" + console.reset)46 blackboard = create_blackboard()47 print('{0}'.format(blackboard))48def test_variable_exists():49 print(console.bold + "\n****************************************************************************************" + console.reset)50 print(console.bold + "* Check Existence of Variable" + console.reset)51 print(console.bold + "****************************************************************************************\n" + console.reset)52 unused_blackboard = create_blackboard()53 tuples = []54 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_foo_exists", variable_name="foo"), Status.SUCCESS))55 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_bar_exists", variable_name="bar"), Status.FAILURE))56 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_nested_foo_exists", variable_name="foobar.foo"), Status.SUCCESS))57 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_nested_bar_exists", variable_name="foobar.bar"), Status.FAILURE))58 for b, unused in tuples:59 b.tick_once()60 for b, asserted_result in tuples:61 print("%s: %s [%s]" % (b.name, b.status, asserted_result))62 assert(b.status == asserted_result)63def test_expected_value():64 print(console.bold + "\n****************************************************************************************" + console.reset)65 print(console.bold + "* Check Expected Value" + console.reset)66 print(console.bold + "****************************************************************************************\n" + console.reset)67 unused_blackboard = create_blackboard()68 tuples = []69 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_foo_equals_bar", variable_name="foo", expected_value="bar"), Status.SUCCESS))70 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_foo_equals_foo", variable_name="foo", expected_value="foo"), Status.FAILURE))71 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_bar_equals_bar", variable_name="bar", expected_value="bar"), Status.FAILURE))72 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_bar_equals_foo", variable_name="bar", expected_value="foo"), Status.FAILURE))73 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_nested_foo_equals_bar", variable_name="foobar.foo", expected_value="bar"), Status.SUCCESS))74 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_nested_foo_equals_foo", variable_name="foobar.foo", expected_value="foo"), Status.FAILURE))75 for b, unused in tuples:76 b.tick_once()77 for b, asserted_result in tuples:78 print("{0}: {1} [{2}]".format(b.name, b.status, asserted_result))79 assert(b.status == asserted_result)80def test_expected_value_inverted():81 print(console.bold + "\n****************************************************************************************" + console.reset)82 print(console.bold + "* Check Not Expected Value" + console.reset)83 print(console.bold + "****************************************************************************************\n" + console.reset)84 unused_blackboard = create_blackboard()85 tuples = []86 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_foo_not_equals_bar", variable_name="foo", expected_value="bar", comparison_operator=operator.ne), Status.FAILURE))87 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_foo_not_equals_foo", variable_name="foo", expected_value="foo", comparison_operator=operator.ne), Status.SUCCESS))88 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_bar_not_equals_bar", variable_name="bar", expected_value="bar", comparison_operator=operator.ne), Status.FAILURE))89 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_bar_not_equals_foo", variable_name="bar", expected_value="foo", comparison_operator=operator.ne), Status.FAILURE))90 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_nested_foo_not_equals_bar", variable_name="foobar.foo", expected_value="bar", comparison_operator=operator.ne), Status.FAILURE))91 tuples.append((py_trees.blackboard.CheckBlackboardVariable(name="check_nested_foo_not_equals_foo", variable_name="foobar.foo", expected_value="foo", comparison_operator=operator.ne), Status.SUCCESS))92 for b, unused in tuples:93 b.tick_once()94 for b, asserted_result in tuples:95 print("%s: %s [%s]" % (b.name, b.status, asserted_result))96 assert(b.status == asserted_result)97def test_wait_for_blackboard_variable():98 print(console.bold + "\n****************************************************************************************" + console.reset)99 print(console.bold + "* Wait for Blackboard Variable" + console.reset)100 print(console.bold + "****************************************************************************************\n" + console.reset)101 unused_blackboard = create_blackboard()102 tuples = []103 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_foo_exists", variable_name="foo"), Status.SUCCESS))104 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_bar_exists", variable_name="bar"), Status.RUNNING))105 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_nested_foo_exists", variable_name="foobar.foo"), Status.SUCCESS))106 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_nested_bar_exists", variable_name="foobar.bar"), Status.RUNNING))107 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_foo_equals_bar", variable_name="foo", expected_value="bar"), Status.SUCCESS))108 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_foo_equals_foo", variable_name="foo", expected_value="foo"), Status.RUNNING))109 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_bar_equals_bar", variable_name="bar", expected_value="bar"), Status.RUNNING))110 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_bar_equals_foo", variable_name="bar", expected_value="foo"), Status.RUNNING))111 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_nested_foo_equals_bar", variable_name="foobar.foo", expected_value="bar"), Status.SUCCESS))112 tuples.append((py_trees.blackboard.WaitForBlackboardVariable(name="check_nested_foo_equals_foo", variable_name="foobar.foo", expected_value="foo"), Status.RUNNING))113 for b, unused in tuples:114 b.tick_once()115 for b, asserted_result in tuples:116 print("%s: %s [%s]" % (b.name, b.status, asserted_result))117 assert(b.status == asserted_result)118def test_clear_blackboard_variable():119 print(console.bold + "\n****************************************************************************************" + console.reset)120 print(console.bold + "* Clear Blackboard Variable" + console.reset)121 print(console.bold + "****************************************************************************************\n" + console.reset)122 blackboard = create_blackboard()123 blackboard.foo = "bar"124 clear_foo = py_trees.blackboard.ClearBlackboardVariable(name="Clear Foo", variable_name="foo")125 clear_bar = py_trees.blackboard.ClearBlackboardVariable(name="Clear Bar", variable_name="bar")126 print("%s" % blackboard)127 print(" - Assert blackboard has attribute 'foo'")128 assert(hasattr(blackboard, "foo"))129 print(" - Clearing 'foo'")130 clear_foo.tick_once()131 print(" - Assert blackboard does not have attribute 'foo'")132 assert(not hasattr(blackboard, "foo"))133 print(" - Clearing 'bar'")134 clear_bar.tick_once()135 print(" - Asserting nothing wierd happened")136 assert(not hasattr(blackboard, "foo"))137def test_set_blackboard_variable():138 print(console.bold + "\n****************************************************************************************" + console.reset)139 print(console.bold + "* Set Blackboard Variable" + console.reset)140 print(console.bold + "****************************************************************************************\n" + console.reset)141 blackboard = create_blackboard()142 set_foo = py_trees.blackboard.SetBlackboardVariable(name="Set Foo", variable_name="foo", variable_value="bar")143 print(" - Set 'foo'")144 set_foo.tick_once()145 print("\n%s" % blackboard)146 print(" - Assert blackboard.foo='bar'")147 assert(hasattr(blackboard, "foo"))148 assert(blackboard.foo == "bar")149 print(" - Assert set_foo.status == SUCCESS")...
__init__.py
Source:__init__.py
...53 'foo' in message test for the presence of an attribute54 (rather than message.HasField('foo'), or55 message.has_foo() )56 del message.foo Remove the attribute foo, rather than57 message.ClearField('foo') or message.clear_foo()5859 Construction:6061 number = PhoneNumber(number='609-555-1234', phone_type=PhoneType.MOBILE)])62 p = Person(name='Andy', phone=[number])6364 This allows you to write nested "protobuf literals" without a series of65 assignment statements (proto2 doesn't seem to allow this).6667 Deserialization:68 An unnamed argument is assumed to be a byte string:6970 number = PhoneNumber('\\x12\\34')71
...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!