Example #1
0
 def test_mock_dice_multiple_creatures(self):
     kobold1 = combatsim.creature.Creature()
     kobold2 = combatsim.creature.Creature()
     MockDice.set_roll(kobold1.saving_throw, '1d20', MockDice.value > 100)
     MockDice.set_roll(kobold2.saving_throw, '1d20', MockDice.value < 0)
     assert kobold1.saving_throw('wisdom', 100)
     assert not kobold2.saving_throw('wisdom', 0)
Example #2
0
 def test_mock_dice_object_overrides_class(self):
     kobold1 = combatsim.creature.Creature()
     kobold2 = combatsim.creature.Creature()
     MockDice.set_roll(combatsim.creature.Creature.saving_throw, '1d20',
                       MockDice.value > 100)
     MockDice.set_roll(kobold2.saving_throw, '1d20', MockDice.value < 0)
     assert kobold1.saving_throw('wisdom', 100)
     assert not kobold2.saving_throw('wisdom', 0)
Example #3
0
 def test_mock_dice_multiple_types(self):
     kobold = combatsim.creature.Monster()
     weapon = Weapon("Longsword", MockDice("1d8"), "slashing", owner=kobold)
     target = Mock()
     target.ac = 15
     MockDice.set_roll(kobold.attack, '1d20', MockDice.value > target.ac)
     MockDice.set_roll(kobold.attack, '1d8', MockDice.value == 10)
     kobold.attack(target, weapon)
     target.take_damage.assert_called_with(10, "slashing")
Example #4
0
 def test_mock_dice_on_class_function(self):
     kobold = combatsim.creature.Creature()
     MockDice.set_roll(combatsim.creature.Creature.saving_throw, '1d20',
                       MockDice.value > 100)
     assert kobold.saving_throw('wisdom', 100)
Example #5
0
 def test_mock_dice_succeed_impossible_save(self):
     kobold = combatsim.creature.Creature()
     MockDice.set_roll(kobold.saving_throw, '1d20', MockDice.value > 100)
     assert kobold.saving_throw('wisdom', 100)
Example #6
0
 def test_mock_dice_fail_tautological_save(self):
     kobold = combatsim.creature.Creature()
     MockDice.set_roll(kobold.saving_throw, '1d20', MockDice.value < 0)
     assert not kobold.saving_throw('wisdom', 0)
Example #7
0
 def test_patch_calls_function_with_args(self):
     func = Mock()
     decorated_func = MockDice.patch()(func)
     decorated_func("a", "b")
     func.assert_called_with("a", "b")
Example #8
0
 def run(self):
     return MockDice("1d8").roll()
Example #9
0
 def test_mock_dice_for_multiple_frames_in_stack(self):
     obj = MyDummyClass(MockDice("1d8"))
     MockDice.set_roll(obj.everything, '1d8', MockDice.value == 0)
     MockDice.set_roll(obj.run, '1d8', MockDice.value == 1)
     assert obj.everything() == ([1], [0])