From f80d087ac494b057cbebf60385863307aced9145 Mon Sep 17 00:00:00 2001 From: evilchili Date: Sat, 6 Aug 2022 16:58:28 -0700 Subject: [PATCH] support no options --- rolltable/tables.py | 2 +- tests/test_tables.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rolltable/tables.py b/rolltable/tables.py index b1bdb6b..07b2f46 100644 --- a/rolltable/tables.py +++ b/rolltable/tables.py @@ -113,7 +113,7 @@ class RollTable: freqs = random.choices(options, weights=weights, k=self.die) values = [] 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'): c = [option] for (k, v) in choice.items(): diff --git a/tests/test_tables.py b/tests/test_tables.py index 2cf8f70..eb32068 100644 --- a/tests/test_tables.py +++ b/tests/test_tables.py @@ -82,6 +82,16 @@ B3: - B choice 3 """ +fixture_no_options = """ +metadata: + headers: + - headerA + - headerB +B1: +B2: +B3: +""" + def test_combined_tables(): combined = tables.RollTable([fixture_combined_A, fixture_combined_B], die=6) @@ -125,5 +135,5 @@ def test_no_descriptions(): def test_yaml(): - t = tables.RollTable([fixture_metadata + fixture_source]) + t = tables.RollTable([fixture_no_options]) print(t.as_yaml)