Пример #1
0
    def test_snap_to_over_distance():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.50451, -0.07607, 10)

        # pre-calculated distance is 17.8 meters
        stepper.snap_to(51.50436, -0.07616, 11)

        pgo = api_wrapper.get_api()
        lat, lng, alt = pgo.get_position()

        assert stepper.current_lat == 51.50451
        assert stepper.current_lng == -0.07607
        assert stepper.current_alt == 10
        assert lat == 51.50451
        assert lng == -0.07607
        assert alt == 10
    def test_execute_fails(self):
        engine = Mock()
        engine.log = Mock()
        engine.log.info = MagicMock()
        engine.log.failed = MagicMock()

        topics = [Mock()]
        get_topics_mock = Mock(return_value=topics)

        execute_mock1 = MagicMock(side_effect=Exception)
        execute_mock2 = MagicMock(side_effect=Exception)

        self.tracker1.execute = execute_mock1
        self.tracker1.get_topics = get_topics_mock

        self.tracker2.execute = execute_mock2
        self.tracker2.get_topics = get_topics_mock

        self.trackers_manager.execute(engine, None)

        self.assertTrue(engine.log.info.called)
        self.assertTrue(engine.log.failed.called)
        get_topics_mock.assert_called_with(None)
        execute_mock1.assert_called_with(topics, engine)
        execute_mock2.assert_called_with(topics, engine)
Пример #3
0
    def test_navigate_campsite_last_position(self):
        config = create_core_test_config({
            "movement": {
                "navigator_campsite": None
            },
            "mapping": {
                "location": "0,0"
            }
        })
        api_wrapper = create_mock_api_wrapper(config)

        logger = Mock()
        logger.log = Mock(return_value=None)
        navigator = CamperNavigator(config, api_wrapper, logger)
        map_cells = self._create_map_cells()

        destinations = list()
        for destination in navigator.navigate(map_cells):
            assert isinstance(destination, Destination)

            assert destination.target_lat == 0
            assert destination.target_lng == 0
            assert destination.name == "Camping position at 0,0"

            destinations.append(destination)

        assert len(destinations) == 1
    def test_execute_with_ids(self):
        engine = Mock()
        engine.log = Mock()
        engine.log.info = MagicMock()
        engine.log.failed = MagicMock()

        topics1 = [Mock()]
        get_topics_mock1 = Mock(return_value=topics1)

        topics2 = []
        get_topics_mock2 = Mock(return_value=topics2)

        execute_mock1 = Mock()
        # Exception shouldn't be thrown because there are no tocpis for plugin
        execute_mock2 = Mock(return_value=Exception)

        self.tracker1.execute = execute_mock1
        self.tracker1.get_topics = get_topics_mock1

        self.tracker2.execute = execute_mock2
        self.tracker2.get_topics = get_topics_mock2

        ids = [1, 2]
        self.trackers_manager.execute(engine, ids)

        self.assertTrue(engine.log.info.called)
        self.assertFalse(engine.log.failed.called)  # Check that exception from tracker2 wasn't raised
        get_topics_mock1.assert_called_with(ids)
        execute_mock1.assert_called_with(topics1, engine)
        get_topics_mock2.assert_called_with(ids)
        execute_mock2.assert_not_called()
Пример #5
0
    def test_navigate_campsite_add_before_start(self):
        config = create_core_test_config({
            "movement": {
                "navigator_campsite": [51.5043872, -0.0741802]
            },
        })
        api_wrapper = create_mock_api_wrapper(config)

        logger = Mock()
        logger.log = Mock(return_value=None)
        navigator = CamperNavigator(config, api_wrapper, logger)
        map_cells = self._create_map_cells()

        navigator.set_campsite(51.5060435, -0.073983)
        destinations = list()
        for destination in navigator.navigate(map_cells):
            assert isinstance(destination, Destination)

            assert destination.target_lat == 51.5060435
            assert destination.target_lng == -0.073983
            assert destination.name == "Camping position at 51.5060435,-0.073983"

            destinations.append(destination)

        assert len(destinations) == 1
Пример #6
0
    def test_favorited_pokemon_filter(self):
        event_manager = EventManager()
        logger = Mock()
        logger.log = Mock()
        transfer_plugin = TransferPokemon(
            {
                'transfer_on_start': False
            },
            event_manager,
            logger
        )

        bot = create_mock_bot()

        transfer_list = [self._create_pokemon(unique_id=1, favorite=True),
                         self._create_pokemon(unique_id=2, favorite=True),
                         self._create_pokemon(unique_id=3, favorite=True),
                         self._create_pokemon(unique_id=4, favorite=False),
                         self._create_pokemon(unique_id=5, favorite=True),
                         self._create_pokemon(unique_id=6, favorite=False)]

        result_dict = transfer_plugin.filter_favorited_pokemon(bot=bot, transfer_list=transfer_list)
        filtered_list = result_dict["transfer_list"]
        assert len(filtered_list) == 2
        assert filtered_list[0].unique_id == 4
        assert filtered_list[1].unique_id == 6
        assert result_dict["filter_list"][0] == "excluding favorited Pokemon"

        transfer_list = [self._create_pokemon(favorite=False)]
        result_dict = transfer_plugin.filter_favorited_pokemon(bot=bot, transfer_list=transfer_list)
        assert len(result_dict["transfer_list"]) == 1
        assert len(result_dict["filter_list"]) == 0

        self.set_empty_inventory(bot)
        assert transfer_plugin.filter_favorited_pokemon(bot=bot) is False
Пример #7
0
    def test_start():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 4.16,
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)

        stepper.start(51.5044524, -0.0752479, 10)

        assert stepper.origin_lat == 51.5044524
        assert stepper.origin_lng == -0.0752479
        assert stepper.origin_alt == 10

        assert stepper.current_lat == 51.5044524
        assert stepper.current_lng == -0.0752479
        assert stepper.current_alt == 10

        pgo = api_wrapper.get_api()
        lat, lng, alt = pgo.get_position()

        assert lat == 51.5044524
        assert lng == -0.0752479
        assert alt == 10
Пример #8
0
    def test_init():
        logger = Mock()
        logger.log = Mock(return_value=None)

        config_namespace = create_core_test_config()
        api_wrapper = create_mock_api_wrapper(config_namespace)
        event_manager = EventManager()
        player_service = Player(api_wrapper, event_manager, logger)
        pokemon_service = PokemonService(api_wrapper)
        mapper = Mapper(config_namespace, api_wrapper, Mock(), logger)
        path_finder = DirectPathFinder(config_namespace)
        stepper = Stepper(config_namespace, api_wrapper, path_finder, logger)
        navigator = FortNavigator(config_namespace, api_wrapper)

        bot = PokemonGoBot(config_namespace, api_wrapper, player_service, pokemon_service, event_manager, mapper, stepper, navigator, logger)

        assert len(bot.pokemon_list) == 151
        assert len(bot.item_list) == 30
        assert bot.position == (0, 0, 0)

        assert bot.config is config_namespace
        assert bot.api_wrapper is api_wrapper
        assert bot.player_service is player_service
        assert bot.pokemon_service is pokemon_service
        assert bot.event_manager is event_manager
        assert bot.mapper is mapper
        assert bot.stepper is stepper
        assert bot.navigator is navigator
        assert bot.logger is logger
Пример #9
0
    def test_init_path_finder_direct():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 4.16,
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)

        assert isinstance(stepper.path_finder, DirectPathFinder)
Пример #10
0
    def test_init_negative_walk():
        config = create_core_test_config({
            "movement": {
                "walk_speed": -5,
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = Mock()
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)

        assert stepper.speed == 4.16
Пример #11
0
    def test_ignore_list_filter(self):
        event_manager = EventManager()
        logger = Mock()
        logger.log = Mock()
        transfer_plugin = TransferPokemon(
            {
                'transfer_on_start': False,
                'use_always_keep_filter': True,
                'use_cp_iv_filter': False,
                'always_keep': {
                    'Bulbasaur': True,
                    'Ivysaur': True,
                    'Venusaur': True,
                }
            },
            event_manager,
            logger
        )

        bot = create_mock_bot()

        transfer_list = [self._create_pokemon(unique_id=1, species_id=1),
                         self._create_pokemon(unique_id=2, species_id=5),
                         self._create_pokemon(unique_id=3, species_id=2),
                         self._create_pokemon(unique_id=4, species_id=4),
                         self._create_pokemon(unique_id=5, species_id=3),
                         self._create_pokemon(unique_id=6, species_id=1),
                         self._create_pokemon(unique_id=7, species_id=5)]

        result_dict = transfer_plugin.filter_pokemon_by_ignore_list(bot=bot, transfer_list=transfer_list)
        filtered_list = result_dict["transfer_list"]
        assert len(filtered_list) == 3
        assert filtered_list[0].unique_id == 2
        assert filtered_list[1].unique_id == 4
        assert filtered_list[2].unique_id == 7
        assert "Bulbasaurs" in result_dict["filter_list"][0]
        assert "Ivysaurs" in result_dict["filter_list"][0]
        assert "Venusaurs" in result_dict["filter_list"][0]

        transfer_list = [self._create_pokemon(species_id=42)]
        result_dict = transfer_plugin.filter_pokemon_by_ignore_list(bot=bot, transfer_list=transfer_list)
        assert len(result_dict["transfer_list"]) == 1
        assert len(result_dict["filter_list"]) == 0

        transfer_list = [self._create_pokemon(species_id=1)]
        result_dict = transfer_plugin.filter_pokemon_by_ignore_list(bot=bot, transfer_list=transfer_list)
        assert len(result_dict["transfer_list"]) == 0
        assert result_dict["filter_list"][0] == "excluding Bulbasaurs"

        self.set_empty_inventory(bot)
        assert transfer_plugin.filter_pokemon_by_ignore_list(bot=bot) is False
Пример #12
0
    def test_step():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
                "path_finder": "direct",
                "distance_unit": "m"
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.50451, -0.07607, 10)

        destination = Destination(51.506000, -0.075049, 11, name="Test Destination", exact_location=False)
        steps = [
            (51.504778, -0.075838, 10),
            (51.505092, -0.075650, 11),
            (51.505436, -0.075446, 11)
        ]
        destination.set_steps(steps)

        pgo = api_wrapper.get_api()

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163411
        # pre-calculated distance is 17.8 meters
        pointer = 0
        for _ in stepper.step(destination):
            target_lat, target_lng, target_alt = steps[pointer]
            assert stepper.current_lat == target_lat
            assert stepper.current_lng == target_lng
            assert stepper.current_alt == target_alt

            bot_lat, bot_lng, bot_alt = pgo.get_position()
            assert bot_lat == target_lat
            assert bot_lng == target_lng
            assert bot_alt == target_alt

            pointer += 1

        assert pointer == 3

        bot_lat, bot_lng, bot_alt = pgo.get_position()
        assert bot_lat == 51.505436
        assert bot_lng == -0.075446
        assert bot_alt == 11
        assert stepper.current_lat == 51.505436
        assert stepper.current_lng == -0.075446
        assert stepper.current_alt == 11
Пример #13
0
    def __do_not_call(self):
        # s = Settings
        s = Mock()

        # methods:
        s.isOptionWritable = Mock(return_value=True)
        s.set = Mock(return_value=None)
        s.save = Mock()

        # props:
        s.log = Mock()

        # subobjects
        s.p = Mock()
        s.p.getboolean = Mock(return_value=True)
        s.p.has_option = Mock
Пример #14
0
    def test_wrap_pokemon(self):
        event_manager = EventManager()
        logger = Mock()
        logger.log = Mock()
        transfer_plugin = TransferPokemon(
            {
                'transfer_on_start': False
            },
            event_manager,
            logger
        )

        transfer_list = [self._create_pokemon(unique_id=1)]
        transfer_list = transfer_plugin.wrap_pokemon_in_list(transfer_list=transfer_list, pokemon=self._create_pokemon(unique_id=2))["transfer_list"]
        assert len(transfer_list) == 2
        assert transfer_list[0].unique_id == 1
        assert transfer_list[1].unique_id == 2
Пример #15
0
    def test_navigate_campsite_invalid_index(self):
        config = create_core_test_config({
            "movement": {
                "navigator_campsite": [51.5043872, -0.0741802]
            },
        })
        api_wrapper = create_mock_api_wrapper(config)

        logger = Mock()
        logger.log = Mock(return_value=None)
        navigator = CamperNavigator(config, api_wrapper, logger)
        navigator.pointer = 100
        map_cells = self._create_map_cells()

        destinations = list()
        for _ in navigator.navigate(map_cells):
            pass

        assert len(destinations) == 0
Пример #16
0
    def test_step_already_near_fort():
        calls = []
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
                "path_finder": "direct",
                "distance_unit": "m"
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)

        destination = Destination(51.50436, -0.07616, 11, name="Test Destination", exact_location=False)
        steps = [
            (51.50442, -0.07612, 10),
            (51.50448, -0.07609, 11),
            (51.50436, -0.07616, 11)
        ]
        destination.set_steps(steps)

        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.50451, -0.07607, 10)

        pgo = api_wrapper.get_api()

        # This route is being walked: http://www.darrinward.com/lat-long/?id=2163408
        calls.append(call("walking_started", coords=(51.50436, -0.07616, 11)))
        pointer = 0
        for _ in stepper.step(destination):
            pointer += 1

        assert pointer == 0

        bot_lat, bot_lng, bot_alt = pgo.get_position()
        assert bot_lat == 51.50451
        assert bot_lng == -0.07607
        assert bot_alt == 10
        assert stepper.current_lat == 51.50451
        assert stepper.current_lng == -0.07607
        assert stepper.current_alt == 10
Пример #17
0
    def test_includeme(self, mock_resolve):
        module = Mock()
        config = Mock()
        config.registry.settings = {'nefertari.engine': 'foo'}
        module.log = 1
        module.__testvar__ = 3
        module.another_var = 4
        mock_resolve.return_value = module
        from nefertari import engine
        assert not hasattr(engine, 'log')
        assert not hasattr(engine, '__testvar__')
        assert not hasattr(engine, 'another_var')

        engine.includeme(config)

        config.include.assert_called_once_with('foo')
        mock_resolve.assert_called_once_with('foo')
        assert not hasattr(engine, 'log')
        assert not hasattr(engine, '__testvar__')
        assert hasattr(engine, 'another_var')
Пример #18
0
    def test_get_route_between():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 5,
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = DirectPathFinder(config)
        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)
        stepper.start(51.5044524, -0.0752479, 10)

        # pre-calculated distance is 205.5 meters
        # expected steps is 205.5 / (0.6 * 5) = 68.5 (which rounds to 69)
        steps = stepper.get_route_between(51.5044524, -0.0752479, 51.5062939, -0.0750065, 10)

        assert len(steps) == 69

        for step in steps:
            assert len(step) == 3
Пример #19
0
def simple_step ():
	from octopus.sequence import Step
	from octopus.util import Event

	d = defer.Deferred()
	step = Mock(spec = Step)
	step.run = Mock(return_value = d)

	ok = defer.succeed(None)
	step.reset = Mock(return_value = ok)
	step.pause = Mock(return_value = ok)
	step.resume = Mock(return_value = ok)
	step.cancel = Mock(return_value = ok)
	step.abort = Mock(return_value = ok)

	step.event = Event()
	step.log = Event()

	step.duration = 10
	
	return d, step
Пример #20
0
    def test_init():
        config = create_core_test_config({
            "movement": {
                "walk_speed": 13.37,
            }
        })
        api_wrapper = create_mock_api_wrapper(config)
        path_finder = Mock()

        logger = Mock()
        logger.log = Mock(return_value=None)
        stepper = Stepper(config, api_wrapper, path_finder, logger)

        assert stepper.origin_lat is None
        assert stepper.origin_lng is None
        assert stepper.origin_alt is None

        assert stepper.current_lat is None
        assert stepper.current_lng is None
        assert stepper.current_alt is None

        assert stepper.speed == 13.37
Пример #21
0
def simple_step ():
	d = defer.Deferred()
	step = Mock(spec = Step)
	step.run = Mock(return_value = d)

	ok = defer.succeed(None)
	step.reset = Mock(return_value = ok)
	step.pause = Mock(return_value = ok)
	step.resume = Mock(return_value = ok)
	step.cancel = Mock(return_value = ok)

	step.event = Mock()
	step.event.__iadd__ = Mock()
	step.event.__isub__ = Mock()

	step.log = Mock()
	step.log.__iadd__ = Mock()
	step.log.__isub__ = Mock()

	step.duration = 10
	
	return d, step
    def test_execute_success(self):
        engine = Mock()
        engine.log = Mock()
        engine.log.info = MagicMock()
        engine.log.failed = MagicMock()

        execute_mock = MagicMock()

        topics = [Mock()]
        get_topics_mock = Mock(return_value=topics)

        self.tracker1.execute = execute_mock
        self.tracker1.get_topics = get_topics_mock

        self.tracker2.execute = execute_mock
        self.tracker2.get_topics = get_topics_mock

        self.trackers_manager.execute(engine, None)

        self.assertTrue(engine.log.info.called)
        self.assertFalse(engine.log.failed.called)
        get_topics_mock.assert_called_with(None)
        execute_mock.assert_called_with(topics, engine)
Пример #23
0
    def _create_generic_bot(config):
        logger = Mock()
        logger.log = Mock()
        config_namespace = create_core_test_config(config)
        api_wrapper = create_mock_api_wrapper(config_namespace)
        event_manager = Mock()
        player_service = Player(api_wrapper, event_manager, logger)
        pokemon_service = PokemonService(api_wrapper)
        mapper = Mapper(config_namespace, api_wrapper, Mock(), logger)
        path_finder = DirectPathFinder(config_namespace)
        stepper = Stepper(config_namespace, api_wrapper, path_finder, logger)
        navigator = FortNavigator(config_namespace, api_wrapper)

        return PokemonGoBot(
            config_namespace,
            api_wrapper,
            player_service,
            pokemon_service,
            event_manager,
            mapper,
            stepper,
            navigator,
            logger
        )