From 85e684747b75167054392e97cca351459e2ecf72 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Mon, 4 Nov 2024 18:55:46 +0300 Subject: [PATCH 1/5] added drawing_decorator as option --- tests/vereya/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/vereya/common.py b/tests/vereya/common.py index 32b4bfb..36bcb39 100644 --- a/tests/vereya/common.py +++ b/tests/vereya/common.py @@ -9,7 +9,7 @@ from tagilmo.utils.vereya_wrapper import MCConnector, RobustObserver from base_test import BaseTest -def init_mission(mc, start_x, start_z, seed, forceReset="false", forceReuse="false", start_y=78, worldType = "default"): +def init_mission(mc, start_x, start_z, seed, forceReset="false", forceReuse="false", start_y=78, worldType = "default", drawing_decorator = None): want_depth = False video_producer = mb.VideoProducer(width=320 * 4, height=240 * 4, want_depth=want_depth) @@ -27,7 +27,8 @@ def init_mission(mc, start_x, start_z, seed, forceReset="false", forceReuse="fal agentSections=[mb.AgentSection(name='Cristina', agenthandlers=agent_handlers, # depth - agentstart=mb.AgentStart([start_x, start_y, start_z, 1]))]) + agentstart=mb.AgentStart([start_x, start_y, start_z, 1]))], + serverSection=mb.ServerSection(handlers=mb.ServerHandlers(drawing_decorator))) flat_json = {"biome":"minecraft:plains", "layers":[{"block":"minecraft:diamond_block","height":1}], "structures":{"structures": {"village":{}}}} From c8891eec545b8d402fe2c9de8cc8661e68be8d57 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Mon, 4 Nov 2024 22:05:16 +0300 Subject: [PATCH 2/5] specified arg for ServerHandlers constructor --- tests/vereya/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/vereya/common.py b/tests/vereya/common.py index 36bcb39..c538927 100644 --- a/tests/vereya/common.py +++ b/tests/vereya/common.py @@ -28,7 +28,7 @@ def init_mission(mc, start_x, start_z, seed, forceReset="false", forceReuse="fal agenthandlers=agent_handlers, # depth agentstart=mb.AgentStart([start_x, start_y, start_z, 1]))], - serverSection=mb.ServerSection(handlers=mb.ServerHandlers(drawing_decorator))) + serverSection=mb.ServerSection(handlers=mb.ServerHandlers(drawingdecorator=drawing_decorator))) flat_json = {"biome":"minecraft:plains", "layers":[{"block":"minecraft:diamond_block","height":1}], "structures":{"structures": {"village":{}}}} From f5fe255f8a772192731a0d957f15265470c7ee49 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Mon, 4 Nov 2024 22:10:50 +0300 Subject: [PATCH 3/5] added tests for block, cuboid and line --- tests/vereya/test_draw.py | 103 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/vereya/test_draw.py diff --git a/tests/vereya/test_draw.py b/tests/vereya/test_draw.py new file mode 100644 index 0000000..4702eb7 --- /dev/null +++ b/tests/vereya/test_draw.py @@ -0,0 +1,103 @@ +import unittest +import logging +import json +import time +from tagilmo import VereyaPython +import tagilmo.utils.mission_builder as mb +from tagilmo.utils.vereya_wrapper import MCConnector, RobustObserver +from base_test import BaseTest +from common import count_items, init_mission + +def test_basic_motion(): + pass + +class TestCraft(BaseTest): + mc = None + + @classmethod + def setUpClass(cls, *args, **kwargs): + start = (0, 0) + cls.block = mb.DrawBlock((start[0] + 2), -60, start[1] + 2, "cobblestone") + cls.cuboid = mb.DrawCuboid(start[0]-2, -61, start[1]-1, start[0]-2, -58, start[1]-2, "diamond_block") + cls.line = mb.DrawLine(start[0] - 2, -62, start[1]-2, start[1] + 2, -62, start[1]+ 2, "redstone_block") + draw = mb.DrawingDecorator([cls.cuboid, cls.line, cls.block,]) + mc, obs = init_mission(None, start_x=start[0], start_z=start[1], seed='4', forceReset="true", start_y=-60, worldType="flat", drawing_decorator=draw) + cls.mc = mc + cls.obs = obs + assert mc.safeStart() + time.sleep(4) + + @classmethod + def tearDownClass(cls, *args, **kwargs): + cls.mc.stop() + + def setUp(self): + super().setUp() + self.mc.sendCommand("chat /clear") + time.sleep(4) + + def test_draw_block(self): + mc = self.mc + print('send ochat') + grid = mc.getGridBox() + grid_size = [grid[k][1] - grid[k][0] + 1 for k in range(3)] + blocks = mc.getNearGrid() + coords = mc.getAgentPos() + lowest_point = [coords[k] + grid[k][0] for k in range(3)] + block = self.block + idx = int(block.x - lowest_point[0] + (block.z - lowest_point[2]) * grid_size[0] + (block.y - lowest_point[1]) * grid_size[0] * grid_size[2]) + real_block_type = blocks[idx] + self.assertEqual(block.blockType, real_block_type) + time.sleep(1) + + def test_draw_cuboid(self): + mc = self.mc + print('send ochat') + grid = mc.getGridBox() + grid_size = [grid[k][1] - grid[k][0] + 1 for k in range(3)] + blocks = mc.getNearGrid() + coords = mc.getAgentPos() + lowest_point = [coords[k] + grid[k][0] for k in range(3)] + cuboid = self.cuboid + real_blocks = [] + x1, y1, z1 = cuboid.x1, cuboid.y1, cuboid.z1 + for y_ in range(cuboid.y2 - cuboid.y1 + 1): + for z_ in range(cuboid.z2 - cuboid.z1 + 1): + for x_ in range(cuboid.x2 - cuboid.x1 + 1): + idx = int(x1 + x_ - lowest_point[0] + (z1 + z_ - lowest_point[2]) * grid_size[0] + (y1 + y_ - lowest_point[1]) * grid_size[0] * grid_size[2]) + real_blocks.append(blocks[idx]) + needed_blocks = [cuboid.blockType] * (cuboid.x2 - cuboid.x1 + 1) * (cuboid.y2 - cuboid.y1 + 1) * (cuboid.z2 - cuboid.z1 + 1) + self.assertEqual(needed_blocks, real_blocks) + time.sleep(1) + + def test_draw_line(self): + mc = self.mc + print('send ochat') + grid = mc.getGridBox() + grid_size = [grid[k][1] - grid[k][0] + 1 for k in range(3)] + blocks = mc.getNearGrid() + coords = mc.getAgentPos() + lowest_point = [coords[k] + grid[k][0] for k in range(3)] + line = self.line + x1, y1, z1 = line.x1, line.y1, line.z1 + x2, y2, z2 = line.x2, line.y2, line.z2 + dx, dy, dz = x2 - x1, y2 - y1, z2 - z1 + steps = max(abs(dx), abs(dy), abs(dz)) + x_inc, y_inc, z_inc = dx / steps, dy / steps, dz / steps + real_blocks = [] + x_, y_, z_ = 0, 0, 0 + for i in range(steps + 1): + x_, y_, z_ = int(i * x_inc), int(i * y_inc), int(i * z_inc) + idx = int(x1 + x_ - lowest_point[0] + (z1 + z_ - lowest_point[2]) * grid_size[0] + (y1 + y_ - lowest_point[1]) * grid_size[0] * grid_size[2]) + real_blocks.append(blocks[idx]) + needed_blocks = [line.blockType] * (steps + 1) + self.assertEqual(needed_blocks, real_blocks) + time.sleep(1) + +def main(): + VereyaPython.setupLogger() + unittest.main() + + +if __name__ == '__main__': + main() From 4d3c8ed735c2283383fe89412eb76e150cd0e2a1 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Mon, 4 Nov 2024 22:34:57 +0300 Subject: [PATCH 4/5] added test for item --- tests/vereya/test_draw.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/vereya/test_draw.py b/tests/vereya/test_draw.py index 4702eb7..bf9aa9e 100644 --- a/tests/vereya/test_draw.py +++ b/tests/vereya/test_draw.py @@ -2,6 +2,7 @@ import logging import json import time +from math import floor from tagilmo import VereyaPython import tagilmo.utils.mission_builder as mb from tagilmo.utils.vereya_wrapper import MCConnector, RobustObserver @@ -20,7 +21,8 @@ def setUpClass(cls, *args, **kwargs): cls.block = mb.DrawBlock((start[0] + 2), -60, start[1] + 2, "cobblestone") cls.cuboid = mb.DrawCuboid(start[0]-2, -61, start[1]-1, start[0]-2, -58, start[1]-2, "diamond_block") cls.line = mb.DrawLine(start[0] - 2, -62, start[1]-2, start[1] + 2, -62, start[1]+ 2, "redstone_block") - draw = mb.DrawingDecorator([cls.cuboid, cls.line, cls.block,]) + cls.item = mb.DrawItem(start[0] + 1, -60, start[1], "diamond") + draw = mb.DrawingDecorator([cls.cuboid, cls.line, cls.block, cls.item]) mc, obs = init_mission(None, start_x=start[0], start_z=start[1], seed='4', forceReset="true", start_y=-60, worldType="flat", drawing_decorator=draw) cls.mc = mc cls.obs = obs @@ -93,7 +95,18 @@ def test_draw_line(self): needed_blocks = [line.blockType] * (steps + 1) self.assertEqual(needed_blocks, real_blocks) time.sleep(1) - + + def test_draw_item(self): + mc = self.mc + print('send ochat') + real_entity = mc.getNearEntities()[0] #there is only one entity in this test (agent does not count) + entity = self.item + real_entity_type = real_entity['name'] + #entities spawn at center of the block surface when summoned via /summon command + self.assertEqual([entity.x, entity.y, entity.z], [floor(real_entity['x']), floor(real_entity['y']), floor(real_entity['z'])]) + self.assertEqual(entity.itemType, real_entity_type) + time.sleep(1) + def main(): VereyaPython.setupLogger() unittest.main() From 462849119df715c46beb6289043a49de24fec4e3 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Mon, 4 Nov 2024 22:35:38 +0300 Subject: [PATCH 5/5] added test_draw to 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 174a119..7712a05 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_flat_world'] + 'test_consistency', 'test_motion_mob', 'test_mob', 'test_agent', 'test_flat_world', 'test_draw'] res = run_tests(test_files) if not res.wasSuccessful(): sys.exit(1)