Package test :: Module test_support
[hide private]
[frames] | no frames]

Module test_support

Supporting definitions for the Python regression tests.

Classes [hide private]
Error
Base class for regression test exceptions.
TestFailed
Test failed.
TestSkipped
Test skipped.
ResourceDenied
Test skipped because it requested a disallowed resource.
_Dummy
BasicTestRunner
Functions [hide private]
 
record_original_stdout(stdout)
 
get_original_stdout()
 
unload(name)
 
unlink(filename)
 
forget(modname)
"Forget" a module was ever imported by removing it from sys.modules and deleting any .pyc and .pyo files.
 
is_resource_enabled(resource)
Test whether a resource is enabled.
 
requires(resource, msg=None)
Raise ResourceDenied if the specified resource is not available.
 
bind_port(sock, host='', preferred_port=54321)
Try to bind the sock to a port.
 
fcmp(x, y)
 
findfile(file, here='/usr/lib/python2.5/test/test_support.pyc')
Try to find a file on sys.path and the working directory.
 
verify(condition, reason='test failed')
Verify that condition is true.
 
vereq(a, b)
Raise TestFailed if a == b is false.
 
sortdict(dict)
Like repr(dict), but in sorted order.
 
check_syntax(statement)
 
open_urlresource(url)
 
run_with_locale(catstr, *locales)
 
set_memlimit(limit)
 
bigmemtest(minsize, memuse, overhead=5242880)
Decorator for bigmem tests.
 
bigaddrspacetest(f)
Decorator for tests that fill the address space.
 
run_suite(suite, testclass=None)
Run tests from a unittest.TestSuite-derived class.
 
run_unittest(*classes)
Run tests from unittest.TestCase-derived classes.
 
run_doctest(module, verbosity=None)
Run doctest on the given module.
 
threading_setup()
 
threading_cleanup(num_active, num_limbo)
 
reap_children()
Use this function at the end of test_main() whenever sub-processes are started.
Variables [hide private]
  verbose = 1
  use_resources = None
  max_memuse = 0
  _original_stdout = None
  FUZZ = 1e-06
  have_unicode = 1
  is_jython = False
  TESTFN_UNICODE = u'@test-àò'
  TESTFN_ENCODING = 'UTF-8'
  TESTFN_UNICODE_UNENCODEABLE = None
  TESTFN = '@test'
  _1M = 1048576
  _1G = 1073741824
  _2G = 2147483648
  MAX_Py_ssize_t = 2147483647

Imports: sys, unittest


Function Details [hide private]

is_resource_enabled(resource)

 

Test whether a resource is enabled. Known resources are set by regrtest.py.

requires(resource, msg=None)

 

Raise ResourceDenied if the specified resource is not available.

If the caller's module is __main__ then automatically return True. The possibility of False being returned occurs when regrtest.py is executing.

bind_port(sock, host='', preferred_port=54321)

 

Try to bind the sock to a port. If we are running multiple tests and we don't try multiple ports, the test can fails. This makes the test more robust.

findfile(file, here='/usr/lib/python2.5/test/test_support.pyc')

 

Try to find a file on sys.path and the working directory. If it is not found the argument passed to the function is returned (this does not necessarily signal failure; could still be the legitimate path).

verify(condition, reason='test failed')

 

Verify that condition is true. If not, raise TestFailed.

The optional argument reason can be given to provide a better error text.

vereq(a, b)

 

Raise TestFailed if a == b is false.

This is better than verify(a == b) because, in case of failure, the error message incorporates repr(a) and repr(b) so you can see the inputs.

Note that "not (a == b)" isn't necessarily the same as "a != b"; the former is tested.

bigmemtest(minsize, memuse, overhead=5242880)

 

Decorator for bigmem tests.

'minsize' is the minimum useful size for the test (in arbitrary, test-interpreted units.) 'memuse' is the number of 'bytes per size' for the test, or a good estimate of it. 'overhead' specifies fixed overhead, independant of the testsize, and defaults to 5Mb.

The decorator tries to guess a good value for 'size' and passes it to the decorated test function. If minsize * memuse is more than the allowed memory use (as defined by max_memuse), the test is skipped. Otherwise, minsize is adjusted upward to use up to max_memuse.

run_doctest(module, verbosity=None)

 

Run doctest on the given module. Return (#failures, #tests).

If optional argument verbosity is not specified (or is None), pass test_support's belief about verbosity on to doctest. Else doctest's usual behavior is used (it searches sys.argv for -v).

reap_children()

 

Use this function at the end of test_main() whenever sub-processes are started. This will help ensure that no extra children (zombies) stick around to hog resources and create problems when looking for refleaks.