Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_mod_str(self):
self.assertEqual(stats.mod_str(-3), '-3')
self.assertEqual(stats.mod_str(0), '+0')
self.assertEqual(stats.mod_str(2), '+2')
def test_mod_str(self):
self.assertEqual(stats.mod_str(-3), '-3')
self.assertEqual(stats.mod_str(0), '+0')
self.assertEqual(stats.mod_str(2), '+2')
def test_saving_throw(self):
# Try it with an ST proficiency
class MyClass(character.Character):
saving_throw_proficiencies = ['strength']
proficiency_bonus = 2
strength = stats.Ability(14)
my_class = MyClass()
self.assertEqual(my_class.strength.saving_throw, 4)
def test_modifier(self):
class MyCharacter(character.Character):
saving_throw_proficiencies = ['strength']
proficiency_bonus = 2
strength = stats.Ability(14)
my_char = MyCharacter()
ranges = [
((1,), -5),
((2, 3), -4),
((4, 5), -3),
((6, 7), -2),
((8, 9), -1),
((10, 11), 0),
((12, 13), 1),
((14, 15), 2),
((16, 17), 3),
((18, 19), 4),
((20, 21), 5),
((22, 23), 6),
((24, 25), 7),
((26, 27), 8),
def test_skill(self):
"""Test for a skill, that depends on another ability."""
class MyClass(character.Character):
dexterity = stats.Ability(14)
acrobatics = stats.Skill(ability='dexterity')
skill_proficiencies = []
proficiency_bonus = 2
my_class = MyClass()
self.assertEqual(my_class.acrobatics, 2)
# Check for a proficiency
my_class.skill_proficiencies = ['acrobatics']
self.assertEqual(my_class.acrobatics, 4)
def test_weapon_damage(self):
weapon = Weapon()
weapon.base_damage = '1d6'
self.assertEqual(weapon.damage, '1d6')
# Now add some bonus damage
weapon.bonus_damage = 2
self.assertEqual(weapon.damage, '1d6 +2')
def test_spell_str(self):
spell = Spell()
spell.name = "My spell"
self.assertEqual(str(spell), 'My spell')
# Try with a ritual
spell.ritual = True
self.assertEqual(str(spell), 'My spell (R)')
# Try with a ritual and a concentration
spell.concentration = True
self.assertEqual(str(spell), 'My spell (R, C)')
def test_setter(self):
"""Verify that this class works as a data descriptor."""
# Set up a dummy class
class MyCharacter(character.Character):
stat = stats.Ability()
char = MyCharacter()
# Check that the stat works as expected once set
char.stat = 15
self.assertEqual(char.stat.value, 15)
self.assertEqual(char.stat.modifier, 2)
def test_wield_shield(self):
char = Character(dexterity=16)
char.wield_shield('shield')
self.assertTrue(isinstance(char.shield, Shield), msg=char.shield)
# Now make sure the armor class is correct
self.assertEqual(char.armor_class, 15)
# Try passing an Armor object directly
char.wield_shield(Shield)
self.assertEqual(char.armor_class, 15)
def test_speed(self):
# Check that the speed pulls from the character's race
char = Character(race='lightfoot halfling')
self.assertEqual(char.speed, '25')
# Check that a character with no race defaults to 30 feet
char = Character()
char.race = None
self.assertEqual(char.speed, '30')