Ejemplo n.º 1
0
    def test_invalid_attack_type(self, attack_type, caplog):
        with pytest.raises(ValueError):
            _ = dealt_damage(
                attacker=Pokemon.generate_random("random", 10),
                defender=Pokemon.generate_random("random", 10),
                attack_type=attack_type,
                attack_power=1,
                attack_modifier=1,
                defense_modifier=1,
                global_modifier=1,
            )

        for record in caplog.records:
            assert record.levelname == "ERROR"
            assert "An invalid attack type was provided" in record.message
Ejemplo n.º 2
0
    def test_generation_fails_with_invalid_name(self, caplog):
        with pytest.raises(ValueError):
            _ = Pokemon.generate_random("Human", 50)

        for record in caplog.records:
            assert record.levelname == "ERROR"
            assert "An invalid pokemon name was provided" in record.message
Ejemplo n.º 3
0
    def test_negative_health_attribution(self, caplog):
        poke = Pokemon.generate_random("Paras", 10)
        poke.health = -20  # health should never be a negative value
        assert poke.health == 0  # make sure checks have handled the pokemon fainting

        for record in caplog.records:
            assert record.levelname == "CRITICAL"
            assert "HP have dropped below 0, pokemon has fainted!" in record.message
Ejemplo n.º 4
0
    def test_health_drops_below_0(self, caplog):
        poke = Pokemon.generate_random("Paras", 10)
        poke.health -= 1000  # to make sure we get below 0
        assert poke.health == 0  # make sure checks have handled the pokemon fainting

        for record in caplog.records:
            assert record.levelname == "CRITICAL"
            assert "HP have dropped below 0, pokemon has fainted!" in record.message
Ejemplo n.º 5
0
    def test_experience_to_level_invalid_curve(self, leveling_type, caplog):
        poke = Pokemon.generate_random("random", 30)
        with pytest.raises(ValueError):
            poke.experience_to_level(31, leveling_type)

        for record in caplog.records:
            assert record.levelname == "ERROR"
            assert "Invalid leveling curve." in record.message
Ejemplo n.º 6
0
    def test_experience_to_level_invalid_level(self, target_level, caplog):
        poke = Pokemon.generate_random("random", 30)
        with pytest.raises(ValueError):
            poke.experience_to_level(target_level, "slow")

        for record in caplog.records:
            assert record.levelname == "ERROR"
            assert "Invalid target level: too high." in record.message
Ejemplo n.º 7
0
    def test_level_up(self):
        poke = Pokemon.generate_random("Reptincel", 75)
        poke.ev = [50, 50, 50, 50, 50, 50]  # give it life experience
        before_level_up = poke.copy()

        assert poke.level == 75
        assert before_level_up.level == 75

        poke.level_up()
        assert poke.level == 76
        assert poke.health != before_level_up.health
        assert poke.attack != before_level_up.attack
        assert poke.defense != before_level_up.defense
        assert poke.special_attack != before_level_up.special_attack
        assert poke.special_defense != before_level_up.special_defense
        assert poke.speed != before_level_up.speed
        assert poke.total != before_level_up.total
Ejemplo n.º 8
0
 def test_generated_pokemon(self):
     poke = Pokemon.generate_random("Dracaufeu", 100)
     assert isinstance(poke, Pokemon)
     assert poke.name == "Dracaufeu"
     assert poke.level == 100
     assert hasattr(poke, "code")
     assert hasattr(poke, "number")
     assert hasattr(poke, "health")
     assert hasattr(poke, "attack")
     assert hasattr(poke, "defense")
     assert hasattr(poke, "special_attack")
     assert hasattr(poke, "special_defense")
     assert hasattr(poke, "speed")
     assert hasattr(poke, "nature")
     assert hasattr(poke, "iv")
     assert hasattr(poke, "ev")
     assert hasattr(poke, "accuracy")
     assert hasattr(poke, "dodge")
     assert hasattr(poke, "base_xp")
     assert hasattr(poke, "base_ev")
Ejemplo n.º 9
0
 def test_generating_true_random(self):
     random_poke = Pokemon.generate_random("random", 10)
     assert random_poke.name in base_stats.POKEMONS_DF.name.to_numpy()
Ejemplo n.º 10
0
    def test_write_read_pickle(self, tmp_path):
        random_salameche = Pokemon.generate_random("Salameche", 37)
        random_salameche.to_pickle(tmp_path / "save.pkl")

        read_salameche = Pokemon.from_pickle(tmp_path / "save.pkl")
        assert read_salameche == random_salameche
Ejemplo n.º 11
0
    def test_write_read_json(self, tmp_path):
        random_pikachu = Pokemon.generate_random("Pikachu", 25)
        random_pikachu.to_json(tmp_path / "save.json")

        read_pikachu = Pokemon.from_json(tmp_path / "save.json")
        assert read_pikachu == random_pikachu
Ejemplo n.º 12
0
    def test_invalid_health_type_attribution(self, invalid_type):
        poke = Pokemon.generate_random("random", 50)

        with pytest.raises(ValidationError):
            poke.health = invalid_type