support no options

This commit is contained in:
evilchili 2022-08-06 16:58:28 -07:00
parent 4b10f01036
commit f80d087ac4
2 changed files with 12 additions and 2 deletions

View File

@ -113,7 +113,7 @@ class RollTable:
freqs = random.choices(options, weights=weights, k=self.die) freqs = random.choices(options, weights=weights, k=self.die)
values = [] values = []
for option in freqs: for option in freqs:
choice = random.choice(ds.data[option]) choice = random.choice(ds.data[option]) if ds.data[option] else ''
if hasattr(choice, 'keys'): if hasattr(choice, 'keys'):
c = [option] c = [option]
for (k, v) in choice.items(): for (k, v) in choice.items():

View File

@ -82,6 +82,16 @@ B3:
- B choice 3 - B choice 3
""" """
fixture_no_options = """
metadata:
headers:
- headerA
- headerB
B1:
B2:
B3:
"""
def test_combined_tables(): def test_combined_tables():
combined = tables.RollTable([fixture_combined_A, fixture_combined_B], die=6) combined = tables.RollTable([fixture_combined_A, fixture_combined_B], die=6)
@ -125,5 +135,5 @@ def test_no_descriptions():
def test_yaml(): def test_yaml():
t = tables.RollTable([fixture_metadata + fixture_source]) t = tables.RollTable([fixture_no_options])
print(t.as_yaml) print(t.as_yaml)