},
'choices': ['leaf']
}
+ graph['nonexistant_child_node'] = {
+ 'set': {},
+ 'choices': ['leafy_greens']
+ }
graph['weighted_node'] = {
'set': {
'k1': [
'1 baz'
]
}
+ graph['null_choice_node'] = {
+ 'set': {},
+ 'choices': [None]
+ }
+ graph['weighted_null_choice_node'] = {
+ 'set': {},
+ 'choices': ['3 null']
+ }
return graph
assert_raises(KeyError, descend_graph, graph, 'bad_node', prng)
+def test_descend_nonexistant_child():
+ graph = build_graph()
+ prng = random.Random(1)
+ assert_raises(KeyError, descend_graph, graph, 'nonexistant_child_node', prng)
+
+
def test_SpecialVariables_dict():
prng = random.Random(1)
testdict = {'foo': 'bar'}
eq(tester['random 10-15 binary'], '\xdfj\xf1\xd80>a\xcd\xc4\xbb')
+
def test_assemble_decision():
graph = build_graph()
prng = random.Random(1)
eq(decision['path'], '/{bucket_readable}')
assert_raises(KeyError, lambda x: decision[x], 'key3')
+
def test_expand_key():
prng = random.Random(1)
test_decision = {
eq(dbl_indirect, 'value1')
eq(randkey, 'value-[/pNI$;92@')
+
def test_expand_loop():
prng = random.Random(1)
test_decision = {
decision = SpecialVariables(test_decision, prng)
assert_raises(RuntimeError, expand_key, decision, test_decision['key1'])
+
def test_expand_decision():
graph = build_graph()
prng = random.Random(1)
eq(request['randkey'], 'value-cx+*~G@&uW_[OW3')
assert_raises(KeyError, lambda x: decision[x], 'key3')
+
def test_weighted_choices():
graph = build_graph()
prng = random.Random(1)
nose.tools.assert_almost_equal(bar_percentage, 0.50, 1)
nose.tools.assert_almost_equal(baz_percentage, 0.25, 1)
+
+def test_null_choices():
+ graph = build_graph()
+ prng = random.Random(1)
+ choice = make_choice(graph['null_choice_node']['choices'], prng)
+
+ eq(choice, '')
+
+
+def test_weighted_null_choices():
+ graph = build_graph()
+ prng = random.Random(1)
+ choice = make_choice(graph['weighted_null_choice_node']['choices'], prng)
+
+ eq(choice, '')
+
+
+def test_null_child():
+ graph = build_graph()
+ prng = random.Random(1)
+ decision = descend_graph(graph, 'null_choice_node', prng)
+
+ eq(decision, {})
+
+
def test_weighted_set():
graph = build_graph()
prng = random.Random(1)
nose.tools.assert_almost_equal(bar_percentage, 0.50, 1)
nose.tools.assert_almost_equal(baz_percentage, 0.25, 1)
+
def test_header_presence():
graph = build_graph()
prng = random.Random(1)
nose.tools.assert_true(next(c2))
-
def test_header_expansion():
graph = build_graph()
prng = random.Random(1)
try:
choice = make_choice(node['choices'], prng)
- decision = descend_graph(decision_graph, choice, prng)
+ if choice == '':
+ decision = {}
+ else:
+ decision = descend_graph(decision_graph, choice, prng)
except IndexError:
decision = {}
return choices
weighted_choices = []
for option in choices:
+ if option is None:
+ weighted_choices.append('')
+ continue
fields = option.split(None, 1)
if len(fields) == 1:
weight = 1
else:
weight = int(fields[0])
value = fields[1]
+ if value == 'null' or value == 'None':
+ value = ''
for _ in xrange(weight):
weighted_choices.append(value)