Code Monkey home page Code Monkey logo

battle_tested's Introduction

battle_tested.py

An automated library that puts functions through hell so in production your code will have already seen worse.

How to install it?

pip install --user battle_tested

iPython Demo

In [1]: from battle_tested import fuzz

In [2]: def test(a):
   ...:     return int(a)
   ...:

In [3]: fuzz(test)
testing: test()
tests: 201          speed: 702/sec  avg: 702
tests: 484          speed: 893/sec  avg: 798
tests: 733          speed: 921/sec  avg: 839
tests: 975          speed: 919/sec  avg: 859
tests: 1138         speed: 864/sec  avg: 860
tests: 1368         speed: 858/sec  avg: 860
tests: 1681         speed: 906/sec  avg: 866
total tests: 1862
fuzzing test() found:
+------------------------+---------+
|   crash_input_types    |    12   |
|    exception_types     |    3    |
|    iffy_input_types    |    4    |
|      output_types      |    1    |
| successful_input_types |    4    |
|     unique_crashes     |    3    |
+------------------------+---------+
Out[3]:
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
|                        | +---------------------------------------------------------------+                                                                    |
|                        | |                        <class 'bytes'>                        |                                                                    |
|                        | |                        <class 'tuple'>                        |                                                                    |
|                        | |           <class 'hypothesis.types.RandomWithSeed'>           |                                                                    |
|                        | |                         <class 'dict'>                        |                                                                    |
|                        | |                        <class 'float'>                        |                                                                    |
| crash_input_types      | |                       <class 'complex'>                       |                                                                    |
|                        | |                       <class 'NoneType'>                      |                                                                    |
|                        | |                   <class 'decimal.Decimal'>                   |                                                                    |
|                        | |                         <class 'list'>                        |                                                                    |
|                        | | <class 'hypothesis.strategies.iterables.<locals>.PrettyIter'> |                                                                    |
|                        | |                         <class 'str'>                         |                                                                    |
|                        | |          <class 'hypothesis.strategies.RandomSeeder'>         |                                                                    |
|                        | +---------------------------------------------------------------+                                                                    |
|                        | +---------------+                                                                                                                    |
|                        | | OverflowError |                                                                                                                    |
| exception_types        | |   ValueError  |                                                                                                                    |
|                        | |   TypeError   |                                                                                                                    |
|                        | +---------------+                                                                                                                    |
|                        | +---------------------------+                                                                                                        |
|                        | | <class 'decimal.Decimal'> |                                                                                                        |
| iffy_input_types       | |       <class 'str'>       |                                                                                                        |
|                        | |      <class 'float'>      |                                                                                                        |
|                        | |      <class 'bytes'>      |                                                                                                        |
|                        | +---------------------------+                                                                                                        |
|                        | +---------+                                                                                                                          |
| output_types           | |   int   |                                                                                                                          |
|                        | +---------+                                                                                                                          |
|                        | +------------------------------+                                                                                                     |
|                        | |        <class 'int'>         |                                                                                                     |
| successful_input_types | |        <class 'bool'>        |                                                                                                     |
|                        | | <class 'fractions.Fraction'> |                                                                                                     |
|                        | |     <class 'uuid.UUID'>      |                                                                                                     |
|                        | +------------------------------+                                                                                                     |
|                        | +-------------------------+------------+----------+--------------------------------------------------------------------------------+ |
|                        | | exception type          | arg types  | location | crash message                                                                  | |
|                        | +-------------------------+------------+----------+--------------------------------------------------------------------------------+ |
| unique_crashes         | | <class 'OverflowError'> | ('float',) | line 2   | 'cannot convert float infinity to integer'                                     | |
|                        | | <class 'TypeError'>     | ('dict',)  | line 2   | "int() argument must be a string, a bytes-like object or a number, not 'dict'" | |
|                        | | <class 'ValueError'>    | ('bytes',) | line 2   | "invalid literal for int() with base 10: b'\\x94\\x94n-\\x81'"                 | |
|                        | +-------------------------+------------+----------+--------------------------------------------------------------------------------+ |
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------+

More Example Usage

from battle_tested import battle_tested, fuzz

@battle_tested(default_output=[], verbose=True, seconds=1, max_tests=5)
def sample(i):
    return []

@battle_tested()
def sample2(a,b,c,d=''):
    t = a, b, c, d

# proof that they only get tested once
print(sample(4))
print(sample2(1,2,3,4))
print(sample('i'))
print(sample2('a','b',2,4))

#======================================
#  Examples using the function syntax
#======================================

def sample3(input_arg):
    return True

fuzz(sample3, seconds=5, verbose=True)

battle_tested's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.