def test_metadata_notify_false(self): # Test the top-level function expr = expression.metadata("butterfly", notify=False) expected = [ create_graph( FilteredTraitObserver( filter=MetadataFilter(metadata_name="butterfly"), notify=False, ), ), ] actual = expr._as_graphs() self.assertEqual(actual, expected)
def test_metadata_method_notify_false(self): # Test the instance method calls the top-level function correctly. expr = expression.metadata("bee").metadata("ant", notify=False) expected = [ create_graph( FilteredTraitObserver( filter=MetadataFilter(metadata_name="bee"), notify=True, ), FilteredTraitObserver( filter=MetadataFilter(metadata_name="ant"), notify=False, ), ), ] actual = expr._as_graphs() self.assertEqual(actual, expected)
def _handle_metadata(trees, default_notifies): """ Handle an element for filtering existing metadata. Parameters ---------- trees : list of lark.tree.Tree The children tree for the "metadata" rule. It contains only one item. default_notifies : list of boolean The notify flag stack. Returns ------- expression : ObserverExpression """ token, = trees metadata_name = token.value notify = default_notifies[-1] return expression_module.metadata(metadata_name, notify=notify)
def test_metadata_notify_false(self): actual = parse("+name:+attr") expected = metadata("name", notify=False).metadata("attr", notify=True) self.assertEqual(actual, expected)
def test_metadata(self): actual = parse("+name") expected = metadata("name", notify=True) self.assertEqual(actual, expected)