crosshair-tool 0.0.99__cp312-cp312-macosx_10_13_x86_64.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.
Files changed (176) hide show
  1. _crosshair_tracers.cpython-312-darwin.so +0 -0
  2. crosshair/__init__.py +42 -0
  3. crosshair/__main__.py +8 -0
  4. crosshair/_mark_stacks.h +790 -0
  5. crosshair/_preliminaries_test.py +18 -0
  6. crosshair/_tracers.h +94 -0
  7. crosshair/_tracers_pycompat.h +522 -0
  8. crosshair/_tracers_test.py +138 -0
  9. crosshair/abcstring.py +245 -0
  10. crosshair/auditwall.py +190 -0
  11. crosshair/auditwall_test.py +77 -0
  12. crosshair/codeconfig.py +113 -0
  13. crosshair/codeconfig_test.py +117 -0
  14. crosshair/condition_parser.py +1237 -0
  15. crosshair/condition_parser_test.py +497 -0
  16. crosshair/conftest.py +30 -0
  17. crosshair/copyext.py +155 -0
  18. crosshair/copyext_test.py +84 -0
  19. crosshair/core.py +1763 -0
  20. crosshair/core_and_libs.py +149 -0
  21. crosshair/core_regestered_types_test.py +82 -0
  22. crosshair/core_test.py +1316 -0
  23. crosshair/diff_behavior.py +314 -0
  24. crosshair/diff_behavior_test.py +261 -0
  25. crosshair/dynamic_typing.py +346 -0
  26. crosshair/dynamic_typing_test.py +210 -0
  27. crosshair/enforce.py +282 -0
  28. crosshair/enforce_test.py +182 -0
  29. crosshair/examples/PEP316/__init__.py +1 -0
  30. crosshair/examples/PEP316/bugs_detected/__init__.py +0 -0
  31. crosshair/examples/PEP316/bugs_detected/getattr_magic.py +16 -0
  32. crosshair/examples/PEP316/bugs_detected/hash_consistent_with_equals.py +31 -0
  33. crosshair/examples/PEP316/bugs_detected/shopping_cart.py +24 -0
  34. crosshair/examples/PEP316/bugs_detected/showcase.py +39 -0
  35. crosshair/examples/PEP316/correct_code/__init__.py +0 -0
  36. crosshair/examples/PEP316/correct_code/arith.py +60 -0
  37. crosshair/examples/PEP316/correct_code/chess.py +77 -0
  38. crosshair/examples/PEP316/correct_code/nesting_inference.py +17 -0
  39. crosshair/examples/PEP316/correct_code/numpy_examples.py +132 -0
  40. crosshair/examples/PEP316/correct_code/rolling_average.py +35 -0
  41. crosshair/examples/PEP316/correct_code/showcase.py +104 -0
  42. crosshair/examples/__init__.py +0 -0
  43. crosshair/examples/check_examples_test.py +146 -0
  44. crosshair/examples/deal/__init__.py +1 -0
  45. crosshair/examples/icontract/__init__.py +1 -0
  46. crosshair/examples/icontract/bugs_detected/__init__.py +0 -0
  47. crosshair/examples/icontract/bugs_detected/showcase.py +41 -0
  48. crosshair/examples/icontract/bugs_detected/wrong_sign.py +8 -0
  49. crosshair/examples/icontract/correct_code/__init__.py +0 -0
  50. crosshair/examples/icontract/correct_code/arith.py +51 -0
  51. crosshair/examples/icontract/correct_code/showcase.py +94 -0
  52. crosshair/fnutil.py +391 -0
  53. crosshair/fnutil_test.py +75 -0
  54. crosshair/fuzz_core_test.py +516 -0
  55. crosshair/libimpl/__init__.py +0 -0
  56. crosshair/libimpl/arraylib.py +161 -0
  57. crosshair/libimpl/binascii_ch_test.py +30 -0
  58. crosshair/libimpl/binascii_test.py +67 -0
  59. crosshair/libimpl/binasciilib.py +150 -0
  60. crosshair/libimpl/bisectlib_test.py +23 -0
  61. crosshair/libimpl/builtinslib.py +5228 -0
  62. crosshair/libimpl/builtinslib_ch_test.py +1191 -0
  63. crosshair/libimpl/builtinslib_test.py +3735 -0
  64. crosshair/libimpl/codecslib.py +86 -0
  65. crosshair/libimpl/codecslib_test.py +86 -0
  66. crosshair/libimpl/collectionslib.py +264 -0
  67. crosshair/libimpl/collectionslib_ch_test.py +252 -0
  68. crosshair/libimpl/collectionslib_test.py +332 -0
  69. crosshair/libimpl/copylib.py +23 -0
  70. crosshair/libimpl/copylib_test.py +18 -0
  71. crosshair/libimpl/datetimelib.py +2559 -0
  72. crosshair/libimpl/datetimelib_ch_test.py +354 -0
  73. crosshair/libimpl/datetimelib_test.py +112 -0
  74. crosshair/libimpl/decimallib.py +5257 -0
  75. crosshair/libimpl/decimallib_ch_test.py +78 -0
  76. crosshair/libimpl/decimallib_test.py +76 -0
  77. crosshair/libimpl/encodings/__init__.py +23 -0
  78. crosshair/libimpl/encodings/_encutil.py +187 -0
  79. crosshair/libimpl/encodings/ascii.py +44 -0
  80. crosshair/libimpl/encodings/latin_1.py +40 -0
  81. crosshair/libimpl/encodings/utf_8.py +93 -0
  82. crosshair/libimpl/encodings_ch_test.py +83 -0
  83. crosshair/libimpl/fractionlib.py +16 -0
  84. crosshair/libimpl/fractionlib_test.py +80 -0
  85. crosshair/libimpl/functoolslib.py +34 -0
  86. crosshair/libimpl/functoolslib_test.py +56 -0
  87. crosshair/libimpl/hashliblib.py +30 -0
  88. crosshair/libimpl/hashliblib_test.py +18 -0
  89. crosshair/libimpl/heapqlib.py +47 -0
  90. crosshair/libimpl/heapqlib_test.py +21 -0
  91. crosshair/libimpl/importliblib.py +18 -0
  92. crosshair/libimpl/importliblib_test.py +38 -0
  93. crosshair/libimpl/iolib.py +216 -0
  94. crosshair/libimpl/iolib_ch_test.py +128 -0
  95. crosshair/libimpl/iolib_test.py +19 -0
  96. crosshair/libimpl/ipaddresslib.py +8 -0
  97. crosshair/libimpl/itertoolslib.py +44 -0
  98. crosshair/libimpl/itertoolslib_test.py +44 -0
  99. crosshair/libimpl/jsonlib.py +984 -0
  100. crosshair/libimpl/jsonlib_ch_test.py +42 -0
  101. crosshair/libimpl/jsonlib_test.py +51 -0
  102. crosshair/libimpl/mathlib.py +179 -0
  103. crosshair/libimpl/mathlib_ch_test.py +44 -0
  104. crosshair/libimpl/mathlib_test.py +67 -0
  105. crosshair/libimpl/oslib.py +7 -0
  106. crosshair/libimpl/pathliblib_test.py +10 -0
  107. crosshair/libimpl/randomlib.py +178 -0
  108. crosshair/libimpl/randomlib_test.py +120 -0
  109. crosshair/libimpl/relib.py +846 -0
  110. crosshair/libimpl/relib_ch_test.py +169 -0
  111. crosshair/libimpl/relib_test.py +493 -0
  112. crosshair/libimpl/timelib.py +72 -0
  113. crosshair/libimpl/timelib_test.py +82 -0
  114. crosshair/libimpl/typeslib.py +15 -0
  115. crosshair/libimpl/typeslib_test.py +36 -0
  116. crosshair/libimpl/unicodedatalib.py +75 -0
  117. crosshair/libimpl/unicodedatalib_test.py +42 -0
  118. crosshair/libimpl/urlliblib.py +23 -0
  119. crosshair/libimpl/urlliblib_test.py +19 -0
  120. crosshair/libimpl/weakreflib.py +13 -0
  121. crosshair/libimpl/weakreflib_test.py +69 -0
  122. crosshair/libimpl/zliblib.py +15 -0
  123. crosshair/libimpl/zliblib_test.py +13 -0
  124. crosshair/lsp_server.py +261 -0
  125. crosshair/lsp_server_test.py +30 -0
  126. crosshair/main.py +973 -0
  127. crosshair/main_test.py +543 -0
  128. crosshair/objectproxy.py +376 -0
  129. crosshair/objectproxy_test.py +41 -0
  130. crosshair/opcode_intercept.py +601 -0
  131. crosshair/opcode_intercept_test.py +304 -0
  132. crosshair/options.py +218 -0
  133. crosshair/options_test.py +10 -0
  134. crosshair/patch_equivalence_test.py +75 -0
  135. crosshair/path_cover.py +209 -0
  136. crosshair/path_cover_test.py +138 -0
  137. crosshair/path_search.py +161 -0
  138. crosshair/path_search_test.py +52 -0
  139. crosshair/pathing_oracle.py +271 -0
  140. crosshair/pathing_oracle_test.py +21 -0
  141. crosshair/pure_importer.py +27 -0
  142. crosshair/pure_importer_test.py +16 -0
  143. crosshair/py.typed +0 -0
  144. crosshair/register_contract.py +273 -0
  145. crosshair/register_contract_test.py +190 -0
  146. crosshair/simplestructs.py +1165 -0
  147. crosshair/simplestructs_test.py +283 -0
  148. crosshair/smtlib.py +24 -0
  149. crosshair/smtlib_test.py +14 -0
  150. crosshair/statespace.py +1199 -0
  151. crosshair/statespace_test.py +108 -0
  152. crosshair/stubs_parser.py +352 -0
  153. crosshair/stubs_parser_test.py +43 -0
  154. crosshair/test_util.py +329 -0
  155. crosshair/test_util_test.py +26 -0
  156. crosshair/tools/__init__.py +0 -0
  157. crosshair/tools/check_help_in_doc.py +264 -0
  158. crosshair/tools/check_init_and_setup_coincide.py +119 -0
  159. crosshair/tools/generate_demo_table.py +127 -0
  160. crosshair/tracers.py +544 -0
  161. crosshair/tracers_test.py +154 -0
  162. crosshair/type_repo.py +151 -0
  163. crosshair/unicode_categories.py +589 -0
  164. crosshair/unicode_categories_test.py +27 -0
  165. crosshair/util.py +741 -0
  166. crosshair/util_test.py +173 -0
  167. crosshair/watcher.py +307 -0
  168. crosshair/watcher_test.py +107 -0
  169. crosshair/z3util.py +76 -0
  170. crosshair/z3util_test.py +11 -0
  171. crosshair_tool-0.0.99.dist-info/METADATA +144 -0
  172. crosshair_tool-0.0.99.dist-info/RECORD +176 -0
  173. crosshair_tool-0.0.99.dist-info/WHEEL +6 -0
  174. crosshair_tool-0.0.99.dist-info/entry_points.txt +3 -0
  175. crosshair_tool-0.0.99.dist-info/licenses/LICENSE +93 -0
  176. crosshair_tool-0.0.99.dist-info/top_level.txt +2 -0
@@ -0,0 +1,190 @@
1
+ import random
2
+ import sys
3
+ import time
4
+ from inspect import Parameter, Signature
5
+ from random import Random, randint
6
+ from typing import Union, overload
7
+
8
+ import numpy as np
9
+ import pytest
10
+
11
+ import crosshair.register_contract
12
+ from crosshair.register_contract import (
13
+ get_contract,
14
+ register_contract,
15
+ register_modules,
16
+ )
17
+ from crosshair.statespace import CONFIRMED, POST_FAIL, MessageType
18
+ from crosshair.test_util import check_states
19
+
20
+
21
+ @pytest.fixture(autouse=True)
22
+ def clear_registrations():
23
+ """Revert the registered contracts and modules after each test."""
24
+ orig_contracts = crosshair.register_contract.REGISTERED_CONTRACTS.copy()
25
+ orig_modules = crosshair.register_contract.REGISTERED_MODULES.copy()
26
+ crosshair.register_contract.REGISTERED_CONTRACTS = {}
27
+ crosshair.register_contract.REGISTERED_MODULES = set()
28
+ yield None
29
+ crosshair.register_contract.REGISTERED_CONTRACTS = orig_contracts
30
+ crosshair.register_contract.REGISTERED_MODULES = orig_modules
31
+
32
+
33
+ def test_register_bound_method():
34
+ assert not register_contract(randint)
35
+
36
+
37
+ def test_register_malformed_contract():
38
+ assert not register_contract(
39
+ Random.randint,
40
+ pre=lambda a, wrong_name: a <= wrong_name,
41
+ )
42
+
43
+
44
+ def test_register_malformed_signature():
45
+ # The signature has wrong arg names (should be `a` and `b`).
46
+ sig = Signature(
47
+ [
48
+ Parameter("self", Parameter.POSITIONAL_OR_KEYWORD),
49
+ Parameter("low", Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
50
+ Parameter("high", Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
51
+ ],
52
+ return_annotation=int,
53
+ )
54
+ assert not register_contract(Random.randint, sig=sig)
55
+
56
+
57
+ def test_register_randint():
58
+ def f(x: int) -> int:
59
+ """
60
+ pre: x <= 10
61
+ post: _ >= x
62
+ """
63
+ return randint(x, 10)
64
+
65
+ randint_sig = None
66
+ register_contract(
67
+ Random.randint,
68
+ pre=lambda a, b: a <= b,
69
+ post=lambda __return__, a, b: a <= __return__ <= b,
70
+ sig=randint_sig,
71
+ )
72
+ check_states(f, CONFIRMED)
73
+
74
+
75
+ def test_register_numpy_randint():
76
+ def f(x: int) -> int:
77
+ """
78
+ pre: x < 10
79
+ post: _ >= x
80
+ """
81
+ return np.random.randint(x, 10)
82
+
83
+ sig = Signature(
84
+ parameters=[
85
+ Parameter("self", Parameter.POSITIONAL_OR_KEYWORD),
86
+ Parameter("low", Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
87
+ Parameter("high", Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
88
+ ],
89
+ return_annotation=int,
90
+ )
91
+ register_contract(
92
+ np.random.RandomState.randint,
93
+ pre=lambda low, high: low < high,
94
+ post=lambda __return__, low, high: low <= __return__ < high,
95
+ sig=sig,
96
+ )
97
+ check_states(f, CONFIRMED)
98
+
99
+
100
+ def test_register_overload():
101
+ @overload
102
+ def overld(a: int) -> int: ...
103
+
104
+ @overload
105
+ def overld(a: str) -> str: ...
106
+
107
+ def overld(a: Union[int, str]) -> Union[int, str]:
108
+ if isinstance(a, int):
109
+ return -a if a < 0 else a
110
+ else:
111
+ return "hello: " + a
112
+
113
+ def f1(x: int) -> int:
114
+ """
115
+ post: _ >= 0
116
+ """
117
+ return overld(x)
118
+
119
+ def f2(x: str) -> str:
120
+ """
121
+ post: len(_) > 6
122
+ """
123
+ return overld(x)
124
+
125
+ sig_1 = Signature(
126
+ parameters=[Parameter("a", Parameter.POSITIONAL_OR_KEYWORD, annotation=int)],
127
+ return_annotation=int,
128
+ )
129
+ sig_2 = Signature(
130
+ parameters=[Parameter("a", Parameter.POSITIONAL_OR_KEYWORD, annotation=str)],
131
+ return_annotation=str,
132
+ )
133
+
134
+ def post_cond(a, __return__):
135
+ if isinstance(a, str):
136
+ return len(__return__) > 6
137
+ if isinstance(a, int):
138
+ return __return__ > 0
139
+ return False
140
+
141
+ register_contract(
142
+ overld,
143
+ post=post_cond,
144
+ sig=[sig_1, sig_2],
145
+ )
146
+ check_states(f1, CONFIRMED)
147
+ check_states(f2, CONFIRMED)
148
+
149
+
150
+ def test_register_two_steps():
151
+ def f():
152
+ pass
153
+
154
+ sig1 = Signature(parameters=[], return_annotation=int)
155
+ sig2 = Signature(parameters=[], return_annotation=float)
156
+ sig3 = Signature(parameters=[], return_annotation=str)
157
+ register_contract(f, sig=sig1)
158
+ register_contract(f, sig=[sig2, sig3])
159
+ assert get_contract(f).sigs == [sig1, sig2, sig3]
160
+
161
+
162
+ def test_register_twice_with_different_post():
163
+ def f() -> int:
164
+ return 4
165
+
166
+ register_contract(f)
167
+ assert not register_contract(f, post=lambda __return__: __return__ == 4)
168
+
169
+
170
+ if sys.version_info >= (3, 8):
171
+
172
+ def test_register_modules():
173
+ def f() -> int:
174
+ """
175
+ post: _ >= 0
176
+ """
177
+ return time.time_ns()
178
+
179
+ register_modules(time)
180
+ check_states(f, POST_FAIL)
181
+ crosshair.register_contract
182
+
183
+ def f() -> int:
184
+ """
185
+ post: _ > 0
186
+ """
187
+ return randint(5, 10)
188
+
189
+ register_modules(random)
190
+ check_states(f, POST_FAIL)