Best Python code snippet using hypothesis
test_nested_where_filters.py
Source: test_nested_where_filters.py
1import pytest2from datagateway_api.src.search_api.filters import SearchAPIWhereFilter3from datagateway_api.src.search_api.nested_where_filters import NestedWhereFilters4from datagateway_api.src.search_api.query import SearchAPIQuery5class TestNestedWhereFilters:6 @pytest.mark.parametrize(7 "lhs, rhs, joining_operator, expected_where_clause",8 [9 pytest.param("A", None, "AND", "(A)", id="LHS (A) w/ misc. AND"),10 pytest.param("A", None, "OR", "(A)", id="LHS (A) w/ misc. OR"),11 pytest.param([], "A", "AND", "(A)", id="RHS (A) w/ misc. AND"),12 pytest.param([], "A", "OR", "(A)", id="RHS (A) w/ misc. OR"),13 pytest.param("A", "B", "AND", "(A AND B)", id="(A AND B)"),14 pytest.param("A", "B", "OR", "(A OR B)", id="(A OR B)"),15 pytest.param(16 "(A AND B)",17 "(C AND D)",18 "AND",19 "((A AND B) AND (C AND D))",20 id="((A AND B) AND (C AND D))",21 ),22 pytest.param(23 "(A AND B)",24 "(C AND D)",25 "OR",26 "((A AND B) OR (C AND D))",27 id="((A AND B) OR (C AND D))",28 ),29 pytest.param(30 "(A OR B)",31 "(C OR D)",32 "OR",33 "((A OR B) OR (C OR D))",34 id="((A OR B) OR (C OR D))",35 ),36 pytest.param(37 "(A OR B)",38 "(C OR D)",39 "AND",40 "((A OR B) AND (C OR D))",41 id="((A OR B) AND (C OR D))",42 ),43 pytest.param(44 "(A AND B AND C) OR (C AND D)",45 "(E AND F)",46 "OR",47 "((A AND B AND C) OR (C AND D) OR (E AND F))",48 id="((A AND B AND C) OR (C AND D) OR (E AND F))",49 ),50 pytest.param(51 "(A AND B AND C) AND (C OR D)",52 "(E AND F)",53 "OR",54 "((A AND B AND C) AND (C OR D) OR (E AND F))",55 id="((A AND B AND C) AND (C OR D)) OR (E AND F))",56 ),57 pytest.param(58 "((A AND B AND C) AND (C OR D))",59 "(E AND F)",60 "OR",61 "(((A AND B AND C) AND (C OR D)) OR (E AND F))",62 id="(((A AND B AND C) AND (C OR D))) OR (E AND F))",63 ),64 ],65 )66 def test_str_filters(self, lhs, rhs, joining_operator, expected_where_clause):67 test_nest = NestedWhereFilters(lhs, rhs, joining_operator)68 where_clause = str(test_nest)69 assert where_clause == expected_where_clause70 @pytest.mark.parametrize(71 "lhs, rhs, joining_operator, query, expected_where_clause",72 [73 pytest.param(74 SearchAPIWhereFilter("name", "test name", "eq"),75 SearchAPIWhereFilter("id", 3, "eq"),76 "OR",77 SearchAPIQuery("File"),78 "(o.name = 'test name' OR o.id = '3')",79 id="(o.title = 'test name' OR o.id = '3')",80 ),81 pytest.param(82 [SearchAPIWhereFilter("name", "test name", "eq")],83 SearchAPIWhereFilter("id", 3, "eq"),84 "OR",85 SearchAPIQuery("File"),86 "(o.name = 'test name' OR o.id = '3')",87 id="Single filter list in LHS",88 ),89 pytest.param(90 [SearchAPIWhereFilter("name", "test name", "eq")],91 [SearchAPIWhereFilter("id", 3, "eq")],92 "OR",93 SearchAPIQuery("File"),94 "(o.name = 'test name' OR o.id = '3')",95 id="Single filter list in LHS and RHS",96 ),97 pytest.param(98 [99 SearchAPIWhereFilter("name", "test name", "eq"),100 SearchAPIWhereFilter("id", 10, "lt"),101 ],102 [SearchAPIWhereFilter("id", 3, "gt")],103 "AND",104 SearchAPIQuery("File"),105 "(o.name = 'test name' AND o.id < '10' AND o.id > '3')",106 id="Multiple filters on LHS",107 ),108 pytest.param(109 [110 SearchAPIWhereFilter("title", "test name", "eq"),111 SearchAPIWhereFilter("pid", "test doi", "like"),112 ],113 [114 SearchAPIWhereFilter("doi", "doi test", "neq"),115 SearchAPIWhereFilter("summary", "Test Summary", "like"),116 ],117 "AND",118 SearchAPIQuery("Document"),119 "(o.name = 'test name' AND o.doi like '%test doi%' AND o.doi != "120 "'doi test' AND o.summary like '%Test Summary%')",121 id="Multiple filters on LHS and RHS",122 ),123 ],124 )125 def test_search_api_filters(126 self, lhs, rhs, joining_operator, query, expected_where_clause,127 ):128 test_nest = NestedWhereFilters(lhs, rhs, joining_operator, query)129 where_clause = str(test_nest)130 assert where_clause == expected_where_clause131 @pytest.mark.parametrize(132 "lhs, rhs, joining_operator, expected_where_clause",133 [134 pytest.param(135 NestedWhereFilters("A", "B", "OR"),136 NestedWhereFilters("C", "D", "AND"),137 "OR",138 "((A OR B) OR (C AND D))",139 id="((A OR B) OR (C AND D))",140 ),141 ],142 )143 def test_nested_classes(144 self, lhs, rhs, joining_operator, expected_where_clause,145 ):146 test_nest = NestedWhereFilters(lhs, rhs, joining_operator)147 where_clause = str(test_nest)148 assert where_clause == expected_where_clause149 @pytest.mark.parametrize(150 "test_filters, query",151 [152 pytest.param(153 SearchAPIWhereFilter("name", "test name", "eq"),154 SearchAPIQuery("File"),155 id="Single WHERE filter",156 ),157 pytest.param(158 NestedWhereFilters(159 [SearchAPIWhereFilter("name", "test name", "eq")],160 [SearchAPIWhereFilter("id", 3, "eq")],161 "OR",162 SearchAPIQuery("File"),163 ),164 SearchAPIQuery("File"),165 id="NestedWhereFilters object",166 ),167 pytest.param(168 [169 SearchAPIWhereFilter("name", "test name", "eq"),170 SearchAPIWhereFilter("id", 3, "eq"),171 ],172 SearchAPIQuery("File"),173 id="List of WHERE filters",174 ),175 ],176 )177 def test_apply_filter(self, test_filters, query):178 NestedWhereFilters.set_search_api_query(test_filters, query)179 if not isinstance(test_filters, list):180 test_filters = [test_filters]181 for filter_ in test_filters:182 if isinstance(filter_, NestedWhereFilters):183 assert filter_.lhs[0].search_api_query == query184 assert filter_.rhs[0].search_api_query == query185 else:...
test_randomization.py
Source: test_randomization.py
...30 @given(st.integers())31 @settings(32 max_examples=100, phases=no_shrink, database=None, verbosity=Verbosity.quiet33 )34 def test_nest(y):35 assert y < x36 with raises(AssertionError):37 test_nest()...
test_nesting.py
Source: test_nesting.py
...22 @given(st.integers())23 @settings(24 max_examples=100, phases=no_shrink, database=None, verbosity=Verbosity.quiet25 )26 def test_nest(y):27 if y >= x:28 raise ValueError()29 with raises(ValueError):30 test_nest()...
Check out the latest blogs from LambdaTest on this topic:
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.
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.
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.
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.
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.
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!!