mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-02 14:45:17 +02:00
add residue code
This commit is contained in:
parent
1e3ed29c34
commit
99da01fecd
7 changed files with 64 additions and 3 deletions
3
tests/metagpt/environment/api/__init__.py
Normal file
3
tests/metagpt/environment/api/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc :
|
||||
3
tests/metagpt/environment/gym_env/__init__.py
Normal file
3
tests/metagpt/environment/gym_env/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc :
|
||||
3
tests/metagpt/environment/software_env/__init__.py
Normal file
3
tests/metagpt/environment/software_env/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc :
|
||||
37
tests/metagpt/environment/test_base_env.py
Normal file
37
tests/metagpt/environment/test_base_env.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : the unittest of ExtEnv&Env
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.environment.base_env import Env, mark_as_writeable, mark_as_readable
|
||||
from metagpt.environment.api.env_api import EnvAPIAbstract
|
||||
|
||||
|
||||
class ForTestEnv(Env):
|
||||
value: int = 0
|
||||
|
||||
@mark_as_readable
|
||||
def read_api_no_parms(self):
|
||||
return self.value
|
||||
|
||||
@mark_as_readable
|
||||
def read_api(self, a: int, b: int):
|
||||
return a + b
|
||||
|
||||
@mark_as_writeable
|
||||
def write_api(self, a: int, b: int):
|
||||
self.value = a + b
|
||||
|
||||
|
||||
def test_ext_env():
|
||||
env = ForTestEnv()
|
||||
assert len(env.read_api_registry) == 2
|
||||
assert len(env.write_api_registry) == 1
|
||||
|
||||
assert env.step(EnvAPIAbstract(api_name="write_api", kwargs={"a": 5, "b": 10})) == 15
|
||||
with pytest.raises(ValueError):
|
||||
env.observe("not_exist_api")
|
||||
|
||||
assert env.observe("read_api_no_parms") == 15
|
||||
assert env.observe(EnvAPIAbstract(api_name="read_api", kwargs={"a": 5, "b": 5})) == 10
|
||||
3
tests/metagpt/environment/werewolf_env/__init__.py
Normal file
3
tests/metagpt/environment/werewolf_env/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc :
|
||||
Loading…
Add table
Add a link
Reference in a new issue