How to use my_rule method in hypothesis

Best Python code snippet using hypothesis

test_sgl.py

Source: test_sgl.py Github

copy

Full Screen

1"""2Tests to show the use of the SGL code base3"""4from sgl.api import satisfies5from sgl.principal import Principal6def test_delegate():7 rule = {8 "grant": ["backstage"],9 "when": {"all": [{"roles": "press", "n": 2}, {"roles": "stagehand"}]},10 }11 assert satisfies(12 [13 Principal(id="alex", roles=["press"]),14 Principal(id="carol", roles=["press"]),15 Principal(id="bob", roles=["stagehand"]),16 ],17 rule,18 )19 assert not satisfies(20 [21 Principal(id="alex", roles=["press"]),22 Principal(id="bob", roles=["stagehand"]),23 ],24 rule,25 )26def test_grants():27 my_rule = {"grant": ["backstage"], "when": {"roles": "press"}}28 bad = {"id": "Alex", "roles": ["ticket-holder"]}29 good = {"id": "Sofia", "roles": ["ticket-holder", "press"]}30 assert satisfies(good, my_rule)31 assert not satisfies(bad, my_rule)32def test_complex():33 my_rule = {34 "grant": ["backstage"],35 "when": {36 "any": [{"roles": "press", "n": 2}, {"roles": "stagehand", "n": 2}]37 },38 }39 a = [40 Principal(id="alex", roles=["press"]),41 Principal(id="carol", roles=["press"]),42 Principal(id="bob", roles=["stagehand"]),43 ]44 assert satisfies(a, my_rule)45def test_crazy_roles():46 rule = {47 "grant": ["vote"],48 "when": {49 "all": [{"n": 2, "roles": "board"}, {"n": 1, "roles": "investor"}]50 },51 }52 a = [53 Principal(id="tim", roles=["investor", "board"]),54 Principal(id="bob", roles=["investor", "board"]),55 Principal(id="alice", roles=["board"]),56 ]...

Full Screen

Full Screen

test_rules.py

Source: test_rules.py Github

copy

Full Screen

1import os2import datetime3import json4import pytest5from dcc_utils import rule, dcc6from dcc_utils.exceptions import DCCRuleError7def test_simple_rule():8 my_dcc = dcc.from_image(os.path.join("tests", "test_data", "valid_certificate.png"))9 my_rule = rule.from_file(os.path.join("tests", "test_data", "de_v_rule.json"))10 res = my_rule.evaluate_dcc(my_dcc)11 assert res12def test_rule_outta_time():13 my_dcc = dcc.from_image(os.path.join("tests", "test_data", "valid_certificate.png"))14 my_rule = rule.from_file(os.path.join("tests", "test_data", "de_v_rule_2.json"))15 clock = datetime.datetime(2022, 10, 10, 0, 0, tzinfo=datetime.timezone.utc)16 res = my_rule.evaluate_dcc(17 my_dcc,18 {19 "validationClock": clock,20 },21 )22 assert not res23def test_rule_description():24 my_rule = rule.from_file(os.path.join("tests", "test_data", "de_v_rule.json"))25 assert my_rule.payload["Identifier"] == "VR-DE-0001"26 assert (27 my_rule.description["en"]28 == "The vaccination schedule must be complete (e.g., 1/​1, 2/​2)."29 )30def test_rule_errors():31 with pytest.raises(DCCRuleError):32 rule.from_json({"Logi": "a"})33 logic = json.loads(34 (open(os.path.join("tests", "test_data", "de_v_rule.json"))).read()35 )36 logic["Logic"] = None37 my_rule = rule.from_json(logic)38 my_dcc = dcc.from_image(os.path.join("tests", "test_data", "valid_certificate.png"))...

Full Screen

Full Screen

test_rule.py

Source: test_rule.py Github

copy

Full Screen

1from rule import Rule2from input_parser import parse_rule_line, read_input3def test_a_bit_of_containment():4 my_rule = Rule("some rule", (1, 42), (55,99))5 assert my_rule.is_valid(1)6 assert my_rule.is_valid(42)7 assert not my_rule.is_valid(0)8 assert not my_rule.is_valid(43)9 assert my_rule.is_valid(55)10 assert my_rule.is_valid(99)11 assert my_rule.is_valid(35)12 assert my_rule.is_valid(60)13 assert not my_rule.is_valid(54)14 assert not my_rule.is_valid(100)15def test_rule_parsing():16 line = "departure gate: 1-42 or 55-104"17 rule = parse_rule_line(line)18 assert rule.name == "departure gate"19 assert rule.range1 == (1, 42)20 assert rule.range2 == (55, 104)21def test_overall_parsing():22 test_input = """class: 0-1 or 4-1923row: 0-5 or 8-1924seat: 0-13 or 16-1925your ticket:2611,12,1327nearby tickets:283,9,182915,1,5305,14,9"""31 rules, my_ticket, nearby_tickets = read_input(test_input)32 assert len(rules) == 333 assert rules[0].name == "class"34 # don't need to check if overall rule parsing worked because we have a test for that35 assert my_ticket == [11, 12, 13]...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How to Recognize and Hire Top QA / DevOps Engineers

With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.

7 Skills of a Top Automation Tester in 2021

With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.

Different Ways To Style CSS Box Shadow Effects

Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.

Continuous delivery and continuous deployment offer testers opportunities for growth

Development practices are constantly changing and as testers, we need to embrace change. One of the changes that we can experience is the move from monthly or quarterly releases to continuous delivery or continuous deployment. This move to continuous delivery or deployment offers testers the chance to learn new skills.

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