コード例 #1
0
ファイル: test_runner.py プロジェクト: Xyzic/yggdrasil
def test_import_as_function_C():
    r"""Test import_as_function for C."""
    contents = r"""models:
      - name: c_modelA
        language: c
        args: ./src/model_function_modelA.c
        function: model_function
        inputs: inputA
        outputs: outputA"""
    yamlfile = os.path.join(os.path.dirname(ex_yamls['model_function']['c']),
                            'test_import.yml')
    assert (not os.path.isfile(yamlfile))
    with open(yamlfile, 'w') as fd:
        fd.write(contents)
    try:
        fmodel = import_as_function(yamlfile)
        input_args = {}
        for x in fmodel.arguments:
            input_args[x] = b'hello'
        result = fmodel(**input_args)
        for x in fmodel.returns:
            assert (x in result)
        fmodel.stop()
        fmodel.stop()
    finally:
        os.remove(yamlfile)
コード例 #2
0
ファイル: test_runner.py プロジェクト: Xyzic/yggdrasil
def test_import_as_function():
    r"""Test import_as_function."""
    yamlfile = ex_yamls['fakeplant']['python']
    fmodel = import_as_function(yamlfile)
    input_args = {}
    for x in fmodel.arguments:
        input_args[x] = 1.0
    result = fmodel(**input_args)
    for x in fmodel.returns:
        assert (x in result)
    fmodel.stop()
    fmodel.stop()
コード例 #3
0
def test_import_as_function_server():
    r"""Test import_as_function w/ server function."""
    yamlfile = None
    for x in ex_yamls['rpc_lesson3']['python']:
        if 'server' in x:
            yamlfile = x
            break
    assert(yamlfile)
    fmodel = import_as_function(yamlfile)
    input_args = {}
    for x in fmodel.arguments:
        input_args[x] = 'hello'
    fmodel.model_info()
    result = fmodel(**input_args)
    for x in fmodel.returns:
        assert(x in result)
    result = fmodel(*list(input_args.values()))
    for x in fmodel.returns:
        assert(x in result)
    fmodel.stop()
    fmodel.stop()
コード例 #4
0
 def test_calling_service_as_function(self, running_service):
     r"""Test calling an integrations as a service in an integration."""
     # if running_service.commtype != None:
     #     pytest.skip("redundent test")
     cli = running_service
     name = 'test'
     test_yml = ex_yamls['fakeplant']['python']
     try:
         cli.registry.add(name, test_yml)
         fmodel = import_as_function(name, cli.address)
         input_args = {}
         for x in fmodel.arguments:
             input_args[x] = 1.0
         fmodel.model_info()
         result = fmodel(**input_args)
         for x in fmodel.returns:
             assert (x in result)
         result = fmodel(*list(input_args.values()))
         for x in fmodel.returns:
             assert (x in result)
         fmodel.stop()
         fmodel.stop()
     finally:
         cli.registry.remove(name)