Back to index

python3.2  3.2.2
Namespaces | Classes | Functions | Variables
ctypes.test Namespace Reference

Namespaces

namespace  runtests
namespace  test_anon
namespace  test_array_in_pointer
namespace  test_arrays
namespace  test_as_parameter
namespace  test_bitfields
namespace  test_buffers
namespace  test_bytes
namespace  test_byteswap
namespace  test_callbacks
namespace  test_cast
namespace  test_cfuncs
namespace  test_checkretval
namespace  test_delattr
namespace  test_errcheck
namespace  test_errno
namespace  test_find
namespace  test_frombuffer
namespace  test_funcptr
namespace  test_functions
namespace  test_incomplete
namespace  test_init
namespace  test_integers
namespace  test_internals
namespace  test_keeprefs
namespace  test_libc
namespace  test_loading
namespace  test_macholib
namespace  test_memfunctions
namespace  test_numbers
namespace  test_objects
namespace  test_parameters
namespace  test_pep3118
namespace  test_pickling
namespace  test_pointers
namespace  test_prototypes
namespace  test_python_api
namespace  test_random_things
namespace  test_refcounts
namespace  test_repr
namespace  test_returnfuncptrs
namespace  test_simplesubclasses
namespace  test_sizes
namespace  test_slicing
namespace  test_stringptr
namespace  test_strings
namespace  test_struct_fields
namespace  test_structures
namespace  test_unaligned_structures
namespace  test_unicode
namespace  test_values
namespace  test_varsize_struct
namespace  test_win32

Classes

class  ResourceDenied
class  TestRunner
class  BasicTestRunner

Functions

def is_resource_enabled
def requires
def find_package_modules
def get_tests
def usage
def test_with_refcounts
def main
def run_tests

Variables

list use_resources = []
dictionary _unavail = {}

Function Documentation

def ctypes.test.find_package_modules (   package,
  mask 
)

Definition at line 38 of file __init__.py.

00038 
00039 def find_package_modules(package, mask):
00040     import fnmatch
00041     if (hasattr(package, "__loader__") and
00042             hasattr(package.__loader__, '_files')):
00043         path = package.__name__.replace(".", os.path.sep)
00044         mask = os.path.join(path, mask)
00045         for fnm in package.__loader__._files.keys():
00046             if fnmatch.fnmatchcase(fnm, mask):
00047                 yield os.path.splitext(fnm)[0].replace(os.path.sep, ".")
00048     else:
00049         path = package.__path__[0]
00050         for fnm in os.listdir(path):
00051             if fnmatch.fnmatchcase(fnm, mask):
00052                 yield "%s.%s" % (package.__name__, os.path.splitext(fnm)[0])

Here is the call graph for this function:

Here is the caller graph for this function:

def ctypes.test.get_tests (   package,
  mask,
  verbosity,
  exclude = () 
)
Return a list of skipped test modules, and a list of test cases.

Definition at line 53 of file __init__.py.

00053 
00054 def get_tests(package, mask, verbosity, exclude=()):
00055     """Return a list of skipped test modules, and a list of test cases."""
00056     tests = []
00057     skipped = []
00058     for modname in find_package_modules(package, mask):
00059         if modname.split(".")[-1] in exclude:
00060             skipped.append(modname)
00061             if verbosity > 1:
00062                 print("Skipped %s: excluded" % modname, file=sys.stderr)
00063             continue
00064         try:
00065             mod = __import__(modname, globals(), locals(), ['*'])
00066         except ResourceDenied as detail:
00067             skipped.append(modname)
00068             if verbosity > 1:
00069                 print("Skipped %s: %s" % (modname, detail), file=sys.stderr)
00070             continue
00071         for name in dir(mod):
00072             if name.startswith("_"):
00073                 continue
00074             o = getattr(mod, name)
00075             if type(o) is type(unittest.TestCase) and issubclass(o, unittest.TestCase):
00076                 tests.append(o)
00077     return skipped, tests

Here is the call graph for this function:

Here is the caller graph for this function:

def ctypes.test.is_resource_enabled (   resource)
Test whether a resource is enabled.

If the caller's module is __main__ then automatically return True.

Definition at line 12 of file __init__.py.

00012 
00013 def is_resource_enabled(resource):
00014     """Test whether a resource is enabled.
00015 
00016     If the caller's module is __main__ then automatically return True."""
00017     if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
00018         return True
00019     result = use_resources is not None and \
00020            (resource in use_resources or "*" in use_resources)
00021     if not result:
00022         _unavail[resource] = None
00023     return result

Here is the caller graph for this function:

def ctypes.test.main (   packages)

Definition at line 154 of file __init__.py.

00154 
00155 def main(*packages):
00156     try:
00157         opts, args = getopt.getopt(sys.argv[1:], "rqvu:x:")
00158     except getopt.error:
00159         return usage()
00160 
00161     verbosity = 1
00162     search_leaks = False
00163     exclude = []
00164     for flag, value in opts:
00165         if flag == "-q":
00166             verbosity -= 1
00167         elif flag == "-v":
00168             verbosity += 1
00169         elif flag == "-r":
00170             try:
00171                 sys.gettotalrefcount
00172             except AttributeError:
00173                 print("-r flag requires Python debug build", file=sys.stderr)
00174                 return -1
00175             search_leaks = True
00176         elif flag == "-u":
00177             use_resources.extend(value.split(","))
00178         elif flag == "-x":
00179             exclude.extend(value.split(","))
00180 
00181     mask = "test_*.py"
00182     if args:
00183         mask = args[0]
00184 
00185     for package in packages:
00186         run_tests(package, mask, verbosity, search_leaks, exclude)
00187 

Here is the call graph for this function:

def ctypes.test.requires (   resource,
  msg = None 
)
Raise ResourceDenied if the specified resource is not available.

If the caller's module is __main__ then automatically return True.

Definition at line 25 of file __init__.py.

00025 
00026 def requires(resource, msg=None):
00027     """Raise ResourceDenied if the specified resource is not available.
00028 
00029     If the caller's module is __main__ then automatically return True."""
00030     # see if the caller's module is __main__ - if so, treat as if
00031     # the resource was set
00032     if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
00033         return
00034     if not is_resource_enabled(resource):
00035         if msg is None:
00036             msg = "Use of the `%s' resource not enabled" % resource
00037         raise ResourceDenied(msg)

Here is the call graph for this function:

Here is the caller graph for this function:

def ctypes.test.run_tests (   package,
  mask,
  verbosity,
  search_leaks,
  exclude 
)

Definition at line 188 of file __init__.py.

00188 
00189 def run_tests(package, mask, verbosity, search_leaks, exclude):
00190     skipped, testcases = get_tests(package, mask, verbosity, exclude)
00191     runner = TestRunner(verbosity=verbosity)
00192 
00193     suites = [unittest.makeSuite(o) for o in testcases]
00194     suite = unittest.TestSuite(suites)
00195     result = runner.run(suite, skipped)
00196 
00197     if search_leaks:
00198         # hunt for refcount leaks
00199         runner = BasicTestRunner()
00200         for t in testcases:
00201             test_with_refcounts(runner, verbosity, t)
00202 
00203     return bool(result.errors)

Here is the call graph for this function:

Here is the caller graph for this function:

def ctypes.test.test_with_refcounts (   runner,
  verbosity,
  testcase 
)
Run testcase several times, tracking reference counts.

Definition at line 82 of file __init__.py.

00082 
00083 def test_with_refcounts(runner, verbosity, testcase):
00084     """Run testcase several times, tracking reference counts."""
00085     import gc
00086     import ctypes
00087     ptc = ctypes._pointer_type_cache.copy()
00088     cfc = ctypes._c_functype_cache.copy()
00089     wfc = ctypes._win_functype_cache.copy()
00090 
00091     # when searching for refcount leaks, we have to manually reset any
00092     # caches that ctypes has.
00093     def cleanup():
00094         ctypes._pointer_type_cache = ptc.copy()
00095         ctypes._c_functype_cache = cfc.copy()
00096         ctypes._win_functype_cache = wfc.copy()
00097         gc.collect()
00098 
00099     test = unittest.makeSuite(testcase)
00100     for i in range(5):
00101         rc = sys.gettotalrefcount()
00102         runner.run(test)
00103         cleanup()
00104     COUNT = 5
00105     refcounts = [None] * COUNT
00106     for i in range(COUNT):
00107         rc = sys.gettotalrefcount()
00108         runner.run(test)
00109         cleanup()
00110         refcounts[i] = sys.gettotalrefcount() - rc
00111     if filter(None, refcounts):
00112         print("%s leaks:\n\t" % testcase, refcounts)
00113     elif verbosity:
00114         print("%s: ok." % testcase)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file __init__.py.

00078 
00079 def usage():
00080     print(__doc__)
00081     return 1

Here is the caller graph for this function:


Variable Documentation

Definition at line 24 of file __init__.py.

Definition at line 3 of file __init__.py.