Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Fix tests on main #301

Merged
merged 7 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

DO_REVIEW = True

units = mephisto_data_browser.get_units_for_task_name("objects-interaction-task-pilot-5")
units = mephisto_data_browser.get_units_for_task_name(
"objects-interaction-task-pilot-5"
)

print(f"prev len: {len(units)}")
print(Counter([u.get_status() for u in units]))
units = [u for u in units if u.get_status() == "completed"]
print(f"len: {len(units)}")
print(f"len: {len(units)}")
4 changes: 2 additions & 2 deletions deploy/web/server/tests/test_tornado_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
URL = f"http://localhost:{PORT}"


class TestFlags:
class MockFlags:
def __init__(self, hostname, port):
self.hostname = hostname
self.port = port
Expand All @@ -79,7 +79,7 @@ def setUp(self):
# Need to fix this somehow...
self.db_path = os.path.join(self.data_dir, "test_server.db")
self.db = LIGHTDatabase(self.db_path)
self.FLAGS = TestFlags("localhost", PORT)
self.FLAGS = MockFlags("localhost", PORT)
self.client = httpclient.AsyncHTTPClient()
super().setUp()

Expand Down
2 changes: 1 addition & 1 deletion light/world/souls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Current flags:
- [**`OnEventSoul`**](https://github.com/facebookresearch/LIGHT/tree/main/light/world/souls/on_event_soul.py): Extended `ModelSoul` class that is able to handle some basic scripted heuristic events as well as the more general `on_event` types that can be linked to a `GraphNode`.
- [**`PlayerSoul`**](https://github.com/facebookresearch/LIGHT/tree/main/light/world/souls/player_soul.py): Simple `Soul` class that allows for a human player to take control of the `GraphAgent`. Requires use of a `PlayerProvider` containing the abstractions for sending observations and receiving actions.
- [**`RepeatSoul`**](https://github.com/facebookresearch/LIGHT/tree/main/light/world/souls/repeat_soul.py): Bare-bones `Soul` class for use in demonstrations. Simply speaks back the observations it sees with a `SayEvent`.
- [**`TestSoul`**](https://github.com/facebookresearch/LIGHT/tree/main/light/world/souls/test_soul.py): Core soul for being able to run tests on the LIGHT `World` classes. Has a directly accessible `observations` field and a `do_act` function allowing scripted execution of actions.
- [**`MockSoul`**](https://github.com/facebookresearch/LIGHT/tree/main/light/world/souls/mock_soul.py): Core soul for being able to run tests on the LIGHT `World` classes. Has a directly accessible `observations` field and a `do_act` function allowing scripted execution of actions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
from light.graph.events.base import GraphEvent


class TestSoul(Soul):
class MockSoul(Soul):
"""
A Soul for use in testing
"""

def __init__(self, target_node: "GraphAgent", world: "World"):
"""
TestSouls are created for test cases to take actions
MockSouls are created for test cases to take actions
and report observations
"""
super().__init__(target_node, world)
Expand All @@ -34,13 +34,13 @@ def do_act(self, event):

async def observe_event(self, event: "GraphEvent"):
"""
TestSouls do very little beyond saying what they observed, and smiling
MockSouls do very little beyond saying what they observed, and smiling
for good measure.
"""
self.observations.append(event)

def reap(self):
"""
TestSouls don't have any extra resources, and thus don't need to clean up.
MockSouls don't have any extra resources, and thus don't need to clean up.
"""
super().reap()
30 changes: 15 additions & 15 deletions light/world/souls/tests/test_souls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from light.graph.structured_graph import OOGraph
from light.world.world import World
from light.graph.events.graph_events import EmoteEvent, SayEvent
from light.world.souls.test_soul import TestSoul
from light.world.souls.mock_soul import MockSoul
from light.world.souls.repeat_soul import RepeatSoul


Expand All @@ -26,7 +26,7 @@ def wrapper(*args, **kwargs):
return wrapper


class TestSouls(unittest.TestCase):
class MockSouls(unittest.TestCase):
"""Unit tests for simple souls"""

def test_init_soul(self):
Expand All @@ -37,16 +37,16 @@ def test_init_soul(self):
agent_node.force_move_to(room_node)
test_world = World({}, None, True)
test_world.oo_graph = test_graph
test_soul = TestSoul(agent_node, test_world)
self.assertEqual(agent_node, test_soul.target_node)
self.assertEqual(test_world, test_soul.world)
mock_soul = MockSoul(agent_node, test_world)
self.assertEqual(agent_node, mock_soul.target_node)
self.assertEqual(test_world, mock_soul.world)

test_event = EmoteEvent.construct_from_args(
agent_node, targets=[], text="smile"
)
test_soul.do_act(test_event)
mock_soul.do_act(test_event)

test_soul.reap()
mock_soul.reap()

@async_test
async def test_message_sending(self):
Expand All @@ -65,7 +65,7 @@ async def test_message_sending(self):
test_world.oo_graph = test_graph

purgatory = test_world.purgatory
purgatory.register_filler_soul_provider("test", TestSoul, lambda: [])
purgatory.register_filler_soul_provider("test", MockSoul, lambda: [])
purgatory.register_filler_soul_provider("repeat", RepeatSoul, lambda: [])

purgatory.fill_soul(test_node, "test")
Expand All @@ -74,23 +74,23 @@ async def test_message_sending(self):
purgatory.fill_soul(repeat_node, "repeat")
self.assertIn(repeat_node.node_id, purgatory.node_id_to_soul)

test_soul: "TestSoul" = purgatory.node_id_to_soul[test_node.node_id]
mock_soul: "MockSoul" = purgatory.node_id_to_soul[test_node.node_id]
repeat_soul = purgatory.node_id_to_soul[repeat_node.node_id]

# Make the test soul act, and observe what follows
test_event = EmoteEvent.construct_from_args(test_node, targets=[], text="smile")
test_soul.do_act(test_event)
mock_soul.do_act(test_event)

observations = test_soul.observations
observations = mock_soul.observations
start_time = time.time()
OBSERVATION_WAIT_TIMEOUT = 3.3
while len(observations) < 3:
self.assertTrue(
time.time() - start_time < OBSERVATION_WAIT_TIMEOUT,
f"Exceeded expected duration {OBSERVATION_WAIT_TIMEOUT} waiting "
f"for parrot events, found {test_soul.observations}",
f"for parrot events, found {mock_soul.observations}",
)
observations = test_soul.observations
observations = mock_soul.observations
await asyncio.sleep(0.01)

# Observations should be the self smile event, then the repeat agent's say and smile
Expand All @@ -114,11 +114,11 @@ async def test_message_sending(self):
self.assertEqual(other_emote_observe.actor, repeat_node)
self.assertEqual(other_emote_observe.text_content, "smile")

observations = test_soul.observations
observations = mock_soul.observations
# Extra observation may have slipped in?
self.assertEqual(len(observations), 3, "Unexpected amount of observations")
self.assertEqual(
len(test_soul._observe_futures), 0, "All obs threads should have deleted"
len(mock_soul._observe_futures), 0, "All obs threads should have deleted"
)


Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ yappi>=1.2.5
torch>=1.5.0
tornado>=6.0.4
pandas>=1.0.3
parlai>=0.1.20200716
parlai>=1.6.0
psycopg2-binary>=2.8.5
pytest>=6.0.0
pytest>=5.0.0
pyzmq>=19.0.1
tqdm>=4.48.0
hydra-core>=1.0.0
Expand Down