hypothesis 6.135.8__py3-none-any.whl → 6.135.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hypothesis/database.py CHANGED
@@ -447,11 +447,16 @@ class DirectoryBasedExampleDatabase(ExampleDatabase):
447
447
  kp = self._key_path(key)
448
448
  if not kp.is_dir():
449
449
  return
450
- for path in os.listdir(kp):
451
- try:
452
- yield (kp / path).read_bytes()
453
- except OSError:
454
- pass
450
+
451
+ try:
452
+ for path in os.listdir(kp):
453
+ try:
454
+ yield (kp / path).read_bytes()
455
+ except OSError:
456
+ pass
457
+ except OSError: # pragma: no cover
458
+ # the `kp` directory might have been deleted in the meantime
459
+ pass
455
460
 
456
461
  def save(self, key: bytes, value: bytes) -> None:
457
462
  key_path = self._key_path(key)
@@ -45,11 +45,11 @@ try:
45
45
  except ImportError:
46
46
  black = None # type: ignore
47
47
 
48
- HEADER = f"""\
48
+ HEADER = """\
49
49
  From HEAD Mon Sep 17 00:00:00 2001
50
- From: Hypothesis {__version__} <no-reply@hypothesis.works>
51
- Date: {{when:%a, %d %b %Y %H:%M:%S}}
52
- Subject: [PATCH] {{msg}}
50
+ From: {author}
51
+ Date: {when:%a, %d %b %Y %H:%M:%S}
52
+ Subject: [PATCH] {msg}
53
53
 
54
54
  ---
55
55
  """
@@ -165,20 +165,44 @@ def get_patch_for(
165
165
  *,
166
166
  strip_via: tuple[str, ...] = (),
167
167
  ) -> Optional[tuple[str, str, str]]:
168
- # Skip this if we're unable to find the location or source of this function.
168
+ # Skip this if we're unable to find the location of this function.
169
169
  try:
170
170
  module = sys.modules[func.__module__]
171
- fname = Path(module.__file__).relative_to(Path.cwd()) # type: ignore
172
- before = inspect.getsource(func)
171
+ file_path = Path(module.__file__) # type: ignore
173
172
  except Exception:
174
173
  return None
175
174
 
175
+ fname = (
176
+ file_path.relative_to(Path.cwd())
177
+ if file_path.is_relative_to(Path.cwd())
178
+ else file_path
179
+ )
180
+ patch = _get_patch_for(
181
+ func, examples, strip_via=strip_via, namespace=module.__dict__
182
+ )
183
+ if patch is None:
184
+ return None
185
+
186
+ (before, after) = patch
187
+ return (str(fname), before, after)
188
+
189
+
190
+ # split out for easier testing of patches in hypofuzz, where the function to
191
+ # apply the patch to may not be loaded in sys.modules.
192
+ def _get_patch_for(
193
+ func: Any,
194
+ examples: Sequence[tuple[str, str]],
195
+ *,
196
+ strip_via: tuple[str, ...] = (),
197
+ namespace: dict[str, Any],
198
+ ) -> Optional[tuple[str, str]]:
199
+ try:
200
+ before = inspect.getsource(func)
201
+ except Exception: # pragma: no cover
202
+ return None
203
+
176
204
  modules_in_test_scope = sorted(
177
- (
178
- (k, v)
179
- for (k, v) in module.__dict__.items()
180
- if isinstance(v, types.ModuleType)
181
- ),
205
+ ((k, v) for (k, v) in namespace.items() if isinstance(v, types.ModuleType)),
182
206
  key=lambda kv: len(kv[1].__name__),
183
207
  )
184
208
 
@@ -204,7 +228,7 @@ def get_patch_for(
204
228
  isinstance(anode, ast.Name)
205
229
  and isinstance(anode.ctx, ast.Load)
206
230
  and anode.id not in names
207
- and anode.id not in module.__dict__
231
+ and anode.id not in namespace
208
232
  ):
209
233
  for k, v in modules_in_test_scope:
210
234
  if anode.id in v.__dict__:
@@ -236,8 +260,8 @@ def get_patch_for(
236
260
  return None
237
261
 
238
262
  if (
239
- module.__dict__.get("hypothesis") is sys.modules["hypothesis"]
240
- and "given" not in module.__dict__ # more reliably present than `example`
263
+ namespace.get("hypothesis") is sys.modules["hypothesis"]
264
+ and "given" not in namespace # more reliably present than `example`
241
265
  ):
242
266
  decorator_func = "hypothesis.example"
243
267
  else:
@@ -257,7 +281,7 @@ def get_patch_for(
257
281
  decorator=decorator_func,
258
282
  width=88 - len(prefix), # to match Black's default formatting
259
283
  ).transform_module(node)
260
- return (str(fname), before, indent(after.code, prefix=prefix))
284
+ return (before, indent(after.code, prefix=prefix))
261
285
 
262
286
 
263
287
  def make_patch(
@@ -265,6 +289,7 @@ def make_patch(
265
289
  *,
266
290
  msg: str = "Hypothesis: add explicit examples",
267
291
  when: Optional[datetime] = None,
292
+ author: str = f"Hypothesis {__version__} <no-reply@hypothesis.works>",
268
293
  ) -> str:
269
294
  """Create a patch for (fname, before, after) triples."""
270
295
  assert triples, "attempted to create empty patch"
@@ -274,7 +299,7 @@ def make_patch(
274
299
  for fname, before, after in triples:
275
300
  by_fname.setdefault(Path(fname), []).append((before, after))
276
301
 
277
- diffs = [HEADER.format(msg=msg, when=when)]
302
+ diffs = [HEADER.format(msg=msg, when=when, author=author)]
278
303
  for fname, changes in sorted(by_fname.items()):
279
304
  source_before = source_after = fname.read_text(encoding="utf-8")
280
305
  for before, after in changes:
@@ -192,6 +192,10 @@ def _constants_from_source(source: Union[str, bytes], *, limit: bool) -> Constan
192
192
  return visitor.constants
193
193
 
194
194
 
195
+ def _constants_file_str(constants: Constants) -> str:
196
+ return str(sorted(constants, key=lambda v: (str(type(v)), v)))
197
+
198
+
195
199
  @lru_cache(4096)
196
200
  def constants_from_module(module: ModuleType, *, limit: bool = True) -> Constants:
197
201
  try:
@@ -236,7 +240,7 @@ def constants_from_module(module: ModuleType, *, limit: bool = True) -> Constant
236
240
  # somewhat arbitrary sort order. The cache file doesn't *have* to be
237
241
  # stable... but it is aesthetically pleasing, and means we could rely
238
242
  # on it in the future!
239
- + str(sorted(constants, key=lambda v: (str(type(v)), v))),
243
+ + _constants_file_str(constants),
240
244
  encoding="utf-8",
241
245
  )
242
246
  except Exception: # pragma: no cover
hypothesis/version.py CHANGED
@@ -8,5 +8,5 @@
8
8
  # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
9
  # obtain one at https://mozilla.org/MPL/2.0/.
10
10
 
11
- __version_info__ = (6, 135, 8)
11
+ __version_info__ = (6, 135, 10)
12
12
  __version__ = ".".join(map(str, __version_info__))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypothesis
3
- Version: 6.135.8
3
+ Version: 6.135.10
4
4
  Summary: A library for property-based testing
5
5
  Author-email: "David R. MacIver and Zac Hatfield-Dodds" <david@drmaciver.com>
6
6
  License-Expression: MPL-2.0
@@ -6,7 +6,7 @@ hypothesis/_settings.py,sha256=FGEckgd43ifGBrGcP8pN0YiVu74ZZl2IqghgUZBPUPI,39049
6
6
  hypothesis/configuration.py,sha256=ruHxaoUFm9_gjyFhloszHF8wt-_yW8FQtWfMXFLwdzc,4341
7
7
  hypothesis/control.py,sha256=6zyn0hDDOt5FugCpD2vw1UJFn3uYwd7lpYqMLoHpOgQ,12625
8
8
  hypothesis/core.py,sha256=SNleVqFMjWOtrPYByAbl0XBqkTnHKq12-fKbK0kWEQw,92576
9
- hypothesis/database.py,sha256=2GOOU_3IClEZ-zTGoZPWicwHfH_VF6ANE-XsqFuuOZA,47131
9
+ hypothesis/database.py,sha256=qbiow_zUTUVUzvUa0OlCmkvrBRTyGxA7cTscIn6q_B0,47299
10
10
  hypothesis/entry_points.py,sha256=aY9iTAiu1GaLljqqXFcMBgipZQ60RBOwwvPVmEr1lQE,1440
11
11
  hypothesis/errors.py,sha256=fci2Xe3kUIEBZ92361vot2f7IRjtfEn1aI1Bdf8vfRU,10048
12
12
  hypothesis/provisional.py,sha256=AmYdLs9Yuz6wrJ8QDO8EOX8njGfoVdUFeccuca5khl4,8052
@@ -14,10 +14,10 @@ hypothesis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  hypothesis/reporting.py,sha256=f-jhl1JfAi5_tG8dsUd2qDjGcPdvxEzfF6hXmpTFQ1g,1761
15
15
  hypothesis/stateful.py,sha256=vQ8wDO7YW-8nGlBGLfR9ariwmRCS9jxJy-Ky3swXjDE,42861
16
16
  hypothesis/statistics.py,sha256=kZ5mc0fAg7gnSO6EmDo82fyz8DYhIiJ_mHe7srxOeQ0,5438
17
- hypothesis/version.py,sha256=HDvRrINvs4J753R-FC-LQ2FqZQhRlgU7mrhH5euNkb0,498
17
+ hypothesis/version.py,sha256=zNVpD2w8EJ6Knk7ulTB14thAexTwxSDUr521snNGsl8,499
18
18
  hypothesis/extra/__init__.py,sha256=gx4ENVDkrzBxy5Lv3Iyfs3tvMGdWMbiHfi95B7t61CY,415
19
19
  hypothesis/extra/_array_helpers.py,sha256=PLmFckBfQpzQ4Q3dFJQqMmrbm7Qdvqxf1t9LHDCuSp0,27627
20
- hypothesis/extra/_patching.py,sha256=JztID3rv8Wnos7WMbZaLM3mlKnwt6ZlifyRfXSy4mLQ,11719
20
+ hypothesis/extra/_patching.py,sha256=A5s5EAf81itr--w4SAFyzuecSZm4eT397jM7BvbnQXU,12385
21
21
  hypothesis/extra/array_api.py,sha256=bv_wisQS56wvwg-LiC26DxvzmPxcNLzlbzmltFWZ_Jo,42609
22
22
  hypothesis/extra/cli.py,sha256=HOH_BGosyUvS4yNDsWF4Dfe672tEFGT4BBPBuZamm1s,12885
23
23
  hypothesis/extra/codemods.py,sha256=i_iM5aSnrNjSZ_uNW40yShxXo7qaXuCrDHy8OznOa7o,11224
@@ -39,7 +39,7 @@ hypothesis/internal/cache.py,sha256=5GJ92S7HNjefuiOOSUchp3IYw1XxLVRmYoFHEoL7eVk,
39
39
  hypothesis/internal/cathetus.py,sha256=q6t16mT2jzlJmBddhRlqC2wg_w7FggVDRAVkzs04W-U,2258
40
40
  hypothesis/internal/charmap.py,sha256=dIsRCxa6r1r-rF_NUy04Z-afFa2b6fCFEjWTMYsAgXY,11781
41
41
  hypothesis/internal/compat.py,sha256=CexhnEVndODX3E-iJmBzt_svqLmADF_6vWkd7lXLRQI,10970
42
- hypothesis/internal/constants_ast.py,sha256=to4zxaUpA4JU5iPXy2pOb38dWG_tibu6UZkd2Vrq-fA,10091
42
+ hypothesis/internal/constants_ast.py,sha256=VcItL6O6LbNd-NpunBuonKE9rLNVVxNlOfTDY8Lqci0,10189
43
43
  hypothesis/internal/coverage.py,sha256=u2ALnaYgwd2jSkZkA5aQYA1uMnk7gwaasMJbq_l3iIg,3380
44
44
  hypothesis/internal/detection.py,sha256=v_zf0GYsnfJKQMNw78qYv61Dh-YaXXfgqKpVIOsBvfw,1228
45
45
  hypothesis/internal/entropy.py,sha256=wgNeddIM0I3SD1yydz12Lsop6Di5vsle4e9u5fWAxIs,8014
@@ -105,9 +105,9 @@ hypothesis/utils/terminal.py,sha256=IxGYDGaE4R3b_vMfz5buWbN18XH5qVP4IxqAgNAU5as,
105
105
  hypothesis/vendor/__init__.py,sha256=gx4ENVDkrzBxy5Lv3Iyfs3tvMGdWMbiHfi95B7t61CY,415
106
106
  hypothesis/vendor/pretty.py,sha256=WEZC-UV-QQgCjUf2Iz1WWaWnbgT7Hc3s-GWEVxq-Qz0,36114
107
107
  hypothesis/vendor/tlds-alpha-by-domain.txt,sha256=W9hYvpu2BMmNgE-SfPp8-GTzEVjw0HJUviqlvHwpZu8,9588
108
- hypothesis-6.135.8.dist-info/licenses/LICENSE.txt,sha256=rIkDe6xjVQZE3OjPMsZ2Xl-rncGhzpS4n4qAXzQaZ1A,17141
109
- hypothesis-6.135.8.dist-info/METADATA,sha256=HdZyzvkWTMUPXGrbKESobO_OmKy9M5lwmiLlFD3JFIc,5637
110
- hypothesis-6.135.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
111
- hypothesis-6.135.8.dist-info/entry_points.txt,sha256=JDoUs9w1bYme7aG_eJ1cCtstRTWD71BzG8iRi-G2eHE,113
112
- hypothesis-6.135.8.dist-info/top_level.txt,sha256=ReGreaueiJ4d1I2kEiig_CLeA0sD4QCQ4qk_8kH1oDc,81
113
- hypothesis-6.135.8.dist-info/RECORD,,
108
+ hypothesis-6.135.10.dist-info/licenses/LICENSE.txt,sha256=rIkDe6xjVQZE3OjPMsZ2Xl-rncGhzpS4n4qAXzQaZ1A,17141
109
+ hypothesis-6.135.10.dist-info/METADATA,sha256=OKN6987_2dDGZzZBMCItH59GHVEaXE8IOqn69A9gYsI,5638
110
+ hypothesis-6.135.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
111
+ hypothesis-6.135.10.dist-info/entry_points.txt,sha256=JDoUs9w1bYme7aG_eJ1cCtstRTWD71BzG8iRi-G2eHE,113
112
+ hypothesis-6.135.10.dist-info/top_level.txt,sha256=ReGreaueiJ4d1I2kEiig_CLeA0sD4QCQ4qk_8kH1oDc,81
113
+ hypothesis-6.135.10.dist-info/RECORD,,