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