def test_set_items_method_optional(self): # Test the instance method calls the top-level function correctly. expr = expression.set_items().set_items(optional=True) expected = [ create_graph( SetItemObserver(notify=True, optional=False), SetItemObserver(notify=True, optional=True), ), ] actual = expr._as_graphs() self.assertEqual(actual, expected)
def test_set_items_optional_true(self): expr = expression.set_items(optional=True) expected = [ create_graph(SetItemObserver(notify=True, optional=True), ), ] actual = expr._as_graphs() self.assertEqual(actual, expected)
def create_observer(**kwargs): """ Convenience function for creating SetItemObserver with default values. """ values = dict( notify=True, optional=False, ) values.update(kwargs) return SetItemObserver(**values)
def set_items(notify=True, optional=False): """ Create a new expression for observing items inside a set. Events emitted (if any) will be instances of :class:`~traits.observation.events.SetChangeEvent`. Parameters ---------- notify : bool, optional Whether to notify for changes. Default is to notify. optional : bool, optional Whether to ignore this if the upstream object is not a set. Default is false and an error will be raised if the object is not a set. Returns ------- new_expression : ObserverExpression """ observer = SetItemObserver(notify=notify, optional=optional) return SingleObserverExpression(observer)
def test_equal_observers(self): observer1 = SetItemObserver(notify=False, optional=False) observer2 = SetItemObserver(notify=False, optional=False) self.assertEqual(observer1, observer2) self.assertEqual(hash(observer1), hash(observer2))
def test_not_equal_different_type(self): observer1 = SetItemObserver(notify=False, optional=False) imposter = mock.Mock() imposter.notify = False imposter.optional = False self.assertNotEqual(observer1, imposter)
def test_not_equal_optional(self): observer1 = SetItemObserver(notify=True, optional=True) observer2 = SetItemObserver(notify=True, optional=False) self.assertNotEqual(observer1, observer2)