fix bug with sources that only have lists
This commit is contained in:
parent
15904a51d2
commit
e579d11cfa
|
@ -128,10 +128,7 @@ class DataSource:
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
# If the option is either a list or a string, just select it.
|
# If the option is either a list or a string, just select it.
|
||||||
if rand:
|
choices = self.data[option]
|
||||||
choices = [random.choice(self.data[option])]
|
|
||||||
else:
|
|
||||||
choices = self.data[option]
|
|
||||||
|
|
||||||
for choice in choices:
|
for choice in choices:
|
||||||
# If the randomly-selected choice is a dict, choose a random item and return a list consisting
|
# If the randomly-selected choice is a dict, choose a random item and return a list consisting
|
||||||
|
@ -153,6 +150,7 @@ class DataSource:
|
||||||
flattened.append(choice)
|
flattened.append(choice)
|
||||||
return flattened
|
return flattened
|
||||||
|
|
||||||
|
|
||||||
class RollTable:
|
class RollTable:
|
||||||
"""
|
"""
|
||||||
Generate a roll table using weighted distributions of random options.
|
Generate a roll table using weighted distributions of random options.
|
||||||
|
|
|
@ -204,7 +204,14 @@ def test_text():
|
||||||
assert repr(tables.RollTable([fixture_source]))
|
assert repr(tables.RollTable([fixture_source]))
|
||||||
|
|
||||||
|
|
||||||
def test_as_dict():
|
@pytest.mark.parametrize('table', [
|
||||||
source = tables.RollTable([fixture_no_descriptions]).datasources[0]
|
tables.RollTable([fixture_no_options]),
|
||||||
ds = source.as_dict()
|
tables.RollTable([fixture_one_choice]),
|
||||||
assert ds['option 1']['choice'] == 'choice 1'
|
tables.RollTable([fixture_metadata + fixture_source]),
|
||||||
|
tables.RollTable([fixture_source]),
|
||||||
|
tables.RollTable([fixture_no_options]),
|
||||||
|
tables.RollTable([fixture_lists_and_dicts]),
|
||||||
|
])
|
||||||
|
def test_as_dict(table):
|
||||||
|
for src in table.datasources:
|
||||||
|
assert src.as_dict()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user