Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Commit

Permalink
More backwards breaking changes. Switched around the method names of …
Browse files Browse the repository at this point in the history
…the various list related methods to be much more uniform
  • Loading branch information
icook committed Oct 20, 2013
1 parent 51c4fc3 commit ced9f9d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
23 changes: 12 additions & 11 deletions src/yota/form.py
Expand Up @@ -213,14 +213,14 @@ def __init__(self, **kwargs):
self._node_list.insert(0, self.start)
else:
if self.auto_start_close:
self.insert(0, Leader(template=self.start_template,
self.insert_node(0, Leader(template=self.start_template,
_attr_name='start',
**self.context))
if hasattr(self, 'close'):
self._node_list.append(self.close)
else:
if self.auto_start_close:
self.insert(-1, Leader(template=self.close_template,
self.insert_node(-1, Leader(template=self.close_template,
_attr_name='close',
**self.context))

Expand Down Expand Up @@ -293,13 +293,6 @@ def _process_errors(self):
def is_piecewise(self):
return bool('piecewise' in self.g_context and self.g_context['piecewise'])

def add_listener(self, listener):
""" Attaches a :class:`Listener` to an event type. These Listener will
be executed when trigger event is called. """
if type not in self._event_lists:
self._event_lists[listener.type] = []
self._event_lists[listener.type].append(listener)

def trigger_event(self, type):
""" Runs all the associated :class:`Listener`'s for a specific event
type. """
Expand All @@ -309,6 +302,14 @@ def trigger_event(self, type):
event()
except KeyError:
pass

def insert_listener(self, listener):
""" Attaches a :class:`Listener` to an event type. These Listener will
be executed when trigger event is called. """
if type not in self._event_lists:
self._event_lists[listener.type] = []
self._event_lists[listener.type].append(listener)

def insert_validator(self, new_validators):
""" Inserts a validator to the validator list.
Expand All @@ -323,7 +324,7 @@ def insert_validator(self, new_validators):
# append the validator to the list
self._validation_list.append(validator)

def insert(self, position, new_node_list):
def insert_node(self, position, new_node_list):
""" Inserts a :class:`Node` object or a list of objects at the
specified position into the :attr:`Form._node_list` of the form.
Index -1 is an alias for the end of the list. After insertion
Expand All @@ -345,7 +346,7 @@ def insert(self, position, new_node_list):
else:
self._node_list.insert(position + i, new_node)

def insert_after(self, prev_attr_name, new_node_list):
def insert_node_after(self, prev_attr_name, new_node_list):
""" Runs through the internal node structure attempting to find
a :class:`Node` object whos :attr:`Node._attr_name` is
prev_attr_name and inserts the passed node after it. If
Expand Down
18 changes: 9 additions & 9 deletions src/yota/tests/test_form.py
Expand Up @@ -183,7 +183,7 @@ class TForm(Form):
t = nodes.Entry()

test = TForm()
test.insert(1, nodes.Entry(_attr_name="testing"))
test.insert_node(1, nodes.Entry(_attr_name="testing"))
assert(test.t._parent_form is test)
assert(test.testing._parent_form is test)

Expand Down Expand Up @@ -284,10 +284,10 @@ class TForm(Form):

test = TForm()
# Test one that hits the mark and finds t
test.insert_after('t', nodes.Entry(_attr_name='t2'))
test.insert_node_after('t', nodes.Entry(_attr_name='t2'))
assert(test._node_list[2]._attr_name == 't2')
# Test one that goes to the bottom, no t4
test.insert_after('t4', nodes.Entry(_attr_name='t3'))
test.insert_node_after('t4', nodes.Entry(_attr_name='t3'))
assert(test._node_list[4]._attr_name == 't3')

def test_insert_validator(self):
Expand All @@ -314,13 +314,13 @@ def test_insert_validator(self):
def test_insert_special(self):
""" insert functions test plus special cases """
test = Form()
test.insert(0, nodes.Entry(_attr_name='test1'))
test.insert_node(0, nodes.Entry(_attr_name='test1'))
assert(hasattr(test, 'test1'))
assert(test._node_list[0]._attr_name == 'test1')
test.insert(-1, nodes.Entry(_attr_name='test2'))
test.insert_node(-1, nodes.Entry(_attr_name='test2'))
assert(hasattr(test, 'test2'))
assert(test._node_list[3]._attr_name == 'test2')
test.insert(2, nodes.Entry(_attr_name='test3'))
test.insert_node(2, nodes.Entry(_attr_name='test3'))
assert(hasattr(test, 'test3'))
assert(test._node_list[2]._attr_name == 'test3')

Expand Down Expand Up @@ -466,10 +466,10 @@ class TForm(Form):

self.assertRaises(AttributeError, stupid_2_6)
f = Form()
self.assertRaises(AttributeError, f.insert, 0, nodes.Entry())
self.assertRaises(AttributeError, f.insert_node, 0, nodes.Entry())
self.assertRaises(
AttributeError, f.insert, 0, nodes.Entry(_attr_name='name'))
AttributeError, f.insert_node, 0, nodes.Entry(_attr_name='name'))
self.assertRaises(AttributeError,
f.insert,
f.insert_node,
0,
nodes.Entry(_attr_name='g_context'))
4 changes: 2 additions & 2 deletions src/yota/tests/test_listeners.py
Expand Up @@ -26,15 +26,15 @@ def test_no_event(self):
test = yota.Form()
test.trigger_event("dummy")

def test_add_listener(self):
def test_insert_listener(self):
""" make sure no exception for empty events """
def test_func(list):
list.data = "testing"

class TForm(yota.Form):
test = nodes.List()
test = TForm()
test.add_listener(Listener("dummy", test_func, "test"))
test.insert_listener(Listener("dummy", test_func, "test"))
test.trigger_event("dummy")

assert test.test.data == "testing"
Expand Down

0 comments on commit ced9f9d

Please sign in to comment.