def test_homebrew_spells(self): char = Character() class MySpell(spells.Spell): name="my spell!" char.set_attrs(spells=(MySpell,)) self.assertIsInstance(char.spells[0], spells.Spell) self.assertEqual(char.spells[0].name, "my spell!")
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')
def test_st_bonus_all(self): char = Character() my_item = MyMagicItem(owner=char) char.magic_items = [my_item] # Test an item that confers no saving throw bonus bonus = my_item.st_bonus() self.assertEqual(bonus, 0) # Now test with positive ST bonus my_item.st_bonus_all = 2 bonus = my_item.st_bonus() self.assertEqual(bonus, 2)
def test_proficiencies_text(self): char = Character() char._proficiencies_text = ('hello', 'world') self.assertEqual(char.proficiencies_text, 'Hello, world.') # Check for extra proficiencies char.proficiencies_extra = ("it's", "me") self.assertEqual(char.proficiencies_text, "Hello, world, it's, me.") # Check that race proficienceis are included elf = race.HighElf() char.race = elf expected = "Hello, world, longswords, shortswords, shortbows, longbows, it's, me." self.assertEqual(char.proficiencies_text, expected)
def test_st_bonus_by_ability(self): char = Character(strength=10) my_item = MyMagicItem(owner=char) char.magic_items = [my_item] # Test an item with nonsense ability with self.assertRaises(AttributeError): my_item.st_bonus(ability="flight") # Test that the st_bonus_all is used if the specific ability is not listed my_item.st_bonus_all = 2 bonus = my_item.st_bonus(ability="strength") self.assertEqual(bonus, 2) # Test a specific st_bonus my_item.st_bonus_strength = 3 bonus = my_item.st_bonus(ability="strength") self.assertEqual(bonus, 3)
def test_set_attrs(self): char = Character() char.set_attrs(name='Inara') self.assertEqual(char.name, 'Inara') # Check that the weapons get loaded as objects not string char.set_attrs(weapons=['shortsword']) self.assertEqual(len(char.weapons), 1) self.assertTrue(isinstance(char.weapons[0], Shortsword)) # Check that armor and shield gets set_attrs char.set_attrs(armor='light leather armor', shield='shield') self.assertFalse(isinstance(char.armor, str)) self.assertFalse(isinstance(char.shield, str)) # Check that race gets set to an object char.set_attrs(race='high elf') self.assertIsInstance(char.race, race.HighElf)
def test_proficiencies_text(self): char = Character() char._proficiencies_text = ('hello', 'world') self.assertIn('hello', char.proficiencies_text.lower()) self.assertIn('world', char.proficiencies_text.lower()) # Check for extra proficiencies char._proficiencies_text += ("it's", "me") self.assertIn("it's", char.proficiencies_text.lower()) self.assertIn('me', char.proficiencies_text.lower()) # Check that race proficienceis are included elf = race.HighElf() char.race = elf expected = ("hello", "world", "longswords", "shortswords", "shortbows", "longbows", "it's", "me") for e in expected: self.assertIn(e, char.proficiencies_text.lower())
def test_resolve_mechanic(self): # Test a well defined mechanic NewSpell = Character._resolve_mechanic("mage_hand", None) self.assertTrue(issubclass(NewSpell, spells.Spell)) # Test an unknown mechanic def new_spell(**params): return spells.Spell NewSpell = Character._resolve_mechanic("hocus_pocus", spells.Spell) self.assertTrue(issubclass(NewSpell, spells.Spell)) # Test direct resolution of a proper subclass class MySpell(spells.Spell): pass NewSpell = Character._resolve_mechanic(MySpell, spells.Spell)
def test_is_proficient(self): char = Character(classes=['Wizard']) char.weapon_proficiencies sword = Shortsword() # Check for not-proficient weapon self.assertFalse(char.is_proficient(sword)) # Check if we're proficient in the weapon char.weapon_proficiencies = [Shortsword] self.assertTrue(char.is_proficient(sword)) # Now try it with a racial proficiency char.weapon_proficiencies = tuple() char.race = race.HighElf() self.assertTrue(char.is_proficient(sword))
def test_homebrew_infusions(self): char = Character(classes="artificer") class MyInfusion(infusions.Infusion): name="my infusion!" # Pass an already created infusion class char.set_attrs(infusions=(MyInfusion,)) self.assertIsInstance(char.infusions[0], infusions.Infusion) self.assertEqual(char.infusions[0].name, "my infusion!") # Pass a previously undefined infusion char = Character(classes="artificer") char.set_attrs(infusions=("spam_infusion",)) self.assertIsInstance(char.infusions[0], infusions.Infusion) self.assertEqual(char.infusions[0].name, "Spam Infusion")
def test_proficiencies(self): char1 = Character(name='Multiclass', classes=['wizard', 'fighter'], levels=[5, 4]) for svt in ('intelligence', 'wisdom'): self.assertIn(svt, char1.saving_throw_proficiencies) char2 = Character(name='Multiclass', classes=['wizard', 'rogue'], levels=[5, 4]) char3 = Character(name='Multiclass', classes=['rogue', 'wizard'], levels=[4, 5]) sword = Shortsword() self.assertTrue(char1.is_proficient(sword)) # multiclassing into Rogue doesn't give simple weapon proficiency self.assertFalse(char2.is_proficient(sword)) self.assertTrue(char3.is_proficient(sword))
def test_proficiencies(self): char1 = Character(name="Multiclass", classes=["wizard", "fighter"], levels=[5, 4]) for svt in ("intelligence", "wisdom"): self.assertIn(svt, char1.saving_throw_proficiencies) char2 = Character(name="Multiclass", classes=["wizard", "rogue"], levels=[5, 4]) char3 = Character(name="Multiclass", classes=["rogue", "wizard"], levels=[4, 5]) sword = Shortsword() self.assertTrue(char1.is_proficient(sword)) # multiclassing into Rogue doesn't give simple weapon proficiency self.assertFalse(char2.is_proficient(sword)) self.assertTrue(char3.is_proficient(sword))
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_equip_armor(self): char = Character(dexterity=16) char.wear_armor('leather armor') self.assertTrue(isinstance(char.armor, Armor)) # Now make sure the armor class is correct self.assertEqual(char.armor_class, 14) # Try passing an Armor object directly char.wear_armor(LeatherArmor()) self.assertEqual(char.armor_class, 14) # Test equipped armor with max dexterity mod_str char.armor.dexterity_mod_max = 1 self.assertEqual(char.armor_class, 12)
def test_spellcasting(self): char = Character(name='Multiclass', classes=['wizard', 'fighter'], levels=[5, 4]) self.assertEqual(len(char.spellcasting_classes), 1) char = Character(name='Multiclass', classes=['wizard', 'fighter'], subclasses=[None, 'Eldritch Knight'], levels=[5, 4]) self.assertEqual(len(char.spellcasting_classes), 2) # equivalent spellcasting level: 6 self.assertEqual(char.spell_slots(spell_level=1), 4) self.assertEqual(char.spell_slots(spell_level=2), 3) self.assertEqual(char.spell_slots(spell_level=3), 3) self.assertEqual(char.spell_slots(spell_level=4), 0)
def test_spellcasting(self): char = Character(name="Multiclass", classes=["wizard", "fighter"], levels=[5, 4]) self.assertEqual(len(char.spellcasting_classes), 1) char = Character( name="Multiclass", classes=["wizard", "fighter"], subclasses=[None, "Eldritch Knight"], levels=[5, 4], ) self.assertEqual(len(char.spellcasting_classes), 2) # equivalent spellcasting level: 6 self.assertEqual(char.spell_slots(spell_level=1), 4) self.assertEqual(char.spell_slots(spell_level=2), 3) self.assertEqual(char.spell_slots(spell_level=3), 3) self.assertEqual(char.spell_slots(spell_level=4), 0)
def test_constructor(self): char = Character(name="Multiclass", classes=["wizard", "fighter"], levels=[5, 4]) self.assertIsInstance(char, Character)
def test_load_char(self): char = Character.load({"name": "Dave", "sheet_type": "character"}) self.assertFalse(hasattr(char, "sheet_type"), "'sheet_type' not stripped from char props")
def test_wield_weapon(self): char = Character() char.strength = 14 char.weapon_proficiencies = [Shortsword] # Add a weapon char.wield_weapon('shortsword') self.assertEqual(len(char.weapons), 1) sword = char.weapons[0] self.assertTrue(isinstance(sword, Weapon)) self.assertTrue(isinstance(sword, Shortsword)) self.assertEqual(sword.attack_modifier, 4) # str + prof self.assertEqual(sword.damage, '1d6+2') # str # Check if dexterity is used if it's higher (Finesse weapon) char.weapons = [] char.dexterity = 16 char.wield_weapon('shortsword') sword = char.weapons[0] self.assertEqual(sword.attack_modifier, 5) # dex + prof # Check if race weapon proficiencies are considered char.weapons = [] char.weapon_proficiencies = [] char.race = race.HighElf() char.wield_weapon('shortsword') sword = char.weapons[0] self.assertEqual(sword.attack_modifier, 5)
def test_hit_dice(self): # Test the getter char = Character() char.level = 2 char.hit_dice_faces = 10 self.assertEqual(char.hit_dice, '2d10')
def test_constructor(self): char = Character(name="Inara")
def test_proficiency_bonus(self): char = Character() char.level = 1 self.assertEqual(char.proficiency_bonus, 2) char.level = 4 self.assertEqual(char.proficiency_bonus, 2) char.level = 5 self.assertEqual(char.proficiency_bonus, 3) char.level = 8 self.assertEqual(char.proficiency_bonus, 3) char.level = 9 self.assertEqual(char.proficiency_bonus, 4) char.level = 12 self.assertEqual(char.proficiency_bonus, 4) char.level = 13 self.assertEqual(char.proficiency_bonus, 5) char.level = 16 self.assertEqual(char.proficiency_bonus, 5) char.level = 17 self.assertEqual(char.proficiency_bonus, 6) char.level = 20 self.assertEqual(char.proficiency_bonus, 6)
def test_constructor(self): char = Character(name="Inara") self.assertIsInstance(char, Character)
def test_level(self): char = Character(name='Multiclass', classes=['wizard', 'fighter'], levels=[5, 4]) self.assertEqual(char.level, 9)
def test_constructor(self): char = Character(name='Multiclass', classes=['wizard', 'fighter'], levels=[5, 4])
def test_level(self): char = Character(name="Multiclass", classes=["wizard", "fighter"], levels=[5, 4]) self.assertEqual(char.level, 9)
def test_set_attrs(self): char = Character() char.set_attrs(name="Inara") self.assertEqual(char.name, "Inara") # Check that the weapons get loaded as objects not string char.set_attrs(weapons=["shortsword"]) self.assertEqual(len(char.weapons), 1) self.assertTrue(isinstance(char.weapons[0], Shortsword)) # Check that armor and shield gets set_attrs char.set_attrs(armor="leather armor", shield="shield") self.assertFalse(isinstance(char.armor, str)) self.assertFalse(isinstance(char.shield, str)) # Check that race gets set to an object char.set_attrs(race="high elf") self.assertIsInstance(char.race, race.HighElf) # Check inspiration works char.set_attrs(inspiration=True) self.assertTrue(char.inspiration) char.set_attrs(inspiration=False) self.assertFalse(char.inspiration)