Example #1
0
def test_ghost_wait_before_attack(planet1, planet2):
    game = Mock(spec=GameInterface)
    ticks = set()

    my_planets = [planet1, planet2]
    missions = {
        "hostile": [
            FleetMovement(time1="30h",
                          time2=None,
                          mission="Attaquer",
                          src="[666:666:666]",
                          dst="[1:1:1]")
        ],
        "friendly": [],
    }

    game.get_planets_and_missions = Mock(return_value=(my_planets, missions))
    # noinspection PyTypeChecker
    ghost_fleet_if_necessary(game, ticks)

    game.ghost.assert_not_called()

    assert len(ticks) == 1
    time = next(iter(ticks))
    assert time > datetime.now(), "Next trigger must be in the future"
    assert time - datetime.now() >= TIME_OFFSET
Example #2
0
 def _trigger_bot(self, game: GameInterface,
                  ticks: Set[datetime.datetime]) -> None:
     """
     Trigger main algorithm of the bot.
     :param game: Game interface
     :param ticks: Set of datetime of when to trigger the bot again.
     """
     game.log_in(self.config)
     ghost_fleet_if_necessary(
         game, ticks)  # Will ghost the fleet on threatened planets.
Example #3
0
def test_ghost_planets_are_safe(planet1, planet2):
    game = Mock(spec=GameInterface)
    ticks = set()

    my_planets = [planet1, planet2]
    missions = {
        "hostile": [],
        "friendly": [],
    }

    game.get_planets_and_missions = Mock(return_value=(my_planets, missions))
    # noinspection PyTypeChecker
    ghost_fleet_if_necessary(game, ticks)
    game.ghost.assert_not_called()
Example #4
0
def test_ghost_retrieve(planet1, planet2, ghost_mission):
    game = Mock(spec=GameInterface)
    ticks = set()

    my_planets = [planet1, planet2]
    missions = {
        "hostile": [],
        "friendly": [ghost_mission],
    }

    game.get_planets_and_missions = Mock(return_value=(my_planets, missions))
    # noinspection PyTypeChecker
    ghost_fleet_if_necessary(game, ticks)
    game.retrieve_fleet.assert_called_once_with("[1:1:1]")
Example #5
0
def test_ghost_one_planet_attacked(planet1, planet2, attack1):
    game = Mock(spec=GameInterface)
    ticks = set()

    my_planets = [planet1, planet2]
    missions = {
        "hostile": [attack1],
        "friendly": [],
    }

    game.get_planets_and_missions = Mock(return_value=(my_planets, missions))
    # noinspection PyTypeChecker
    ghost_fleet_if_necessary(game, ticks)
    game.ghost.assert_called_once_with(planet1, ['2', '2', '2', 'PLANET'])
Example #6
0
def test_ghost_cant_ghost(planet1, planet2, attack1):
    game = Mock(spec=GameInterface)
    ticks = set()

    my_planets = [planet1, planet2]
    missions = {
        "hostile": [attack1],
        "friendly": [],
    }

    game.get_planets_and_missions = Mock(return_value=(my_planets, missions))
    game.ghost = Mock(side_effect=Exception("Failed to ghost"))
    # noinspection PyTypeChecker
    ghost_fleet_if_necessary(game, ticks)
    assert game.ghost.call_count == RETRIES_COUNT
Example #7
0
def test_ghost_two_planet_attacked(planet1, planet2, attack1, attack2):
    game = Mock(spec=GameInterface)
    ticks = set()

    my_planets = [planet1, planet2]
    missions = {
        "hostile": [attack1, attack2],
        "friendly": [],
    }

    game.get_planets_and_missions = Mock(return_value=(my_planets, missions))
    # noinspection PyTypeChecker
    ghost_fleet_if_necessary(game, ticks)
    assert game.ghost.call_count == 2
    game.ghost.assert_has_calls([
        call(planet1, ['2', '2', '2', 'PLANET']),
        call(planet2, ['1', '1', '1', 'PLANET']),
    ],
                                any_order=True)