Esempio n. 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)
Esempio n. 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)
Esempio n. 3
0
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),
    ))
Esempio n. 4
0
 def test_dict_items_optional_true(self):
     expr = expression.dict_items(optional=True)
     expected = [
         create_graph(DictItemObserver(notify=True, optional=True), ),
     ]
     actual = expr._as_graphs()
     self.assertEqual(actual, expected)
Esempio n. 5
0
 def test_dict_items_method_optional(self):
     # Test the instance method calls the top-level function correctly.
     expr = expression.dict_items().dict_items(optional=True)
     expected = [
         create_graph(
             DictItemObserver(notify=True, optional=False),
             DictItemObserver(notify=True, optional=True),
         ),
     ]
     actual = expr._as_graphs()
     self.assertEqual(actual, expected)