Exemple #1
0
    def test_positive_integers(self, invalid_pokemon_code,
                               invalid_pokemon_number):
        with pytest.raises(ValidationError):
            _ = Pokemon(
                code=invalid_pokemon_code,
                number=37.0,
                name="Goupix",
                level=15,
                health=38.0,
                attack="41",
                defense=40.0,
                special_attack=50.0,
                special_defense=65.0,
                speed=65.0,
            )

        with pytest.raises(ValidationError):
            _ = Pokemon(
                code=5,
                number=invalid_pokemon_number,
                name="Goupix",
                level=15,
                health=38.0,
                attack="41",
                defense=40.0,
                special_attack=50.0,
                special_defense=65.0,
                speed=65.0,
            )
Exemple #2
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
Exemple #3
0
 def test_attributes_conversions(self):
     poke = Pokemon(
         code="50",
         number=37.0,
         name="Goupix",
         level=15,
         health=38.0,
         attack="41",
         defense=40.0,
         special_attack=50.0,
         special_defense=65.0,
         speed=65.0,
     )
     assert isinstance(poke.code, int)
     assert isinstance(poke.number, int)
     assert isinstance(poke.name, str)
     assert isinstance(poke.level, int)
     assert isinstance(poke.health, int)
     assert isinstance(poke.attack, int)
     assert isinstance(poke.defense, int)
     assert isinstance(poke.special_attack, int)
     assert isinstance(poke.special_defense, int)
     assert isinstance(poke.speed, int)
     assert isinstance(poke.total, int)
     assert isinstance(poke.iv, list)
     assert isinstance(poke.ev, list)
     assert isinstance(poke.accuracy, float)
     assert isinstance(poke.dodge, float)
Exemple #4
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
Exemple #5
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
Exemple #6
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
Exemple #7
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
Exemple #8
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
Exemple #9
0
 def test_total(self):
     poke = Pokemon(
         code=50,
         number=37,
         name="Goupix",
         level=15,
         health=38,
         attack=41,
         defense=40,
         special_attack=50,
         special_defense=65,
         speed=65,
     )
     assert poke.total == 299
Exemple #10
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
Exemple #11
0
    def test_load_pickle(self, _pokemon_pickle_file):
        nosferapti = Pokemon.from_pickle(_pokemon_pickle_file)

        assert nosferapti.code == 56
        assert nosferapti.number == 41
        assert nosferapti.name == "Nosferapti"
        assert nosferapti.level == 5
        assert nosferapti.health == 39
        assert nosferapti.attack == 25
        assert nosferapti.defense == 14
        assert nosferapti.special_attack == 14
        assert nosferapti.special_defense == 19
        assert nosferapti.speed == 24
        assert nosferapti.total == 135
        assert nosferapti.iv == [12, 27, 2, 3, 14, 16]
        assert nosferapti.ev == [0, 0, 0, 0, 0, 0]
        assert nosferapti.accuracy == 1.0
        assert nosferapti.dodge == 1.0
Exemple #12
0
    def test_load_json(self, _pokemon_json_file):
        bulbizarre = Pokemon.from_json(_pokemon_json_file)

        assert bulbizarre.code == 1
        assert bulbizarre.number == 1
        assert bulbizarre.name == "Bulbizarre"
        assert bulbizarre.level == 30
        assert bulbizarre.health == 221
        assert bulbizarre.attack == 103
        assert bulbizarre.defense == 117
        assert bulbizarre.special_attack == 162
        assert bulbizarre.special_defense == 169
        assert bulbizarre.speed == 96
        assert bulbizarre.total == 868
        assert bulbizarre.iv == [21, 0, 14, 27, 19, 12]
        assert bulbizarre.ev == [0, 0, 0, 0, 0, 0]
        assert bulbizarre.accuracy == 1.0
        assert bulbizarre.dodge == 1.0
Exemple #13
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")
Exemple #14
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
Exemple #15
0
    def test_invalid_health_type_attribution(self, invalid_type):
        poke = Pokemon.generate_random("random", 50)

        with pytest.raises(ValidationError):
            poke.health = invalid_type
Exemple #16
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
Exemple #17
0
def _defender_pokemon() -> Pokemon:
    return Pokemon.from_pickle(CURRENT_DIR / "inputs" / "nosferapti.pkl")
Exemple #18
0
def _attacker_pokemon() -> Pokemon:
    return Pokemon.from_json(CURRENT_DIR / "inputs" / "bulbizarre.json")
Exemple #19
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()