import unittest from munch import Munch from mosfet.info import blocks from mosfet.jobs.gather_crop import GatherCropStates from mosfet.jobs.gather_wood import GatherWoodStates class SignWorkTargetTests(unittest.TestCase): def test_crop_search_filters_out_of_bounds_candidates_before_navigation(self): outside = (10, 64, 0) mature_wheat = blocks.MATURE_WHEAT_ID crop_state = blocks.MCD_BLOCKS['wheat']['minStateId'] class FakeWorld: def find_blocks_indexed(self, _center, _block_ids, _distance): return [outside] @staticmethod def work_position_allowed(position): return position != outside def filter_work_positions(self, positions): return [position for position in positions if self.work_position_allowed(position)] @staticmethod def block_at(*_position): return crop_state state = GatherCropStates(Munch(world=FakeWorld(), pos=(0, 64, 0))) state.find_new_crop() self.assertIs(state.state.__func__, state.wait_for_crops.__func__) self.assertEqual(state.bad_crops, []) def test_tree_search_skips_out_of_bounds_tree_without_blacklisting_it(self): outside = (10, 64, 0) inside = (2, 64, 0) oak_log = blocks.MCD_BLOCKS['oak_log']['minStateId'] class FakeWorld: @staticmethod def find_trees(_center, _distance): return [outside, inside] @staticmethod def work_position_allowed(position): return position != outside def filter_work_positions(self, positions): return [position for position in positions if self.work_position_allowed(position)] @staticmethod def block_at(*_position): return oak_log state = GatherWoodStates(Munch(world=FakeWorld(), pos=(0, 64, 0))) state.find_new_tree() self.assertEqual(state.tree, inside) self.assertEqual(state.type, 'oak') self.assertEqual(state.bad_trees, []) if __name__ == '__main__': unittest.main()