Exemple #1
0
 def test_items(self):
     actual = parse("items")
     expected = (trait("items", optional=True)
                 | dict_items(optional=True)
                 | list_items(optional=True)
                 | set_items(optional=True))
     self.assertEqual(actual, expected)
Exemple #2
0
 def test_items_not_notify(self):
     actual = parse("items:attr")
     expected = (trait("items", notify=False, optional=True)
                 | dict_items(notify=False, optional=True)
                 | list_items(notify=False, optional=True)
                 | set_items(notify=False, optional=True)).trait("attr")
     self.assertEqual(actual, expected)
def _handle_items(trees, default_notifies):
    """ Handle keyword "items".

    Parameters
    ----------
    trees : list of lark.tree.Tree
        The children tree for the "items" rule.
        It should be empty.
    default_notifies : list of boolean
        The notify flag stack.

    Returns
    -------
    expression : ObserverExpression
    """
    if trees:
        # Nothing should be wrapped in items
        raise ValueError("Unexpected tree: {!r}".format(trees))

    notify = default_notifies[-1]
    return reduce(operator.or_, (
        expression_module.trait("items", notify=notify, optional=True),
        expression_module.dict_items(notify=notify, optional=True),
        expression_module.list_items(notify=notify, optional=True),
        expression_module.set_items(notify=notify, optional=True),
    ))
 def test_list_items_optional_true(self):
     expr = expression.list_items(optional=True)
     expected = [
         create_graph(ListItemObserver(notify=True, optional=True), ),
     ]
     actual = expr._as_graphs()
     self.assertEqual(actual, expected)
 def test_list_items_method_optional(self):
     # Test the instance method calls the top-level function correctly.
     expr = expression.list_items().list_items(optional=True)
     expected = [
         create_graph(
             ListItemObserver(notify=True, optional=False),
             ListItemObserver(notify=True, optional=True),
         ),
     ]
     actual = expr._as_graphs()
     self.assertEqual(actual, expected)