예제 #1
0
    def runtest(self):
        """Run an AnyScript test item."""
        tmpdir = self.config._tmpdirhandler.mktemp(self.name)
        if self.compare_filename:
            os.makedirs(os.path.dirname(self.compare_filename))
        with change_dir(tmpdir.strpath):
            app = AnyPyProcess(**self.apt_opts)
            result = app.start_macro(self.macro)[0]
            self.app = app
        # Ignore error due to missing Main.RunTest
        if 'ERROR' in result:
            for i, err in enumerate(result['ERROR']):
                runtest_errros = (
                    'Error : Main.RunTest : Unresolved object',
                    'Main.RunTest : Select Operation is not expected')
                if any(s in err for s in runtest_errros):
                    del result['ERROR'][i]
                    break
        # Check that the expected errors are present
        if self.expect_errors:
            error_list = result.get('ERROR', [])
            for xerr in self.expect_errors:
                xerr_found = False
                for i, error in enumerate(error_list):
                    if xerr in error:
                        xerr_found = True
                        del error_list[i]
                if not xerr_found:
                    self.errors.append('TEST ERROR: Expected error not '
                                       'found: "{}"'.format(xerr))
        # Add remaining errors to item's error list
        if 'ERROR' in result and len(result['ERROR']) > 0:
            self.errors.extend(result['ERROR'])
        # Add info to the hdf5 file if compare output was set
        if self.compare_filename is not None:
            import h5py
            f = h5py.File(self.compare_filename, 'a')
            f.attrs['anytest_processtime'] = result['task_processtime']
            f.attrs['anytest_macro'] = '\n'.join(result['task_macro'][:-1])
            f.attrs['anytest_ammr_version'] = pytest.anytest.ammr_version
            f.attrs['anytest_ams_version'] = pytest.anytest.ams_version
            f.close()
            basedir = os.path.dirname(self.compare_filename)
            macrofile = write_macro_file(basedir, self.compare_study,
                                         self.macro[:-1])
            with open(os.path.join(basedir, self.compare_study + '.bat'),
                      'w') as f:
                anybodygui = re.sub(r"(?i)anybodycon\.exe", r"anybody\.exe",
                                    self.anybodycon_path)
                f.write('"{}" -m "{}"'.format(anybodygui, macrofile))

        if len(self.errors) > 0:
            if self.config.getoption("--create-macros"):
                macro_name = write_macro_file(self.fspath.dirname, self.name,
                                              self.macro)
                self.macro_file = macro_name
            raise AnyException(self)
        return
예제 #2
0
def test_hdf5save(tmpdir, default_macro):
    setup_simple_model( tmpdir )
    tmpdir.chdir()
    app = AnyPyProcess(keep_logfiles=True)
    app.start_macro(default_macro)
    
    app.save_to_hdf5('test.hdf5', 'LungeTLEM1')        
        
    assert(os.path.exists('test.hdf5'))
예제 #3
0
def run_model(saddle_height, saddle_pos, silent=False):
    """Run the AnyBody model and return the metabolism results"""
    macro = [
        Load("BikeModel2D.main.any"),
        SetValue("Main.BikeParameters.SaddleHeight", saddle_height),
        SetValue("Main.BikeParameters.SaddlePos", saddle_pos),
        OperationRun("Main.Study.InverseDynamics"),
        Dump("Main.Study.Output.Pmet_total"),
        Dump("Main.Study.Output.Abscissa.t"),
    ]
    app = AnyPyProcess(silent=silent)
    results = app.start_macro(macro)
    return results[0]
예제 #4
0
    def run(self):
        if not self.macrolist:
            print(
                "No operation for AnyBody was selected -> will terminate now")
            return False

        # print('Starting Anybody with the operations: {}'.format(self.operations))
        print('Starting Anybody with the macros:\n{}'.format(
            AnyMacro(self.macrolist)))
        print('Executing "{}" in "{}"'.format(self.any_path, self.any_model))

        # save current working directory and change to Anybody project folder
        cwd = os.getcwd()
        os.chdir(self.any_path)
        app = AnyPyProcess()

        self.output = app.start_macro(macrolist=self.macrolist,
                                      logfile=AnyPy.LOG_FILE)

        # change back to original folder
        os.chdir(cwd)
        return True
예제 #5
0
              'operation Main.ArmModelStudy.InverseDynamics',
              'run',
              'classoperation Main.ArmModelStudy.Output.MaxMuscleActivity "Dump"',
              'classoperation Main.ArmModel.GlobalRef.t "Dump"'
              ]]*5
    return macro


def test_hdf5save(tmpdir, default_macro):
    setup_simple_model( tmpdir )
    tmpdir.chdir()
    app = AnyPyProcess(keep_logfiles=True)
    app.start_macro(default_macro)
    
    app.save_to_hdf5('test.hdf5', 'LungeTLEM1')        
        
    assert(os.path.exists('test.hdf5'))
    
    
    
if __name__ == '__main__':
    macro = [['load "Demo.Arm2D.any"',
              'operation Main.ArmModelStudy.InverseDynamics',
              'run',
              'classoperation Main.ArmModelStudy.Output.MaxMuscleActivity "Dump"',
              'classoperation Main.ArmModel.GlobalRef.t "Dump"'
              ]]*5
    app = AnyPyProcess(keep_logfiles=True)
    app.start_macro(macro)
    
    app.save_to_hdf5('test2.hdf5', 'Lunge11dec')
예제 #6
0
from anypytools import AnyPyProcess
from anypytools.macro_commands import Load, OperationRun

app = AnyPyProcess(num_processes=3)

macro = [Load("main.any"), OperationRun("Main.Study.InverseDynamics")]

app.start_macro(macro, search_subdirs="model[1-9].*main.any")
예제 #7
0
    def runtest(self):
        """Run an AnyScript test item."""

        tmpdir = Path(
            TempdirFactory(TempPathFactory.from_config(self.config)).mktemp(
                self.name))

        with change_dir(tmpdir):
            self.app = AnyPyProcess(**self.app_opts)
            result = self.app.start_macro(self.macro)[0]

        # Ignore error due to missing Main.RunTest
        if "ERROR" in result:
            runtest_missing = any("Error : Main.RunTest :" in err
                                  for err in result["ERROR"])
            if runtest_missing:
                runtest_errros = (
                    "Error : Main.RunTest : Unresolved",
                    "Main.RunTest : Select Operation",
                    "Error : run : command unexpected while",
                )
                result["ERROR"][:] = [
                    err for err in result["ERROR"]
                    if not any(s in err for s in runtest_errros)
                ]
        # Check that the expected errors are present
        error_list = result.get("ERROR", [])
        if self.expect_errors:
            for xerr in self.expect_errors:
                xerr_found = False
                for error in error_list[:]:
                    if xerr in error:
                        xerr_found = True
                        error_list.remove(error)
                if not xerr_found:
                    self.errors.append("TEST ERROR: Expected error not "
                                       'found: "{}"'.format(xerr))

        # Add remaining errors to item's error list
        if error_list:
            self.errors.extend(error_list)

        # Add info to the hdf5 file if compare output was set
        if self.hdf5_outputs:
            base = Path(self.config.getoption("--anytest-output"))
            subfolder = Path(self.config.getoption("--anytest-name"))
            target = base / subfolder / self.name
            self.save_output_files(tmpdir, target, result, self.hdf5_outputs)

        if self.errors and self.config.getoption("--create-macros"):
            logfile = result["task_logfile"]
            shutil.copyfile(logfile, self.fspath / (self.name + ".txt"))
            shutil.copyfile(logfile.with_suffix(".anymcr"),
                            self.fspath / (self.name + ".anymcr"))
            macro_name = _write_macro_file(self.fspath.dirname, self.name,
                                           self.macro)

        shutil.rmtree(tmpdir, ignore_errors=True)

        if len(self.errors) > 0:
            raise AnyException(self)

        return