@@ -182,8 +182,24 @@ def codemod(path):
182
182
flag_value = "equivalent" ,
183
183
help = "very useful when optimising or refactoring code" ,
184
184
)
185
- @click .option ("--idempotent" , "writer" , flag_value = "idempotent" )
186
- @click .option ("--binary-op" , "writer" , flag_value = "binary_operation" )
185
+ @click .option (
186
+ "--errors-equivalent" ,
187
+ "writer" ,
188
+ flag_value = "errors-equivalent" ,
189
+ help = "--equivalent, but also allows consistent errors" ,
190
+ )
191
+ @click .option (
192
+ "--idempotent" ,
193
+ "writer" ,
194
+ flag_value = "idempotent" ,
195
+ help = "check that f(x) == f(f(x))" ,
196
+ )
197
+ @click .option (
198
+ "--binary-op" ,
199
+ "writer" ,
200
+ flag_value = "binary_operation" ,
201
+ help = "associativity, commutativity, identity element" ,
202
+ )
187
203
# Note: we deliberately omit a --ufunc flag, because the magic()
188
204
# detection of ufuncs is both precise and complete.
189
205
@click .option (
@@ -218,22 +234,26 @@ def write(func, writer, except_, style): # noqa: D301 # \b disables autowrap
218
234
# NOTE: if you want to call this function from Python, look instead at the
219
235
# ``hypothesis.extra.ghostwriter`` module. Click-decorated functions have
220
236
# a different calling convention, and raise SystemExit instead of returning.
237
+ kwargs = {"except_" : except_ or (), "style" : style }
221
238
if writer is None :
222
239
writer = "magic"
223
240
elif writer == "idempotent" and len (func ) > 1 :
224
241
raise click .UsageError ("Test functions for idempotence one at a time." )
225
242
elif writer == "roundtrip" and len (func ) == 1 :
226
243
writer = "idempotent"
227
- elif writer == "equivalent" and len (func ) == 1 :
244
+ elif "equivalent" in writer and len (func ) == 1 :
228
245
writer = "fuzz"
246
+ if writer == "errors-equivalent" :
247
+ writer = "equivalent"
248
+ kwargs ["allow_same_errors" ] = True
229
249
230
250
try :
231
251
from hypothesis .extra import ghostwriter
232
252
except ImportError :
233
253
sys .stderr .write (MESSAGE .format ("black" ))
234
254
sys .exit (1 )
235
255
236
- code = getattr (ghostwriter , writer )(* func , except_ = except_ or (), style = style )
256
+ code = getattr (ghostwriter , writer )(* func , ** kwargs )
237
257
try :
238
258
from rich .console import Console
239
259
from rich .syntax import Syntax
@@ -242,10 +262,10 @@ def write(func, writer, except_, style): # noqa: D301 # \b disables autowrap
242
262
except ImportError :
243
263
print (code )
244
264
else :
245
- code = Syntax (
246
- code ,
247
- "python" ,
248
- background_color = "default" ,
249
- theme = "default" if guess_background_color () == "light" else "monokai" ,
250
- )
251
- Console (). print (code , soft_wrap = True )
265
+ try :
266
+ theme = "default" if guess_background_color () == "light" else "monokai"
267
+ code = Syntax ( code , "python" , background_color = "default" , theme = theme )
268
+ Console (). print ( code , soft_wrap = True )
269
+ except Exception :
270
+ print ( "# Error while syntax-highlighting code" , file = sys . stderr )
271
+ print (code )
0 commit comments