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:

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

Now Log Bugs Using LambdaTest and DevRev

In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

27 Best Website Testing Tools In 2022

Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.

11 Best Mobile Automation Testing Tools In 2022

Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.

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