Exemple #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('branch', nargs='?', default='master')
    parser.add_argument('commit', nargs='?', default='HEAD')
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        required=False,
                        default=False,
                        help='force new download and compile')
    parser.add_argument('-ls',
                        '--list',
                        action='store_true',
                        required=False,
                        default=False,
                        help='list all available tests found')
    parser.add_argument(
        '-s',
        '--subset',
        type=str,
        default='',
        help='test filter expression: "defaults and not settings"')
    args = parser.parse_args()
    cd(this_repo_path)
    if args.list:
        pytest.main(shlex.split("--color=yes -v --tb=line --collect-only"))
    else:
        compile_default_projects(args)
        subsetTests = '' if not len(
            args.subset) else '-k "' + args.subset + '"'
        rmAllDiffFiles()  ## not actually needed...
        pytest.main(
            shlex.split("--color=yes --tb=line -v {subset}".format(
                subset=subsetTests)))
def test_screen_loading(ctx):
    for eachdir in [dirname_baseline, dirname_testline]: ## loop through each of baseline and testline and generate the files for later diffing
        cd(eachdir)
        runStr = brainTestStringWithSaving.format(
                 brainT="CGP",
                 initPop="'snapshot_organisms_0.csv'",
                 updates="1"
                 )
        runCmdAndSaveOutput(runStr, filename='screen-poploading') ## generate snapshot_organisms_0.csv
        cd('..') ## could also have done cd(this_repo_path)
    repoDiffForSimilarity('screen-poploading')
def test_reload_most_byid_error(ctx,numToLoad,mostCommand,dirToTest):
    errorMessage = buildMessageErrorExpectedWithArgs( dirToTest,mostCommand,numToLoad ) ## returns this fn name, the args, and that error was expected
    with pytest.raises(subprocess.CalledProcessError, message=errorMessage):
        cd(this_repo_path) ## reset after possible error
        cd(dirToTest)
        initPop = "{most} {amount} by ID from {{'snapshot_organisms_10.csv'}}".format(
                  most=mostCommand,
                  amount=str(numToLoad)
                  )
        runStr = brainTestString.format(
                 brainT='CGP',
                 initPop=initPop,
                 updates="1"
                 )
        runCmdAndSaveOutput(runStr,'tempfile') ## must 'Show' output for error sig to be inspected
Exemple #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('repo', type=str, nargs='?', default=None)
    parser.add_argument('basebranch', type=str, nargs='?', default=None)
    parser.add_argument('testbranch', type=str, nargs='?', default=None)
    parser.add_argument('makeCommand', type=str, nargs='?', default=None)
    parser.add_argument('exeName', type=str, nargs='?', default=None)
    parser.add_argument('-ls',
                        '--list',
                        action='store_true',
                        required=False,
                        default=False,
                        help='list all available tests found')
    parser.add_argument(
        '-s',
        '--subset',
        type=str,
        default='',
        help='test filter expression: "defaults and not settings"')
    args = parser.parse_args()
    noneTotal = 0
    if args.repo is None: noneTotal += 1
    if args.basebranch is None: noneTotal += 1
    if args.testbranch is None: noneTotal += 1
    if args.makeCommand is None: noneTotal += 1
    if args.exeName is None: noneTotal += 1
    if noneTotal > 0 and noneTotal < 5:
        print(
            "Error: [repo basebranch testbranch makeCommand exeName] is an optional 5-argument group"
        )
        parser.print_help(sys.stderr)
        exit(1)
    cd(this_repo_path)
    if args.list:
        #print("running pytest.main only performing test list")
        pytest.main(shlex.split("--color=yes -v --tb=line --collect-only"))
    else:
        print("running pytest.main")
        utils.helpers.exe_name = args.exeName
        utils.helpers.EXE = ".{}{}".format(utils.helpers.slash,
                                           utils.helpers.exe_name)
        compile_default_projects(args)
        subsetTests = '' if not len(
            args.subset) else '-k "' + args.subset + '"'
        pytest.main(
            shlex.split("--color=yes --tb=line -v {subset}".format(
                subset=subsetTests)))
Exemple #5
0
def ctx(
):  ## create a context for all the tests - you could potentially use this to pass an obj to all test fns
    if not ctx.ran:  ## prevents reinit before each and every test fn in this module
        ## generate cfg (have to 'cd' there, because mabe '-s' ignores 'GLOBAL-outputDirectory' setting)
        ## and run mabe with defaults
        dirs = [dirname_baseline, dirname_testline]
        for eachdir in dirs:  ## loop through each of baseline and testline and generate the files for later diffing
            cd(this_repo_path)
            cd(eachdir)
            runCmdAndSaveOutput("{exe} -s".format(exe=dotSlashMabe),
                                filename='screen-settings')
            runCmdAndSaveOutput("{exe} -h".format(exe=dotSlashMabe),
                                filename='screen-help')
            runCmdAndSaveOutput("{exe} -l".format(exe=dotSlashMabe),
                                filename='screen-poploader')
            runCmdAndSaveOutput("{exe} -v".format(exe=dotSlashMabe),
                                filename='screen-version')
            runCmdAndSaveOutput("{exe}".format(exe=dotSlashMabe),
                                filename='screen-simulation')
            cd('..')  ## could also have done cd(thisdotSlashMrepo_path)
        ## FYI, could have done it the following waydotSlashMif we were up one dir in mabe_testing
        #runCmdAndSaveOutput( "{exe} -p GLOBAL-outpudotSlashMDirectory {path}".format(exe=path_baseline_exe, path=dirname_baseline), filename=dirname_baseline+'screen-simulation' )
        ctx.ran = True

    yield None  ## could have actually passed a context object here to all the test fns
    ##
    ## teardown happens after the last test in the module finishes
    ##
    return
Exemple #6
0
def ctx(
):  ## create a context for all the tests - you could potentially use this to pass an obj to all test fns
    if not ctx.ran:  ## prevents reinit before each and every test fn in this module
        ## generate cfg (have to 'cd' there, because mabe '-s' ignores 'GLOBAL-outputDirectory' setting)
        ## and run mabe with defaults
        runStr = dotSlashMabe + " -p GLOBAL-randomSeed {seed} GLOBAL-updates 1 ARCHIVIST_LODWAP-terminateAfter 0"
        dirs = [dirname_baseline, dirname_testline]
        for eachdir in dirs:  ## loop through each of baseline and testline and generate the files for later diffing
            cd(this_repo_path)
            cd(eachdir)
            ## Create 2 files both with random seed
            runCmdAndSaveOutput(runStr.format(seed='-1'),
                                filename='screen-settings-randseed-random-A')
            runCmdAndSaveOutput(runStr.format(seed='-1'),
                                filename='screen-settings-randseed-random-B')
            ## Create 2 files both with identical seed
            runCmdAndSaveOutput(
                runStr.format(seed='101'),
                filename='screen-settings-randseed-nonrandom-A')
            runCmdAndSaveOutput(
                runStr.format(seed='101'),
                filename='screen-settings-randseed-nonrandom-B')
            cd('..')  ## could also have done cd(this_repo_path)
        ## FYI, could have done it the following way if we were up one dir in mabe_testing
        #runCmdAndSaveOutput( "{exe} -p GLOBAL-outputDirectory {path}".format(exe=path_baseline_exe, path=dirname_baseline), filename=dirname_baseline+'screen-simulation' )
        ctx.ran = True

    yield None  ## could have actually passed a context object here to all the test fns
    ##
    ## teardown happens after the last test in the module finishes
    ##
    return
def test_reload_brains(ctx, brainType):
    initPopLoading="greatest 1 by ID from {'snapshot_organisms_0.csv'}"
    for eachdir in [dirname_baseline, dirname_testline]: ## loop through each of baseline and testline and generate the files for later diffing
        cd(this_repo_path)
        cd(eachdir)
        runStr = brainTestStringWithSaving.format(
                 brainT=brainType,
                 initPop="default 1",
                 updates="1"
                 )
        runCmdAndHideOutput(runStr) ## generate snapshot_organisms_0.csv
        runStr = brainTestStringWithSaving.format(
                 brainT=brainType,
                 initPop=initPopLoading,
                 updates="1"
                 )
        runCmdAndHideOutput(runStr) ## normalize ID by running again
        for filetype in ['data','organisms']:
            copyfileAndPermissions('snapshot_'+filetype+'_0.csv', 'save1_'+filetype+'.csv') ## save first output
        runCmdAndHideOutput(runStr) ## generate snapshot_organisms_0.csv
        for filetype in ['data','organisms']:
            copyfileAndPermissions('snapshot_'+filetype+'_0.csv', 'save2_'+filetype+'.csv') ## save second output
        cd('..')
    diffForSimilarity(dirname_baseline+'save1_organisms.csv',
         dirname_baseline+'save2_organisms.csv',
         outfilename='diff-baseline-reloaded-{}-organisms'.format(brainType)
         )
    diffForSimilarity(dirname_testline+'save1_data.csv',
         dirname_testline+'save2_data.csv',
         outfilename='diff-testline-reloaded-{}-data'.format(brainType)
         )
Exemple #8
0
def compile_default_projects(args):
    VSprojsCreated = False
    if not os.path.isfile(path_baseline_exe) or args.force:
        print("clone new",
              args.branch,
              "at",
              args.commit,
              "as baseline",
              flush=True)
        shutil.rmtree(dirname_baseline, ignore_errors=True)
        repo = git.Repo.clone_from("https://github.com/hintzelab/mabe",
                                   dirname_baseline,
                                   branch=args.branch)
        revision = repo.create_head('revision', args.commit)
        repo.heads.revision.checkout()
        cd(dirname_baseline)
        print("building baseline", flush=True)
        rmfile(
            "buildOptions.txt")  ## remove buildOptions so we can regenerate it
        writeDefaultBuildOptions()
        callMBuildToInitBuildOptions()
        checkForCompilerAndCompileOrMakeProjs()
        cd("..")
    if not os.path.isfile(os.path.join('..', mabe)):
        cd("..")
        print("building testline", flush=True)
        rmfile(
            "buildOptions.txt")  ## remove buildOptions so we can regenerate it
        writeDefaultBuildOptions()
        callMBuildToInitBuildOptions()
        checkForCompilerAndCompileOrMakeProjs()
        cd(this_repo_path)
    os.makedirs(dirname_testline, exist_ok=True)
    if (not os.path.isfile(path_baseline_exe)) or (not os.path.isfile(
            os.path.join('..', mabe))):
        print(useVSMessage)
        sys.exit()
    else:
        copyfileAndPermissions(os.path.join('..', mabe), path_testline_exe)
def test_reload_most_byid_noerror(ctx,numToLoad,mostCommand):
    outputFilename = 'screen-reload-{most}-byid-{num}'.format(
                      most=mostCommand, num=str(numToLoad)
                      )
    for eachdir in [dirname_baseline, dirname_testline]: ## loop through each of baseline and testline and generate the files for later diffing
        cd(this_repo_path) ## ensures clean state
        cd(eachdir)
        initPop = "{most} {amount} by ID from {{'snapshot_organisms_10.csv'}}".format(
                  most=mostCommand,
                  amount=str(numToLoad)
                  )
        runStr = brainTestString.format(
                 brainT='CGP',
                 initPop=initPop,
                 updates="1"
                 )
        runCmdAndSaveOutput(runStr, filename=outputFilename) ## normalize ID
        cd('..')
    repoDiffForSimilarity(outputFilename)
def ctx(): ## create a context for all the tests - you could potentially use this to pass an obj to all test fns
    if not ctx.ran: ## prevents reinit before each and every test fn in this module
        ## generate cfg (have to 'cd' there, because mabe '-s' ignores 'GLOBAL-outputDirectory' setting)
        ## and run mabe with defaults
        dirs = [dirname_baseline, dirname_testline]
        for eachdir in dirs: ## loop through each of baseline and testline and generate the files for later diffing
            cd(this_repo_path)
            cd(eachdir)
            runCmdAndSaveOutput( "{exe} -l".format(exe=dotSlashMabe), filename='screen-plf' )
            runCmdAndHideOutput( brainTestStringWithSaving.format( brainT='CGP', initPop='default 100', updates='10' ) ) ## generate large snapshot_organisms_10.csv
            runCmdAndHideOutput( brainTestStringWithSaving.format( brainT='CGP', initPop='default 1', updates='1' ) ) ## generate small snapshot_organisms_0.csv
            cd('..') ## could also have done cd(this_repo_path)
        ctx.ran = True

    yield None ## could have actually passed a context object here to all the test fns
    ##
    ## teardown happens after the last test in the module finishes
    ##
    return
Exemple #11
0
def ctx(
):  ## create a context for all the tests - you could potentially use this to pass an obj to all test fns
    if not ctx.ran:
        ## generate cfg (have to 'cd' there, because mabe '-s' ignores 'GLOBAL-outputDirectory' setting)
        ## and run mabe with defaults
        dirs = [dirname_baseline, dirname_testline]
        for eachdir in dirs:  ## loop through each of baseline and testline and generate the files for later diffing
            cd(this_repo_path)
            cd(eachdir)
            runStr = dotSlashMabe + " -s"
            runCmdAndSaveOutput(
                runStr, filename='screen-settings')  ## save settings to file
            for eachfile in [
                    "settings.cfg", "settings_organism.cfg",
                    "settings_world.cfg"
            ]:  ## make a backup of the settings files
                copyfileAndPermissions(eachfile, eachfile + ".bak")
            runStr = dotSlashMabe + " -f settings*.cfg -s"
            runCmdAndSaveOutput(runStr, filename='screen-settings-reload'
                                )  ## load and save settings to file
            for eachfile in [
                    "settings.cfg", "settings_organism.cfg",
                    "settings_world.cfg"
            ]:  ## make a backup of the settings files
                copyfileAndPermissions(eachfile, eachfile + ".bak")
            ##
            ## MORE GENERATION OF FILES OR BEHAVIOR HERE
            ##
            cd('..')  ## could also have done cd(this_repo_path)
        ## FYI, could have done it the following way if we were up one dir in mabe_testing
        #runCmdAndSaveOutput( "{exe} -p GLOBAL-outputDirectory {path}".format(exe=path_baseline_exe, path=dirname_baseline), filename=dirname_baseline+'screen-simulation' )
        ctx.ran = True

    yield None  ## could have actually passed a context object here to all the test fns
    ##
    ## teardown happens after the last test in the module finishes
    ##
    return
Exemple #12
0
def compile_default_projects(args):
    for eachRepo, eachBranch in zip([dirname_baseline, dirname_testline],
                                    [args.basebranch, args.testbranch]):
        branch, commit = get_branch_and_commit(eachBranch)
        print("{}: cloning repo '{}' and switching to {}:{}".format(
            eachRepo, args.repo, branch, commit))
        if is_repo_at_commit(
                eachRepo, branch, commit
        ) == False:  ## check if baseline repo is already set up, if not then make it
            enableWriteFlagForGitRepoFiles(eachRepo)
            shutil.rmtree(eachRepo, ignore_errors=True)
            repo = None  ## initialize repo var based on local or remote invocation
            if is_local_repo(args.repo):
                oldrepo = git.Repo(args.repo)
                repo = oldrepo.clone(os.path.abspath(eachRepo), branch=branch)
            else:
                repo = git.Repo.clone_from(args.repo, eachRepo, branch=branch)
            repo.heads[0].set_commit(commit)
            repo.heads[0].checkout(force=True)
        cd(eachRepo)
        print("building {}".format(eachRepo), flush=True)
        call_build(args.makeCommand)
        cd("..")
    cd(this_repo_path)