Ticket #5419: fuzz-docs.diff

File fuzz-docs.diff, 2.0 KB (added by Fraser Nevett, 17 years ago)
  • docs/testing.txt

     
    844844
    845845    The name is a string such as ``'admin/index.html'``.
    846846
     847``assertModelUnicodePassesFuzzTest(model, repeat=10):``
     848    Asserts that after having assigned random unicode data into each of the
     849    fields of an instance of the specified model that calling the
     850    ``__unicode__`` method of the instance doesn't raise a ``UnicodeError``.
     851    Random data is assigned and the ``__unicode__`` method called ``repeat``
     852    times.
     853
     854``assertFunctionPassesFuzzTest(func, arg_types=(), permitted_return_types=(), permitted_exceptions=(), repeat=10):``
     855    Asserts that the function when called with random values of the types
     856    specified by ``arg_types`` that the return value has a type from
     857    ``permitted_return_types`` and that if an exception is raised it is one
     858    that is in ``permitted_exceptions``. The function is called ``repeat``
     859    times with random data. For example:
     860
     861                  def test_func(a, b, c):
     862              if a is None or b is None:
     863                  return None
     864                      if a < b:
     865                          raise ValueError("fisrt argument is less than the second.")
     866                      if c:
     867                  return a + b
     868              else:
     869                  return a - b
     870
     871          assertFunctionPassesFuzzTest(test_func,
     872              arg_types=(int, int, bool),
     873              permitted_return_types=(None, int),
     874              permitted_exceptions=(ValueError),
     875              repeat=100)
     876
     877        The ``arg_types`` can be a sequence of sequences to indicate that an
     878        argument can have more than one type:
     879
     880          assertFunctionPassesFuzzTest(test_func,
     881              arg_types=((int, None), (int, None), bool),
     882              permitted_return_types=(None, int),
     883              permitted_exceptions=(ValueError),
     884              repeat=100)
     885       
     886        Note that you can use either ``None`` or ``types.NoneType``.
     887
    847888E-mail services
    848889---------------
    849890
Back to Top