Best Python code snippet using avocado_python
test_ac_parser.py
Source:test_ac_parser.py  
2from lark.exceptions import *3from arpoc.ac.parser import *4def test_plain():5    context = {"subject": {}, "object": {}, "environment": {}}6    assert check_condition('True', context)7    assert not check_condition('False', context)8def test_object_attr():9    context = {"subject": {}, "object": {'test': True}, "environment": {}}10    assert check_condition('object.test == True', context)11    assert not check_condition('exists object.NotExisting', context)12def test_access_attr():13    context = {14        "subject": {},15        "object": {},16        "environment": {},17        "access": {18            'method': 'GET',19            'headers': {20                'Authorization': 'bla'21            },22            'n1': {23                'n2': {24                    'n3': {25                        'n4': "bla"26                    }27                }28            }29        }30    }31    assert check_condition('access.method == "GET"', context)32    assert check_condition('access.headers.Authorization == "bla"', context)33    assert check_condition('access.n1.n2.n3.n4 == "bla"', context)34def test_time_comp():35    context = {"subject": {}, "object": {}, "environment": {"time": "10:28"}}36    assert check_condition(37        "environment.time < '10:30' and environment.time > '10:20'", context)38    context = {"subject": {}, "object": {}, "environment": {"time": "10:35"}}39    assert not check_condition(40        "environment.time < '10:30' and environment.time > '10:20'", context)41def test_subject_attr():42    context = {43        "subject": {44            'email': 'bla'45        },46        "object": {},47        "environment": {48            'time': 12349        }50    }51    assert check_condition('exists subject.email', context)52    assert not check_condition('exists subject.NotExisting', context)53def test_environment_attr():54    context = {"subject": {}, "object": {}, "environment": {'time': 123}}55    assert check_condition('environment.time < 1000', context)56    assert not check_condition('exists environment.NotExisting', context)57def test_regex():58    context = {59        "subject": {60            'name': 'fritz.mueller'61        },62        "object": {},63        "environment": {}64    }65    assert check_condition("subject.name matches r'.*\.mueller'", context)66def test_startswith():67    context = {"subject": {}, "object": {}, "environment": {}}68    assert check_condition('"abcdef" startswith "abc"', context)69def test_startswith_bad_semantics():70    context = {"subject": {}, "object": {}, "environment": {}}71    assert check_condition('"123456789" startswith "123"', context)72    with pytest.raises(VisitError):73        assert check_condition('123456789 startswith 123', context)74    with pytest.raises(VisitError):75        assert check_condition('"apfel" startswith 123', context)76def test_in_list():77    context = {78        "subject": {79            'groups': ['admin', 'user', 'group']80        },81        "object": {},82        "environment": {}83    }84    assert check_condition('5 in [5,4,3]', context)85    assert check_condition("'admin' in subject.groups", context)86    assert check_condition('"admin" in subject.groups', context)87    assert not check_condition('"root" in subject.groups', context)88    context = {"subject": {}, "object": {}, "environment": {}}89    with pytest.raises(VisitError) as e:90        assert not check_condition("'root' in subject.groups", context)91    assert isinstance(e.value.orig_exc, SubjectAttributeMissing)92    #assert isinstance(check_condition("'root' in subject.groups", context),93    #                      bool)94def test_combination():95    context = {"subject": {'email': 'bla'}, "object": {}, "environment": {}}96    assert check_condition('True and True', context)97def test_integer_comparison():98    context = {"subject": {}, "object": {}, "environment": {}}99    assert check_condition('5 < 6', context)100    assert check_condition('6 > 5', context)101    assert check_condition('5 == 5', context)102    assert not check_condition('5 > 6', context)103    assert not check_condition('6 < 5', context)104    assert not check_condition('6 == 7', context)105    assert not check_condition('6 < 6', context)106    assert not check_condition('6 > 6', context)107def test_integer_comparison_bad_semantics():108    context = {"subject": {}, "object": {}, "environment": {}}109    with pytest.raises(VisitError):110        assert check_condition('"bla" < 6', context)111    with pytest.raises(VisitError):112        assert check_condition('6 > "bla"', context)113def test_email_string():114    context = {115        "subject": {116            'email': 'info@example.com'117        },118        "object": {},119        "environment": {}120    }121    assert check_condition('subject.email == "info@example.com"', context)122#    assert not check_condition('exists subject.NotExisting',context)123def test_email_string_single_quoted():124    context = {125        "subject": {126            'email': 'info@example.com'127        },128        "object": {},129        "environment": {}130    }131    assert check_condition("subject.email == 'info@example.com'", context)132#def test_None_mixed():133#    context = {134#        "subject": {135#            'email': 'info@example.com'136#        },137#        "object": {},138#        "environment": {}139#    }140#    assert not check_condition("subject.email == object.email", context)141def test_lists():142    context = {"subject": {}, "object": {}, "environment": {}}143    assert check_condition("['5', 4, True]", context)144def test_nested_lists():145    context = {"subject": {}, "object": {}, "environment": {}}146    assert check_condition("['5', 4, True, [True,False]]", context)147def tests_broken_conditions():148    context = {"subject": {}, "object": {}, "environment": {}}149    with pytest.raises(BadRuleSyntax):150        check_condition("true", context)151    with pytest.raises(BadRuleSyntax):152        check_condition("[1,2,3", context)153    with pytest.raises(BadRuleSyntax):...number_Detection.py
Source:number_Detection.py  
...3        chassis_ctrl.stop()4        pid_gimbal_ctrl.set_follow_chassis_offset(0)5        vision_ctrl.enable_detection(rm_define.vision_detection_marker)6        vision_ctrl.set_marker_detection_distance(set_distance)7        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_zero):8            get_Detection_Number = 09            return 010        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_one):11            get_Detection_Number = 112            return 113        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_two):14            get_Detection_Number = 215            return 216        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_three):17            get_Detection_Number = 318            return 319        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_four):20            get_Detection_Number = 421            return 422        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_five):23            get_Detection_Number = 524            return 525        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_six):26            get_Detection_Number = 627            return 628        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_seven):29            get_Detection_Number = 730            return 731        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_eight):32            get_Detection_Number = 833            return 834        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_nine):35            get_Detection_Number = 9
...number_Detection_v2.py
Source:number_Detection_v2.py  
1def number_Detection(set_distance):2    vision_ctrl.enable_detection(rm_define.vision_detection_marker)3    vision_ctrl.set_marker_detection_distance(set_distance)4    while True:5        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_zero):6            return 07        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_one):8            return 19        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_two):10            return 211        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_three):12            return 313        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_four):14            return 415        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_five):16            return 517        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_six):18            return 619        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_seven):20            return 721        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_eight):22            return 823        if vision_ctrl.check_condition(rm_define.cond_recognized_marker_number_nine):24            return 92526def start():27    while True:28        result = number_Detection(1)
...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!!
