mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-05-19 04:33:26 +02:00
Basic implementation, can fill in some attributes on the character sheet.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from dungeonsheets.character import Character
|
||||
|
||||
class TestCharacter(TestCase):
|
||||
"""Tests for the generic character base class."""
|
||||
|
||||
def test_constructor(self):
|
||||
char = Character(name="Inara")
|
||||
|
||||
def test_hit_dice(self):
|
||||
# Test the getter
|
||||
char = Character()
|
||||
char.hit_dice_faces = 10
|
||||
char.hit_dice_num = 2
|
||||
self.assertEqual(char.hit_dice, '2d10')
|
||||
# Test the setter
|
||||
char.hit_dice = '3d12'
|
||||
self.assertEqual(char.hit_dice_faces, 12)
|
||||
self.assertEqual(char.hit_dice_num, 3)
|
||||
|
||||
def test_set_attrs(self):
|
||||
char = Character()
|
||||
char.set_attrs(name='Inara')
|
||||
self.assertEqual(char.name, 'Inara')
|
||||
@@ -0,0 +1,18 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from dungeonsheets.exceptions import DiceError
|
||||
from dungeonsheets import dice
|
||||
|
||||
class TestDice(TestCase):
|
||||
|
||||
def test_read_dice_str(self):
|
||||
out = dice.read_dice_str('1d6')
|
||||
self.assertEqual(out.faces, 6)
|
||||
self.assertEqual(out.num, 1)
|
||||
# Multiple digits
|
||||
out = dice.read_dice_str('15d10')
|
||||
self.assertEqual(out.faces, 10)
|
||||
self.assertEqual(out.num, 15)
|
||||
# Check a bad value
|
||||
with self.assertRaises(DiceError):
|
||||
dice.read_dice_str('Ed15')
|
||||
@@ -0,0 +1,19 @@
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from dungeonsheets import make_sheets, character
|
||||
|
||||
|
||||
class CharacterFileTestCase(unittest.TestCase):
|
||||
def test_load_character_file(self):
|
||||
charfile = 'examples/rogue.py'
|
||||
result = make_sheets.load_character_file(charfile)
|
||||
self.assertEqual(result['strength'], 10)
|
||||
|
||||
class FDFTestCase(unittest.TestCase):
|
||||
def test_create_fdf(self):
|
||||
fdfname = 'temp.fdf'
|
||||
char = character.Character()
|
||||
make_sheets.create_fdf(char, fdfname=fdfname)
|
||||
self.assertTrue(os.path.exists(fdfname))
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from dungeonsheets import stats
|
||||
|
||||
class TestStats(TestCase):
|
||||
|
||||
def test_modifier(self):
|
||||
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),
|
||||
((28, 29), 9),
|
||||
((30,), 10),
|
||||
]
|
||||
# Test the values for each modifier range
|
||||
stat = stats.Stat()
|
||||
for range_, target in ranges:
|
||||
for value in range_:
|
||||
stat.value = value
|
||||
msg = f"Stat {value} doesn't produce modifier {target} ({stat.modifier})"
|
||||
self.assertEqual(stat.modifier, target, msg)
|
||||
|
||||
def test_modfifier_string(self):
|
||||
stat = stats.Stat()
|
||||
stat.value = 5
|
||||
self.assertEqual(stat.modifier_string, '-3')
|
||||
stat.value = 10
|
||||
self.assertEqual(stat.modifier_string, '0')
|
||||
stat.value = 15
|
||||
self.assertEqual(stat.modifier_string, '+2')
|
||||
|
||||
def test_setter(self):
|
||||
"""Verify that this class works as a data descriptor."""
|
||||
# Set up a dummy class
|
||||
class MyCharacter():
|
||||
stat = stats.Stat()
|
||||
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)
|
||||
Reference in New Issue
Block a user