Example #1
0
 def test_handle_status_change_critical_mana_then_hi_pri_hp(self) -> None:
     # given
     char_status_crit_mana = CharStatus(
         hp=TOTAL_HP,
         mana=0,
         magic_shield_level=0,
         equipment_status={},
         speed=HASTED_SPEED,
     )
     char_status_hi_pri_hp = CharStatus(
         hp=POTION_HP_LO + 1,
         mana=TOTAL_MANA,
         magic_shield_level=0,
         equipment_status={
             "has_greater_heal_potions": True,
             "has_medium_heal_potions": True,
         },
         speed=HASTED_SPEED,
     )
     mock_client = Mock()
     target = KnightPotionKeeper(total_hp=TOTAL_HP,
                                 client=mock_client,
                                 battle_config=make_battle_config())
     target.handle_status_change(char_status=char_status_crit_mana,
                                 is_downtime=True)
     # when
     target.handle_status_change(char_status=char_status_hi_pri_hp,
                                 is_downtime=True)
     # then
     mock_client.drink_medium_heal.assert_called_with(666)
def stress_run_view(cliwin):
    # set the view's state
    int_rotation = [111, 22, 3333, 4, 55555]
    str_rotation = ['first', 'second', 'third', 'fourth', 'fifth']
    char_status = CharStatus(hp=int_rotation[0],
                             speed=int_rotation[1],
                             mana=int_rotation[2],
                             magic_shield_level=int_rotation[3],
                             equipment_status={
                                 'emergency_action_amulet': str_rotation[0],
                                 'emergency_action_ring': str_rotation[1],
                                 'equipped_ring': str_rotation[2],
                                 'equipped_amulet': str_rotation[3],
                                 'magic_shield_status': str_rotation[4],
                             })

    def update_status(char_status, idx):
        char_status.hp = int_rotation[idx % len(int_rotation)]
        char_status.speed = int_rotation[(idx + 1) % len(int_rotation)]
        char_status.mana = int_rotation[(idx + 2) % len(int_rotation)]
        char_status.magic_shield_level = \
            int_rotation[(idx + 3) % len(int_rotation)]
        char_status.emergency_action_amulet = \
            str_rotation[(idx + 0) % len(str_rotation)]
        char_status.emergency_action_ring = \
            str_rotation[(idx + 1) % len(str_rotation)]
        char_status.equipped_ring = str_rotation[(idx + 2) % len(str_rotation)]
        char_status.equipped_amulet = \
            str_rotation[(idx + 3) % len(str_rotation)]
        char_status.magic_shield_status = \
            str_rotation[(idx + 4) % len(str_rotation)]

    view = RunView()
    view.title = "This is a stress test of the RunView."
    view.main_options = "These are the main options of the RunView."
    view.error = "This is the error row of the RunView."
    renderer = ViewRenderer(cliwin)
    # enter state
    renderer.start()
    # transition into main view
    renderer.change_views(view)
    try:
        i = 0
        while True:
            view.set_char_stats(char_status)
            view.set_magic_shield_status(char_status.magic_shield_status)
            view.set_equipped_ring(char_status.equipped_ring)
            view.set_equipped_amulet(char_status.equipped_amulet)
            view.set_emergency_action_amulet(
                char_status.emergency_action_amulet)
            view.set_emergency_action_ring(char_status.emergency_action_ring)
            view.add_log(
                f"This is log #{i} and it is very very long. Let us see.",
                -100)
            view.error = f"Number of log entries: {i}"
            i += 1
            update_status(char_status, i)
            sleep(0.125)
    finally:
        renderer.stop()
 def setUp(self):
     self.char_status = CharStatus(TOTAL_MANA, TOTAL_HP, 1000, MAGIC_SHIELD,
                                   EQUIPMENT_STATUS)
     self.mock_client = Mock()
     self.mock_cast_magic_shield = self.mock_client.cast_magic_shield
     self.mock_cancel_magic_shield = self.mock_client.cancel_magic_shield
     self.target = MagicShieldKeeper(self.mock_client, TOTAL_HP,
                                     MAGIC_SHIELD_TRESHOLD, self.time_fn)
     self.time = START_TIME
Example #4
0
 def test_handle_status_change_mana_hi(self) -> None:
     self.check_handle_status_change(
         # given
         CharStatus(
             hp=TOTAL_HP,
             mana=MANA_HI,
             magic_shield_level=0,
             equipment_status={},
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: m.drink_mana.assert_called_with(1681),
     )
Example #5
0
 def test_handle_status_change_hp_potion_hi_no_minor_heal(self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=POTION_HP_HI,
             mana=TOTAL_MANA,
             magic_shield_level=0,
             equipment_status={"has_minor_heal_potions": False},
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: self.assertEqual(len(m.method_calls), 0),
     )
Example #6
0
 def test_handle_status_change_hp_potion_hi(self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=POTION_HP_HI,
             mana=TOTAL_MANA,
             magic_shield_level=0,
             equipment_status={},
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: m.drink_minor_heal.assert_called_with(1681),
     )
Example #7
0
 def test_handle_status_change_hp_potion_lo_no_medium_heal(self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=POTION_HP_LO,
             mana=TOTAL_MANA,
             magic_shield_level=0,
             equipment_status={"has_medium_heal_potions": False},
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: m.drink_greater_heal.assert_called_with(814),
     )
Example #8
0
 def test_handle_status_change_hp_critical(self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=POTION_HP_CRITICAL - 1,
             mana=TOTAL_MANA,
             magic_shield_level=0,
             equipment_status={},
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: m.drink_greater_heal.assert_called_with(666),
     )
Example #9
0
 def test_handle_status_change_mana_downtime(self) -> None:
     self.check_handle_status_change(
         # given
         CharStatus(
             hp=TOTAL_HP,
             mana=DOWNTIME_MANA - 1,
             magic_shield_level=0,
             equipment_status={},
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: m.drink_mana.assert_called_with(2445),
     )
Example #10
0
 def test_handle_status_change_hp_downtime(self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=TOTAL_HP - HEAL_AT_MISSING - 1,
             mana=TOTAL_MANA,
             magic_shield_level=0,
             equipment_status={},
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: m.drink_minor_heal.assert_called_with(2472),
     )
Example #11
0
 def test_handle_status_change_downtime_but_not_is_downtime(self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=TOTAL_HP - HEAL_AT_MISSING - 1,
             mana=DOWNTIME_MANA - 1,
             magic_shield_level=0,
             equipment_status={},
             speed=HASTED_SPEED,
         ),
         is_downtime=False,
         # then
         assert_fn=lambda m: self.assertEqual(len(m.method_calls), 0),
     )
Example #12
0
 def test_handle_status_change_no_refill(self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=TOTAL_HP,
             mana=TOTAL_MANA,
             magic_shield_level=0,
             equipment_status={},
             speed=HASTED_SPEED,
         ),
         is_downtime=False,
         # then
         assert_fn=lambda m: self.assertEqual(len(m.method_calls), 0),
     )
def status(hp=TOTAL_HP,
           mana=TOTAL_MANA,
           speed=HASTED_SPEED,
           magic_shield_level=0,
           equipped_amulet=AmuletName.UNKNOWN.name,
           equipped_ring=RingName.UNKNOWN.name,
           emergency_action_amulet=AmuletName.UNKNOWN.name,
           emergency_action_ring=RingName.UNKNOWN.name,
           magic_shield_status=MagicShieldStatus.OFF_COOLDOWN):
    return CharStatus(
        hp, speed, mana, magic_shield_level, {
            'equipped_amulet': equipped_amulet,
            'equipped_ring': equipped_ring,
            'emergency_action_amulet': emergency_action_amulet,
            'emergency_action_ring': emergency_action_ring,
            'magic_shield_status': magic_shield_status,
        })
Example #14
0
 def test_handle_status_change_hp_potion_hi_mana_lo_no_heal_potions(
         self) -> None:
     # given
     self.check_handle_status_change(
         CharStatus(
             hp=POTION_HP_HI,
             mana=MANA_LO,
             magic_shield_level=0,
             equipment_status={
                 "has_greater_heal_potions": False,
                 "has_medium_heal_potions": False,
                 "has_minor_heal_potions": False,
             },
             speed=HASTED_SPEED,
         ),
         # then
         lambda m: m.drink_mana.assert_called_with(920),
     )
Example #15
0
def stress_run_view(cliwin):
    # set the view's state
    int_rotation = [111, 22, 3333, 4, 55555]
    str_rotation = [
        "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
        "eigth", "ninth"
    ]
    char_status = CharStatus(
        hp=int_rotation[0],
        speed=int_rotation[1],
        mana=int_rotation[2],
        magic_shield_level=int_rotation[3],
        equipment_status={
            "normal_action_amulet": str_rotation[0],
            "normal_action_ring": str_rotation[1],
            "emergency_action_amulet": str_rotation[2],
            "emergency_action_ring": str_rotation[3],
            "tank_action_amulet": str_rotation[4],
            "tank_action_ring": str_rotation[5],
            "equipped_ring": str_rotation[6],
            "equipped_amulet": str_rotation[7],
            "magic_shield_status": str_rotation[8],
        },
    )

    def update_status(char_status, idx):
        char_status.hp = int_rotation[idx % len(int_rotation)]
        char_status.speed = int_rotation[(idx + 1) % len(int_rotation)]
        char_status.mana = int_rotation[(idx + 2) % len(int_rotation)]
        char_status.magic_shield_level = int_rotation[(idx + 3) %
                                                      len(int_rotation)]
        char_status.normal_action_amulet = str_rotation[(idx + 0) %
                                                        len(str_rotation)]
        char_status.normal_action_ring = str_rotation[(idx + 1) %
                                                      len(str_rotation)]
        char_status.emergency_action_amulet = str_rotation[(idx + 2) %
                                                           len(str_rotation)]
        char_status.emergency_action_ring = str_rotation[(idx + 3) %
                                                         len(str_rotation)]
        char_status.tank_action_amulet = str_rotation[(idx + 4) %
                                                      len(str_rotation)]
        char_status.tank_action_ring = str_rotation[(idx + 5) %
                                                    len(str_rotation)]
        char_status.equipped_ring = str_rotation[(idx + 6) % len(str_rotation)]
        char_status.equipped_amulet = str_rotation[(idx + 7) %
                                                   len(str_rotation)]
        char_status.magic_shield_status = str_rotation[(idx + 8) %
                                                       len(str_rotation)]

    view = RunView()
    view.title = "This is a stress test of the RunView."
    view.main_options = "These are the main options of the RunView."
    view.error = "This is the error row of the RunView."
    renderer = ViewRenderer(cliwin)
    # enter state
    renderer.start()
    # transition into main view
    renderer.change_views(view)
    try:
        i = 0
        while True:
            view.set_char_stats(char_status)
            view.set_magic_shield_status(char_status.magic_shield_status)
            view.set_equipped_ring(char_status.equipped_ring)
            view.set_equipped_amulet(char_status.equipped_amulet)
            view.set_emergency_action_amulet(
                char_status.emergency_action_amulet)
            view.set_emergency_action_ring(char_status.emergency_action_ring)
            view.set_tank_action_amulet(char_status.tank_action_amulet)
            view.set_tank_action_ring(char_status.tank_action_ring)
            view.add_log(
                f"This is log #{i} and it is very very long. Let us see.",
                -100)
            view.error = f"Number of log entries: {i}"
            i += 1
            update_status(char_status, i)
            sleep(0.125)
    finally:
        renderer.stop()