adding support for dicts of lists
This commit is contained in:
parent
845dbe1f7a
commit
3fbcb57aca
|
@ -134,6 +134,10 @@ class RollTable:
|
|||
if not ds.data[option]:
|
||||
values.append([option])
|
||||
continue
|
||||
if hasattr(ds.data[option], 'keys'):
|
||||
rand_key = random.choice(list(ds.data[option].keys()))
|
||||
choice = [rand_key, *ds.data[option][rand_key]]
|
||||
else:
|
||||
choice = random.choice(ds.data[option])
|
||||
if hasattr(choice, 'keys'):
|
||||
c = [option]
|
||||
|
|
|
@ -92,26 +92,49 @@ B2:
|
|||
B3:
|
||||
"""
|
||||
|
||||
fixture_lists = """
|
||||
fixture_lists_and_dicts = ["""
|
||||
#
|
||||
# one two three four
|
||||
# foo bar baz quz
|
||||
# category one two three four
|
||||
# Category foo bar baz quz
|
||||
#
|
||||
metadata:
|
||||
headers:
|
||||
- category
|
||||
- one
|
||||
- two
|
||||
- three
|
||||
- four
|
||||
foo:
|
||||
- bar:
|
||||
Category:
|
||||
- foo:
|
||||
- bar
|
||||
- baz
|
||||
- quz
|
||||
"""
|
||||
""", """
|
||||
#
|
||||
# category one two three four
|
||||
# Category foo bar baz quz
|
||||
#
|
||||
metadata:
|
||||
headers:
|
||||
- category
|
||||
- one
|
||||
- two
|
||||
- three
|
||||
- four
|
||||
Category:
|
||||
foo:
|
||||
- bar
|
||||
- baz
|
||||
- quz
|
||||
bar:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
"""]
|
||||
|
||||
|
||||
def test_lists():
|
||||
t = tables.RollTable([fixture_lists], die=1)
|
||||
def test_lists_and_dicts():
|
||||
t = tables.RollTable(fixture_lists_and_dicts, die=1)
|
||||
assert str(t)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user