Don't like writing dedicated test code? Let battle_tested do it for you.


In [1]:
%xmode plain


Exception reporting mode: Plain

In [2]:
from battle_tested import battle_tested

@battle_tested()
def hardened_int(a):
    """ makes an int no matter what """
    try:
        return int(a)
    except (ValueError, TypeError):
        return 0


testing: hardened_int()
Falsifying example: fuzz(arg_list=[Decimal('Infinity')])
total tests: 14
Traceback (most recent call last):

  File "<ipython-input-2-a1981437fc5c>", line 3, in <module>
    @battle_tested()

  File "/Users/cody/py3/lib/python3.6/site-packages/battle_tested/__init__.py", line 447, in __call__
    self.fuzz(fn, seconds=self.seconds, max_tests=self.max_tests, verbose=self.verbose)

  File "/Users/cody/py3/lib/python3.6/site-packages/battle_tested/__init__.py", line 428, in fuzz
    fuzz()

  File "/Users/cody/py3/lib/python3.6/site-packages/battle_tested/__init__.py", line 392, in fuzz
    @given(strategy)

  File "/Users/cody/py3/lib/python3.6/site-packages/hypothesis/core.py", line 648, in wrapped_test
    state.run()

  File "/Users/cody/py3/lib/python3.6/site-packages/hypothesis/core.py", line 542, in run
    print_example=True, is_final=True

  File "/Users/cody/py3/lib/python3.6/site-packages/hypothesis/executors.py", line 58, in default_new_style_executor
    return function(data)

  File "/Users/cody/py3/lib/python3.6/site-packages/hypothesis/core.py", line 111, in run
    return test(*args, **kwargs)

  File "/Users/cody/py3/lib/python3.6/site-packages/battle_tested/__init__.py", line 424, in fuzz
    raise ex

  File "/Users/cody/py3/lib/python3.6/site-packages/battle_tested/__init__.py", line 399, in fuzz
    fn(*arg_list)

  File "<ipython-input-2-a1981437fc5c>", line 7, in hardened_int
    return int(a)

OverflowError: 

--------------------- battle_tested crashed hardened_int() ---------------------

Error Message:

   OverflowError - cannot convert Infinity to integer

Breakpoint: <ipython-input-2-a1981437fc5c> - line 7
To reproduce this error, run:

   hardened_int(Decimal('Infinity'))

----------------------------------------------------------------------------------


In [ ]: