def test_token_map_default_add(self): """ Token map accepts default token and add token operations. """ class T1(object): def __init__(self, key, value): self.key = key self.value = value t = T1('foo', 'baz') tokens = [ AddTokenOp(t), SetDefaultTokenOp(t) ] self.assertDictEqual(token_map(tokens), {t: t}) tokens = [ SetDefaultTokenOp(t), AddTokenOp(t) ] self.assertDictEqual(token_map(tokens), {t: t}) tokens = [ SetDefaultTokenOp(t), AddTokenOp(t), SetDefaultTokenOp(t) ] self.assertDictEqual(token_map(tokens), {t: t})
def test_token_map_default_remove(self): """ A default token can be removed from the result. """ class T1(object): def __init__(self, key, value): self.key = key self.value = value t = T1('foo', 'baz') tokens = [ SetDefaultTokenOp(t), ] self.assertDictEqual(token_map(tokens), {t: t}) tokens.append(RemoveTokenOp(t)) self.assertDictEqual(token_map(tokens), {})
def test_token_map_add_remove(self): """ A token can be removed from the result using the remove operation. """ class T1(object): def __init__(self, key, value): self.key = key self.value = value t = T1('foo', 'baz') tokens = [ AddTokenOp(t), ] self.assertDictEqual(token_map(tokens), {t: t}) tokens.append(RemoveTokenOp(t)) self.assertDictEqual(token_map(tokens), {})
def token_map_custom_key_callback(self): class T1(object): def __init__(self, key, value): self.key = key self.value = value t1 = T1('foo', 'bar') t2 = T1('foo', 'baz') tokens = [ AddTokenOp(t1), SetDefaultTokenOp(t2) ] keyfunc = lambda op: 'some {:s}'.format(op.token.key) valuefunc = lambda op: 'my {:s}'.format(op.token.value) self.assertDictEqual(token_map(tokens), {t1: t1, t2: t2}) self.assertDictEqual(token_map(tokens, keyfunc), {'some foo': t1}) self.assertDictEqual(token_map(tokens, keyfunc, valuefunc), { 'some foo': 'my bar' })
def test_token_map_add(self): """ Add a token to the stream using the add-token operation. """ class T1(object): def __init__(self, key, value): self.key = key self.value = value t = T1('foo', 'bar') tokens = [ AddTokenOp(t) ] self.assertDictEqual(token_map(tokens), {t: t})
def get_links(self): """ Returns an iterator over output, input pairs """ return token_map(self.selected).values()
def get_handlers(self): """ Returns an iterator over event handler tokens. """ return token_map(self.selected).values()