def test_all(): parsers = ['gccxml', 'clang'] cases = [{'parser': p} for p in parsers] cwd = os.getcwd() base = os.path.dirname(cwd) path = base if 'PYTHONPATH' in os.environ: path = path+':'+os.environ['PYTHONPATH'] pyexec = sys.executable xdexec = os.path.join(base, 'scripts', 'xdress') defaults = {'cwd': cwd, 'base': base, 'pyexec': pyexec, 'xdexec': xdexec, 'instdir': INSTDIR, 'rootdir': ROOTDIR, 'path': path, 'builddir': os.path.join(PROJDIR, 'build')} commands = ( 'PYTHONPATH="{path}" {pyexec} {xdexec} --debug -p={parser} --builddir="{builddir}"\n' '{pyexec} setup.py install --prefix="{instdir}" --root="{rootdir}" -- --\n' ) for case in cases: parser = case['parser'] instdir = case['instdir'] = defaults['instdir'] + '-' + parser builddir = case['builddir'] = defaults['builddir'] + '-' + parser if not PARSERS_AVAILABLE[parser]: yield skip_then_continue, parser + " unavailable" continue cleanfs(GENERATED_PATHS) rtn = 1 holdsrtn = [rtn] # needed because nose does not send() to test generator fill = dict(defaults) fill.update(case) cmds = commands.format(**fill).strip().splitlines() for cmd in cmds: yield check_cmd, cmd, PROJDIR, holdsrtn rtn = holdsrtn[0] if rtn != 0: break # don't execute further commands if rtn != 0: break # don't try further cases # we have now run xdress and build the project # What follow are project unit tests, no need to break on these instsite = os.path.join(instdir, 'lib', 'python*', 'site-packages') instsite = glob.glob(instsite)[0] instproj = os.path.join(instsite, PROJNAME) for testfile in dirtests(TESTDIR): with clean_import(testfile, [TESTDIR, instproj, instsite]) as testmod: for test in modtests(testmod): print(test) yield test else: cleanfs(GENERATED_PATHS)
def test_describe_cpp(): rc = parse_global_rc() clang_includes = rc.clang_includes if "clang_includes" in rc else () testdir = os.path.dirname(__file__) fname = os.path.join(testdir, "toaster.h") buildbase = os.path.join(testdir, "build") ts.register_class("Base", ("T", "i"), cpp_type="Base") ts.register_class("Point", ("B", "C"), cpp_type="Point") ts.register_classname("Toaster", "toaster", "toaster", "cpp_toaster") for name in "NoDefaultBase", "NoDefault", "Default": ts.register_class(name, cpp_type=name) def check(parser): goals = ( ("class", ("Base", "int32", 7, 0), exp_base_desc(parser)), ("class", ("Point", True, "CA", 0), exp_point_desc), ("class", "Toaster", exp_toaster_desc), ("func", "simple", exp_simple_desc), # Verify that we pick up parameter names from definitions ("func", "twice", exp_twice_desc), # Verify that the first parameter name declaration wins ("func", "conflict", exp_conflict_desc), ("func", ("lasso", 17, "int32", "float32"), exp_lasso_desc(17)), ("func", ("lasso", 18, "int32", "float32"), exp_lasso_desc(18)), ("class", "Default", exp_default_desc), ("class", "NoDefaultBase", exp_nodefault_base_desc), ("class", "NoDefault", exp_nodefault_desc), ("var", "Choices", exp_choices_desc), ) for kind, name, exp in goals: obs = ad.describe( fname, name=name, kind=kind, parsers=parser, builddir=buildbase + "-" + parser, verbose=False, ts=ts, clang_includes=clang_includes, ) assert_equal_or_diff(obs, exp) for parser in "gccxml", "clang": cleanfs(buildbase + "-" + parser) if PARSERS_AVAILABLE[parser]: yield check, parser else: yield skip_then_continue, parser + " unavailable"
def test_describe_cpp(): rc = parse_global_rc() clang_includes = rc.clang_includes if 'clang_includes' in rc else () testdir = os.path.dirname(__file__) fname = os.path.join(testdir, 'toaster.h') buildbase = os.path.join(testdir, 'build') ts.register_class('Base', ('T', 'i'), cpp_type='Base') ts.register_class('Point', ('B', 'C'), cpp_type='Point') ts.register_classname('Toaster', 'toaster', 'toaster', 'cpp_toaster') for name in 'NoDefaultBase', 'NoDefault', 'Default': ts.register_class(name, cpp_type=name) def check(parser): goals = ( ('class', ('Base', 'int32', 7, 0), exp_base_desc(parser)), ('class', ('Point', True, 'CA', 0), exp_point_desc), ('class', 'Toaster', exp_toaster_desc), ('func', 'simple', exp_simple_desc), # Verify that we pick up parameter names from definitions ('func', 'twice', exp_twice_desc), # Verify that the first parameter name declaration wins ('func', 'conflict', exp_conflict_desc), ('func', ('lasso', 17, 'int32', 'float32'), exp_lasso_desc(17)), ('func', ('lasso', 18, 'int32', 'float32'), exp_lasso_desc(18)), ('class', 'Default', exp_default_desc), ('class', 'NoDefaultBase', exp_nodefault_base_desc), ('class', 'NoDefault', exp_nodefault_desc), ('var', 'Choices', exp_choices_desc)) for kind, name, exp in goals: obs = ad.describe(fname, name=name, kind=kind, parsers=parser, builddir=buildbase + '-' + parser, verbose=False, ts=ts, clang_includes=clang_includes) assert_equal_or_diff(obs, exp) for parser in 'gccxml', 'clang': cleanfs(buildbase + '-' + parser) if PARSERS_AVAILABLE[parser]: yield check, parser else: yield skip_then_continue, parser + ' unavailable'
def test_autoall(): rc = parse_global_rc() clang_includes = rc.clang_includes if 'clang_includes' in rc else () exp_var = ['Choice'] exp_fun = ['foo'] exp_cls = ['Blah'] testdir = os.path.dirname(__file__) filename = os.path.join(testdir, 'all.h') buildbase = os.path.join(testdir, 'build') def check_all(parser): obs_var, obs_fun, obs_cls = autoall.findall(filename, parsers=parser, builddir=buildbase + '-' + parser, clang_includes=clang_includes) assert_equal_or_diff(obs_var, exp_var) assert_equal_or_diff(obs_fun, exp_fun) assert_equal_or_diff(obs_cls, exp_cls) for parser in 'gccxml', 'clang': cleanfs(buildbase + '-' + parser) if PARSERS_AVAILABLE[parser]: yield check_all, parser else: yield skip_then_continue, parser + ' unavailable'
def test_describe_cpp(): rc = parse_global_rc() clang_includes = rc.clang_includes if 'clang_includes' in rc else () testdir = os.path.dirname(__file__) fname = os.path.join(testdir, 'toaster.h') buildbase = os.path.join(testdir, 'build') ts.register_class('Base', ('T', 'i'), cpp_type='Base') ts.register_class('Point', ('B', 'C'), cpp_type='Point') ts.register_classname('Toaster', 'toaster', 'toaster', 'cpp_toaster') for name in 'NoDefaultBase', 'NoDefault', 'Default': ts.register_class(name, cpp_type=name) def check(parser): goals = (('class', ('Base', 'int32', 7, 0), exp_base_desc(parser)), ('class', ('Point', True, 'CA', 0), exp_point_desc), ('class', 'Toaster', exp_toaster_desc), ('func', 'simple', exp_simple_desc), # Verify that we pick up parameter names from definitions ('func', 'twice', exp_twice_desc), # Verify that the first parameter name declaration wins ('func', 'conflict', exp_conflict_desc), ('func', ('lasso', 17, 'int32', 'float32'), exp_lasso_desc(17)), ('func', ('lasso', 18, 'int32', 'float32'), exp_lasso_desc(18)), ('class', 'Default', exp_default_desc), ('class', 'NoDefaultBase', exp_nodefault_base_desc), ('class', 'NoDefault', exp_nodefault_desc), ('var', 'Choices', exp_choices_desc)) for kind, name, exp in goals: obs = ad.describe(fname, name=name, kind=kind, parsers=parser, builddir=buildbase + '-' + parser, verbose=False, ts=ts, clang_includes=clang_includes) assert_equal_or_diff(obs, exp) for parser in 'gccxml', 'clang': cleanfs(buildbase + '-' + parser) if PARSERS_AVAILABLE[parser]: yield check, parser else: yield skip_then_continue, parser + ' unavailable'