From d6c7b33a5510d16c460b67692ddcecab19d899b9 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Sun, 20 Oct 2024 21:14:20 +0300 Subject: [PATCH 1/2] test for starting a mission in a flat world --- tests/vereya/test_flat_world.py | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/vereya/test_flat_world.py diff --git a/tests/vereya/test_flat_world.py b/tests/vereya/test_flat_world.py new file mode 100644 index 0000000..8068662 --- /dev/null +++ b/tests/vereya/test_flat_world.py @@ -0,0 +1,76 @@ +import unittest +import logging +from tagilmo import VereyaPython +import json +import time +import tagilmo.utils.mission_builder as mb +from tagilmo.utils.vereya_wrapper import MCConnector, RobustObserver +from base_test import BaseTest + + +def init_mission(mc, start_x=None, start_z=None): + want_depth = False + + video_producer = mb.VideoProducer(width=320 * 4, + height=240 * 4, want_depth=want_depth) + + obs = mb.Observations() + + agent_handlers = mb.AgentHandlers(observations=obs, + video_producer=video_producer) + + print('starting at ({0}, {1})'.format(start_x, start_z)) + + #miss = mb.MissionXML(namespace="ProjectMalmo.microsoft.com", + miss = mb.MissionXML( + agentSections=[mb.AgentSection(name='Cristina', + agenthandlers=agent_handlers, + # depth + agentstart=mb.AgentStart([start_x, -60.0, start_z, 1]))]) + world = mb.flatworld("", + seed='5', + forceReset="false") + miss.setWorld(world) + miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager" + # uncomment to disable passage of time: + miss.serverSection.initial_conditions.time_pass = 'false' + miss.serverSection.initial_conditions.time_start = "1000" + + if mc is None: + mc = MCConnector(miss) + obs = RobustObserver(mc) + else: + mc.setMissionXML(miss) + return mc, obs + + +class TestFlat(BaseTest): + mc = None + + @classmethod + def setUpClass(cls, *args, **kwargs): + start = (-108.0, -187.0) + mc, obs = init_mission(None, start_x=start[0], start_z=start[1]) + cls.mc = mc + assert mc.safeStart() + time.sleep(3) + + @classmethod + def tearDownClass(cls, *args, **kwargs): + cls.mc.stop() + + def setUp(self): + super().setUp() + self.mc.sendCommand("chat /clear") + time.sleep(3) + + def test_flat_world(self): + self.assertTrue(self.mc.is_mission_running()) + + +def main(): + VereyaPython.setupLogger() + unittest.main() + +if __name__ == '__main__': + main() From 7224e9322df85b834f1fafc9b165d3f3117b0b35 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Sun, 20 Oct 2024 21:14:38 +0300 Subject: [PATCH 2/2] added flat world test in test_files --- tests/vereya/run_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/vereya/run_tests.py b/tests/vereya/run_tests.py index db97666..174a119 100644 --- a/tests/vereya/run_tests.py +++ b/tests/vereya/run_tests.py @@ -29,7 +29,7 @@ def main(): test_files = ['test_motion_vereya', 'test_craft', 'test_inventory', 'test_quit', 'test_observation', 'test_placement', 'test_image', - 'test_consistency', 'test_motion_mob', 'test_mob', 'test_agent'] + 'test_consistency', 'test_motion_mob', 'test_mob', 'test_agent', 'test_flat_world'] res = run_tests(test_files) if not res.wasSuccessful(): sys.exit(1)