mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-05-18 20:23:27 +02:00
Added instructions for running tests and building docs.
This commit is contained in:
@@ -78,6 +78,70 @@ IP violations.
|
|||||||
How to Contribute
|
How to Contribute
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
Running Tests
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Dungeonsheets uses tests to verify the package works as
|
||||||
|
intended. Tests are found in the ``tests/`` folder. To run the tests
|
||||||
|
using *pytest*, run the following from a console:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
pip install -r requirements.txt -r requirements-tests.txt
|
||||||
|
pytest
|
||||||
|
|
||||||
|
Dungeonsheets defines tests using the *unittest* package in the
|
||||||
|
standard library. **For example**, to test a new function in the
|
||||||
|
``dungeonsheets/dice.py`` module, modify ``tests/test_dice.py``:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
:caption: dice.py
|
||||||
|
|
||||||
|
def roll(a, b=None):
|
||||||
|
"""roll(20) means roll 1d20, roll(2, 6) means roll 2d6"""
|
||||||
|
if b is None:
|
||||||
|
return random.randint(1, a)
|
||||||
|
else:
|
||||||
|
return sum([random.randint(1, b) for _ in range(a)])
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
:caption: test_dice.py
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
from dungeonsheets.dice import roll
|
||||||
|
|
||||||
|
class TestDice(TestCase):
|
||||||
|
def test_simple_rolling(self):
|
||||||
|
num_tests = 100
|
||||||
|
# Do a bunch of rolls and make sure the numbers are within the requsted range
|
||||||
|
for _ in range(num_tests):
|
||||||
|
result = roll(6)
|
||||||
|
self.assertGreaterEqual(result, 1)
|
||||||
|
self.assertLessEqual(result, 6)
|
||||||
|
|
||||||
|
def test_multi_rolling(self):
|
||||||
|
num_tests = 100
|
||||||
|
for _ in range(num_tests):
|
||||||
|
result = roll(2, 4) # Roll 2d4
|
||||||
|
self.assertGreaterEqual(result, 2)
|
||||||
|
self.assertLessEqual(result, 8)
|
||||||
|
|
||||||
|
|
||||||
|
Building Documentation
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Dungeonsheets uses sphinx to build documentations. All files are in
|
||||||
|
reStructuredText and are kept in the ``docs/`` folder. To build the
|
||||||
|
HTML files, run:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
pip install -r requirements.txt -r requirements-tests.txt
|
||||||
|
cd docs/
|
||||||
|
make html
|
||||||
|
|
||||||
|
The results can be found in the ``_build/html/`` foler.
|
||||||
|
|
||||||
Submitting Bugs
|
Submitting Bugs
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.. include:: ../CONTRIBUTING.rst
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ Welcome to Dungeonsheets's documentation!
|
|||||||
gm_notes
|
gm_notes
|
||||||
advanced_features
|
advanced_features
|
||||||
examples
|
examples
|
||||||
|
contributing
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class TestDice(TestCase):
|
|||||||
|
|
||||||
def test_simple_rolling(self):
|
def test_simple_rolling(self):
|
||||||
num_tests = 100
|
num_tests = 100
|
||||||
|
# Do a bunch of rolls and make sure the numbers are within the requsted range
|
||||||
for _ in range(num_tests):
|
for _ in range(num_tests):
|
||||||
result = roll(6)
|
result = roll(6)
|
||||||
self.assertGreaterEqual(result, 1)
|
self.assertGreaterEqual(result, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user