Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.1
2 Name: hypothesis-auto
3 Version: 1.1.5
4 Summary: Extends Hypothesis to add fully automatic testing of type annotated functions
5 License: MIT
6 Author: Timothy Crosley
7 Author-email: [email protected]
8 Requires-Python: >=3.6
9 Classifier: License :: OSI Approved :: MIT License
10 Classifier: Programming Language :: Python :: 3
11 Classifier: Programming Language :: Python :: 3.6
12 Classifier: Programming Language :: Python :: 3.7
13 Classifier: Programming Language :: Python :: 3.8
14 Classifier: Programming Language :: Python :: 3.9
15 Classifier: Programming Language :: Python :: 3.10
16 Classifier: Programming Language :: Python :: 3.11
17 Provides-Extra: pytest
18 Requires-Dist: hypothesis (>=4.36,<6.0.0)
19 Requires-Dist: pydantic (>=0.32.2,<2.0.0)
20 Requires-Dist: pytest (>=4.0.0); extra == "pytest"
21 Description-Content-Type: text/markdown
22
23 [![hypothesis-auto - Fully Automatic Tests for Type Annotated Functions Using Hypothesis.](https://raw.github.com/timothycrosley/hypothesis-auto/master/art/logo_large.png)](https://timothycrosley.github.io/hypothesis-auto/)
24 _________________
25
26 [![PyPI version](https://badge.fury.io/py/hypothesis-auto.svg)](http://badge.fury.io/py/hypothesis-auto)
27 [![Build Status](https://travis-ci.org/timothycrosley/hypothesis-auto.svg?branch=master)](https://travis-ci.org/timothycrosley/hypothesis-auto)
28 [![codecov](https://codecov.io/gh/timothycrosley/hypothesis-auto/branch/master/graph/badge.svg)](https://codecov.io/gh/timothycrosley/hypothesis-auto)
29 [![Join the chat at https://gitter.im/timothycrosley/hypothesis-auto](https://badges.gitter.im/timothycrosley/hypothesis-auto.svg)](https://gitter.im/timothycrosley/hypothesis-auto?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
30 [![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.python.org/pypi/hypothesis-auto/)
31 [![Downloads](https://pepy.tech/badge/hypothesis-auto)](https://pepy.tech/project/hypothesis-auto)
32 _________________
33
34 [Read Latest Documentation](https://timothycrosley.github.io/hypothesis-auto/) - [Browse GitHub Code Repository](https://github.com/timothycrosley/hypothesis-auto/)
35 _________________
36
37 **hypothesis-auto** is an extension for the [Hypothesis](https://hypothesis.readthedocs.io/en/latest/) project that enables fully automatic tests for type annotated functions.
38
39 [![Hypothesis Pytest Auto Example](https://raw.github.com/timothycrosley/hypothesis-auto/master/art/demo.gif)](https://github.com/timothycrosley/hypothesis-auto/blob/master/art/demo.gif)
40
41 Key Features:
42
43 * **Type Annotation Powered**: Utilize your function's existing type annotations to build dozens of test cases automatically.
44 * **Low Barrier**: Start utilizing property-based testing in the lowest barrier way possible. Just run `auto_test(FUNCTION)` to run dozens of test.
45 * **pytest Compatible**: Like Hypothesis itself, hypothesis-auto has built-in compatibility with the popular [pytest](https://docs.pytest.org/en/latest/) testing framework. This means that you can turn your automatically generated tests into individual pytest test cases with one line.
46 * **Scales Up**: As you find your self needing to customize your auto_test cases, you can easily utilize all the features of [Hypothesis](https://hypothesis.readthedocs.io/en/latest/), including custom strategies per a parameter.
47
48 ## Installation:
49
50 To get started - install `hypothesis-auto` into your projects virtual environment:
51
52 `pip3 install hypothesis-auto`
53
54 OR
55
56 `poetry add hypothesis-auto`
57
58 OR
59
60 `pipenv install hypothesis-auto`
61
62 ## Usage Examples:
63
64 !!! warning
65 In old usage examples you will see `_` prefixed parameters like `_auto_verify=`. This was done to avoid conflicting with existing function parameters.
66 Based on community feedback the project switched to `_` suffixes, such as `auto_verify_=` to keep the likely hood of conflicting low while
67 avoiding the connotation of private parameters.
68
69 ### Framework independent usage
70
71 #### Basic `auto_test` usage:
72
73 ```python3
74 from hypothesis_auto import auto_test
75
76
77 def add(number_1: int, number_2: int = 1) -> int:
78 return number_1 + number_2
79
80
81 auto_test(add) # 50 property based scenarios are generated and ran against add
82 auto_test(add, auto_runs_=1_000) # Let's make that 1,000
83 ```
84
85 #### Adding an allowed exception:
86
87 ```python3
88 from hypothesis_auto import auto_test
89
90
91 def divide(number_1: int, number_2: int) -> int:
92 return number_1 / number_2
93
94 auto_test(divide)
95
96 -> 1012 raise the_error_hypothesis_found
97 1013
98 1014 for attrib in dir(test):
99
100 <ipython-input-2-65a3aa66e9f9> in divide(number_1, number_2)
101 1 def divide(number_1: int, number_2: int) -> int:
102 ----> 2 return number_1 / number_2
103 3
104
105 0/0
106
107 ZeroDivisionError: division by zero
108
109
110 auto_test(divide, auto_allow_exceptions_=(ZeroDivisionError, ))
111 ```
112
113 #### Using `auto_test` with a custom verification method:
114
115 ```python3
116 from hypothesis_auto import Scenario, auto_test
117
118
119 def add(number_1: int, number_2: int = 1) -> int:
120 return number_1 + number_2
121
122
123 def my_custom_verifier(scenario: Scenario):
124 if scenario.kwargs["number_1"] > 0 and scenario.kwargs["number_2"] > 0:
125 assert scenario.result > scenario.kwargs["number_1"]
126 assert scenario.result > scenario.kwargs["number_2"]
127 elif scenario.kwargs["number_1"] < 0 and scenario.kwargs["number_2"] < 0:
128 assert scenario.result < scenario.kwargs["number_1"]
129 assert scenario.result < scenario.kwargs["number_2"]
130 else:
131 assert scenario.result >= min(scenario.kwargs.values())
132 assert scenario.result <= max(scenario.kwargs.values())
133
134
135 auto_test(add, auto_verify_=my_custom_verifier)
136 ```
137
138 Custom verification methods should take a single [Scenario](https://timothycrosley.github.io/hypothesis-auto/reference/hypothesis_auto/tester/#scenario) and raise an exception to signify errors.
139
140 For the full set of parameters, you can pass into auto_test see its [API reference documentation](https://timothycrosley.github.io/hypothesis-auto/reference/hypothesis_auto/tester/).
141
142 ### pytest usage
143
144 #### Using `auto_pytest_magic` to auto-generate dozens of pytest test cases:
145
146 ```python3
147 from hypothesis_auto import auto_pytest_magic
148
149
150 def add(number_1: int, number_2: int = 1) -> int:
151 return number_1 + number_2
152
153
154 auto_pytest_magic(add)
155 ```
156
157 #### Using `auto_pytest` to run dozens of test case within a temporary directory:
158
159 ```python3
160 from hypothesis_auto import auto_pytest
161
162
163 def add(number_1: int, number_2: int = 1) -> int:
164 return number_1 + number_2
165
166
167 @auto_pytest()
168 def test_add(test_case, tmpdir):
169 tmpdir.mkdir().chdir()
170 test_case()
171 ```
172
173 #### Using `auto_pytest_magic` with a custom verification method:
174
175 ```python3
176 from hypothesis_auto import Scenario, auto_pytest
177
178
179 def add(number_1: int, number_2: int = 1) -> int:
180 return number_1 + number_2
181
182
183 def my_custom_verifier(scenario: Scenario):
184 if scenario.kwargs["number_1"] > 0 and scenario.kwargs["number_2"] > 0:
185 assert scenario.result > scenario.kwargs["number_1"]
186 assert scenario.result > scenario.kwargs["number_2"]
187 elif scenario.kwargs["number_1"] < 0 and scenario.kwargs["number_2"] < 0:
188 assert scenario.result < scenario.kwargs["number_1"]
189 assert scenario.result < scenario.kwargs["number_2"]
190 else:
191 assert scenario.result >= min(scenario.kwargs.values())
192 assert scenario.result <= max(scenario.kwargs.values())
193
194
195 auto_pytest_magic(add, auto_verify_=my_custom_verifier)
196 ```
197
198 Custom verification methods should take a single [Scenario](https://timothycrosley.github.io/hypothesis-auto/reference/hypothesis_auto/tester/#scenario) and raise an exception to signify errors.
199
200 For the full reference of the pytest integration API see the [API reference documentation](https://timothycrosley.github.io/hypothesis-auto/reference/hypothesis_auto/pytest/).
201
202 ## Why Create hypothesis-auto?
203
204 I wanted a no/low resistance way to start incorporating property-based tests across my projects. Such a solution that also encouraged the use of type hints was a win/win for me.
205
206 I hope you too find `hypothesis-auto` useful!
207
208 ~Timothy Crosley
209