class TestPathfindingService(object): TEST_IMAGE_FILE = "../resources/test_data/image_detection/world_mixed/vlcsnap-2016-03-25-01h40m32s095.png" SAMPLE_POSITION = Vector2(5, 5) SAMPLE_NODE_PATH = NodePath([Node(SAMPLE_POSITION)]) @classmethod def setup_class(cls): test_image = Image.from_file(cls.TEST_IMAGE_FILE) cls._coordinate_factory = CoordinateFactory() cls._world_map_service = WorldMapService(cls._coordinate_factory) cls._world_map = cls._world_map_service.detect_objects(test_image) @mock.patch('services.pathfinding.PathfindingService.Pathfinder', autospec = False) def setup(self, pathfinder_mock): self._pathfinder_mock_instance = pathfinder_mock.return_value self._pathfinder_mock_instance.find_path.side_effect = self._find_path_mock self._pathfinding_service = PathfindingService(self._pathfinder_mock_instance, self._world_map_service, self._coordinate_factory) def _find_path_mock(self, pathfinder_config): return self.SAMPLE_NODE_PATH def test_given_island_description_when_finding_path_to_island_then_path_is_returned(self): path, island = self._pathfinding_service.find_path_to_island(IslandDescriptor(IslandType.TRIANGLE, IslandColor.RED)) assert_equals(path.vertices[0], self.SAMPLE_POSITION) @raises(NoPathFoundError) def test_given_unexisting_island_description_when_finding_path_to_island_then_rror_is_raised(self): self._pathfinding_service.find_path_to_island(IslandDescriptor(IslandType.PENTAGON, IslandColor.RED)) def test_when_finding_path_to_treasure_then_path_is_returned(self): path, treasure = self._pathfinding_service.find_path_to_treasure() assert_equals(path.vertices[0], self.SAMPLE_POSITION) @raises(NoPathFoundError) def test_given_no_path_to_island_when_finding_path_to_treasure_then_error_is_raised(self): self._pathfinder_mock_instance.find_path.side_effect = NoPathFoundError() self._pathfinding_service.find_path_to_treasure() def test_when_finding_path_to_charging_station_then_path_is_returned(self): path, target_location = self._pathfinding_service.find_path_to_charging_station() assert_equals(path.vertices[0], self.SAMPLE_POSITION) @raises(NoPathFoundError) def test_given_no_path_to_charging_station_when_finding_path_to_charging_station_then_error_is_raised(self): self._pathfinder_mock_instance.find_path.side_effect = NoPathFoundError() self._pathfinding_service.find_path_to_charging_station()
def setup(self, pathfinder_mock): self._pathfinder_mock_instance = pathfinder_mock.return_value self._pathfinder_mock_instance.find_path.side_effect = self._find_path_mock self._pathfinding_service = PathfindingService(self._pathfinder_mock_instance, self._world_map_service, self._coordinate_factory)